本文整理匯總了Java中org.apache.activemq.command.MessageAck.setTransactionId方法的典型用法代碼示例。如果您正苦於以下問題:Java MessageAck.setTransactionId方法的具體用法?Java MessageAck.setTransactionId怎麽用?Java MessageAck.setTransactionId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.activemq.command.MessageAck
的用法示例。
在下文中一共展示了MessageAck.setTransactionId方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onStompMessageNack
import org.apache.activemq.command.MessageAck; //導入方法依賴的package包/類
public MessageAck onStompMessageNack(String messageId, TransactionId transactionId) throws ProtocolException {
MessageId msgId = new MessageId(messageId);
if (!dispatchedMessage.containsKey(msgId)) {
return null;
}
MessageAck ack = new MessageAck();
ack.setDestination(consumerInfo.getDestination());
ack.setConsumerId(consumerInfo.getConsumerId());
ack.setAckType(MessageAck.POSION_ACK_TYPE);
ack.setMessageID(msgId);
if (transactionId != null) {
unconsumedMessage.add(dispatchedMessage.get(msgId));
ack.setTransactionId(transactionId);
}
dispatchedMessage.remove(msgId);
return ack;
}
示例2: immediateIndividualTransactedAck
import org.apache.activemq.command.MessageAck; //導入方法依賴的package包/類
private void immediateIndividualTransactedAck(MessageDispatch md) throws JMSException {
// acks accumulate on the broker pending transaction completion to indicate
// delivery status
registerSync();
MessageAck ack = new MessageAck(md, MessageAck.INDIVIDUAL_ACK_TYPE, 1);
ack.setTransactionId(session.getTransactionContext().getTransactionId());
session.syncSendPacket(ack);
}
示例3: acknowledge
import org.apache.activemq.command.MessageAck; //導入方法依賴的package包/類
/**
* Acknowledge all the messages that have been delivered to the client up to
* this point.
*
* @throws JMSException
*/
public void acknowledge() throws JMSException {
clearDeliveredList();
waitForRedeliveries();
synchronized(deliveredMessages) {
// Acknowledge all messages so far.
MessageAck ack = makeAckForAllDeliveredMessages(MessageAck.STANDARD_ACK_TYPE);
if (ack == null)
return; // no msgs
if (session.getTransacted()) {
rollbackOnFailedRecoveryRedelivery();
session.doStartTransaction();
ack.setTransactionId(session.getTransactionContext().getTransactionId());
}
pendingAck = null;
session.sendAck(ack);
// Adjust the counters
deliveredCounter = Math.max(0, deliveredCounter - deliveredMessages.size());
additionalWindowSize = Math.max(0, additionalWindowSize - deliveredMessages.size());
if (!session.getTransacted()) {
deliveredMessages.clear();
}
}
}
示例4: doCommit
import org.apache.activemq.command.MessageAck; //導入方法依賴的package包/類
@Override
void doCommit() throws Exception {
if (!dispatchedInTx.isEmpty()) {
MessageDispatch md = dispatchedInTx.getFirst();
MessageAck pendingTxAck = new MessageAck(md, MessageAck.STANDARD_ACK_TYPE, dispatchedInTx.size());
pendingTxAck.setTransactionId(md.getMessage().getTransactionId());
pendingTxAck.setFirstMessageId(dispatchedInTx.getLast().getMessage().getMessageId());
LOG.trace("Sending commit Ack to ActiveMQ: {}", pendingTxAck);
dispatchedInTx.clear();
sendToActiveMQ(pendingTxAck, new ResponseHandler() {
@Override
public void onResponse(IAmqpProtocolConverter converter, Response response) throws IOException {
if (response.isException()) {
if (response.isException()) {
Throwable exception = ((ExceptionResponse) response).getException();
exception.printStackTrace();
sender.close();
}
}
pumpProtonToSocket();
}
});
}
}
示例5: tightUnmarshal
import org.apache.activemq.command.MessageAck; //導入方法依賴的package包/類
/**
* Un-marshal an object instance from the data input stream
*
* @param o the object to un-marshal
* @param dataIn the data input stream to build the object from
* @throws IOException
*/
public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn, BooleanStream bs) throws IOException {
super.tightUnmarshal(wireFormat, o, dataIn, bs);
MessageAck info = (MessageAck)o;
info.setDestination((org.apache.activemq.command.ActiveMQDestination) tightUnmarsalCachedObject(wireFormat, dataIn, bs));
info.setTransactionId((org.apache.activemq.command.TransactionId) tightUnmarsalCachedObject(wireFormat, dataIn, bs));
info.setConsumerId((org.apache.activemq.command.ConsumerId) tightUnmarsalCachedObject(wireFormat, dataIn, bs));
info.setAckType(dataIn.readByte());
info.setFirstMessageId((org.apache.activemq.command.MessageId) tightUnmarsalNestedObject(wireFormat, dataIn, bs));
info.setLastMessageId((org.apache.activemq.command.MessageId) tightUnmarsalNestedObject(wireFormat, dataIn, bs));
info.setMessageCount(dataIn.readInt());
}
示例6: looseUnmarshal
import org.apache.activemq.command.MessageAck; //導入方法依賴的package包/類
/**
* Un-marshal an object instance from the data input stream
*
* @param o the object to un-marshal
* @param dataIn the data input stream to build the object from
* @throws IOException
*/
public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn) throws IOException {
super.looseUnmarshal(wireFormat, o, dataIn);
MessageAck info = (MessageAck)o;
info.setDestination((org.apache.activemq.command.ActiveMQDestination) looseUnmarsalCachedObject(wireFormat, dataIn));
info.setTransactionId((org.apache.activemq.command.TransactionId) looseUnmarsalCachedObject(wireFormat, dataIn));
info.setConsumerId((org.apache.activemq.command.ConsumerId) looseUnmarsalCachedObject(wireFormat, dataIn));
info.setAckType(dataIn.readByte());
info.setFirstMessageId((org.apache.activemq.command.MessageId) looseUnmarsalNestedObject(wireFormat, dataIn));
info.setLastMessageId((org.apache.activemq.command.MessageId) looseUnmarsalNestedObject(wireFormat, dataIn));
info.setMessageCount(dataIn.readInt());
}
示例7: populateObject
import org.apache.activemq.command.MessageAck; //導入方法依賴的package包/類
@Override
protected void populateObject(Object object) throws Exception {
super.populateObject(object);
MessageAck info = (MessageAck) object;
info.setDestination(createActiveMQDestination("Destination:1"));
info.setTransactionId(createTransactionId("TransactionId:2"));
info.setConsumerId(createConsumerId("ConsumerId:3"));
info.setAckType((byte) 1);
info.setFirstMessageId(createMessageId("FirstMessageId:4"));
info.setLastMessageId(createMessageId("LastMessageId:5"));
info.setMessageCount(1);
}
示例8: populateObject
import org.apache.activemq.command.MessageAck; //導入方法依賴的package包/類
@Override
protected void populateObject(Object object) throws Exception {
super.populateObject(object);
MessageAck info = (MessageAck) object;
info.setDestination(createActiveMQDestination("Destination:1"));
info.setTransactionId(createTransactionId("TransactionId:2"));
info.setConsumerId(createConsumerId("ConsumerId:3"));
info.setAckType((byte) 1);
info.setFirstMessageId(createMessageId("FirstMessageId:4"));
info.setLastMessageId(createMessageId("LastMessageId:5"));
info.setMessageCount(1);
info.setPoisonCause(createThrowable("PoisonCause:6"));
}
示例9: onStompMessageAck
import org.apache.activemq.command.MessageAck; //導入方法依賴的package包/類
synchronized MessageAck onStompMessageAck(String messageId, TransactionId transactionId) {
MessageId msgId = new MessageId(messageId);
if (!dispatchedMessage.containsKey(msgId)) {
return null;
}
MessageAck ack = new MessageAck();
ack.setDestination(consumerInfo.getDestination());
ack.setConsumerId(consumerInfo.getConsumerId());
if (ackMode == CLIENT_ACK) {
if (transactionId == null) {
ack.setAckType(MessageAck.STANDARD_ACK_TYPE);
} else {
ack.setAckType(MessageAck.DELIVERED_ACK_TYPE);
}
int count = 0;
for (Iterator<?> iter = dispatchedMessage.entrySet().iterator(); iter.hasNext();) {
@SuppressWarnings("rawtypes")
Map.Entry entry = (Entry)iter.next();
MessageId id = (MessageId)entry.getKey();
MessageDispatch msg = (MessageDispatch)entry.getValue();
if (transactionId != null) {
if (!unconsumedMessage.contains(msg)) {
unconsumedMessage.add(msg);
count++;
}
} else {
iter.remove();
count++;
}
if (id.equals(msgId)) {
ack.setLastMessageId(id);
break;
}
}
ack.setMessageCount(count);
if (transactionId != null) {
ack.setTransactionId(transactionId);
}
} else if (ackMode == INDIVIDUAL_ACK) {
ack.setAckType(MessageAck.INDIVIDUAL_ACK_TYPE);
ack.setMessageID(msgId);
if (transactionId != null) {
unconsumedMessage.add(dispatchedMessage.get(msgId));
ack.setTransactionId(transactionId);
}
dispatchedMessage.remove(msgId);
}
return ack;
}
示例10: settle
import org.apache.activemq.command.MessageAck; //導入方法依賴的package包/類
private void settle(final Delivery delivery, final int ackType) throws Exception {
byte[] tag = delivery.getTag();
if (tag != null && tag.length > 0 && delivery.remotelySettled()) {
checkinTag(tag);
}
if (ackType == -1) {
// we are going to settle, but redeliver.. we we won't yet ack to ActiveMQ
delivery.settle();
onMessageDispatch((MessageDispatch) delivery.getContext());
} else {
MessageDispatch md = (MessageDispatch) delivery.getContext();
MessageAck ack = new MessageAck();
ack.setConsumerId(consumerId);
ack.setFirstMessageId(md.getMessage().getMessageId());
ack.setLastMessageId(md.getMessage().getMessageId());
ack.setMessageCount(1);
ack.setAckType((byte) ackType);
ack.setDestination(md.getDestination());
DeliveryState remoteState = delivery.getRemoteState();
if (remoteState != null && remoteState instanceof TransactionalState) {
TransactionalState s = (TransactionalState) remoteState;
long txid = toLong(s.getTxnId());
LocalTransactionId localTxId = new LocalTransactionId(connectionId, txid);
ack.setTransactionId(localTxId);
// Store the message sent in this TX we might need to re-send on rollback
md.getMessage().setTransactionId(localTxId);
dispatchedInTx.addFirst(md);
}
LOG.trace("Sending Ack to ActiveMQ: {}", ack);
sendToActiveMQ(ack, new ResponseHandler() {
@Override
public void onResponse(IAmqpProtocolConverter converter, Response response) throws IOException {
if (response.isException()) {
if (response.isException()) {
Throwable exception = ((ExceptionResponse) response).getException();
exception.printStackTrace();
sender.close();
}
} else {
delivery.settle();
}
pumpProtonToSocket();
}
});
}
}
示例11: testQueuePersistentXAUncommitedAcksLostOnRestart
import org.apache.activemq.command.MessageAck; //導入方法依賴的package包/類
public void testQueuePersistentXAUncommitedAcksLostOnRestart() throws Exception {
int NUMBER = 100;
ActiveMQDestination destination = new ActiveMQQueue("TEST");
// Setup the producer and send the message.
StubConnection connection = createConnection();
ConnectionInfo connectionInfo = createConnectionInfo();
SessionInfo sessionInfo = createSessionInfo(connectionInfo);
ProducerInfo producerInfo = createProducerInfo(sessionInfo);
connection.send(connectionInfo);
connection.send(sessionInfo);
connection.send(producerInfo);
for (int i = 0; i < NUMBER; i++) {
Message message = createMessage(producerInfo, destination);
message.setPersistent(true);
connection.send(message);
}
// Setup the consumer and receive the message.
ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
connection.send(consumerInfo);
// Begin the transaction.
XATransactionId txid = createXATransaction(sessionInfo);
connection.send(createBeginTransaction(connectionInfo, txid));
Message m = null;
for (int i = 0; i < NUMBER; i++) {
m = receiveMessage(connection);
assertNotNull(m);
}
MessageAck ack = createAck(consumerInfo, m, NUMBER, MessageAck.STANDARD_ACK_TYPE);
ack.setTransactionId(txid);
connection.send(ack);
// Don't commit
// restart the broker.
restartBroker();
// Setup the consumer and receive the message.
connection = createConnection();
connectionInfo = createConnectionInfo();
sessionInfo = createSessionInfo(connectionInfo);
connection.send(connectionInfo);
connection.send(sessionInfo);
consumerInfo = createConsumerInfo(sessionInfo, destination);
connection.send(consumerInfo);
// All messages should be re-delivered.
for (int i = 0; i < NUMBER; i++) {
m = receiveMessage(connection);
assertNotNull(m);
}
assertNoMessagesLeft(connection);
}
示例12: testQueuePersistentCommittedAcksNotLostOnRestart
import org.apache.activemq.command.MessageAck; //導入方法依賴的package包/類
public void testQueuePersistentCommittedAcksNotLostOnRestart() throws Exception {
ActiveMQDestination destination = createDestination();
// Setup the producer and send the message.
StubConnection connection = createConnection();
ConnectionInfo connectionInfo = createConnectionInfo();
SessionInfo sessionInfo = createSessionInfo(connectionInfo);
ProducerInfo producerInfo = createProducerInfo(sessionInfo);
connection.send(connectionInfo);
connection.send(sessionInfo);
connection.send(producerInfo);
for (int i = 0; i < 4; i++) {
Message message = createMessage(producerInfo, destination);
message.setPersistent(true);
connection.send(message);
}
// Begin the transaction.
XATransactionId txid = createXATransaction(sessionInfo);
connection.send(createBeginTransaction(connectionInfo, txid));
ConsumerInfo consumerInfo;
Message m = null;
for (ActiveMQDestination dest : destinationList(destination)) {
// Setup the consumer and receive the message.
consumerInfo = createConsumerInfo(sessionInfo, dest);
connection.send(consumerInfo);
for (int i = 0; i < 4; i++) {
m = receiveMessage(connection);
assertNotNull(m);
}
MessageAck ack = createAck(consumerInfo, m, 4, MessageAck.STANDARD_ACK_TYPE);
ack.setTransactionId(txid);
connection.send(ack);
}
// Commit
connection.request(createCommitTransaction1Phase(connectionInfo, txid));
// restart the broker.
restartBroker();
// Setup the consumer and receive the message.
connection = createConnection();
connectionInfo = createConnectionInfo();
sessionInfo = createSessionInfo(connectionInfo);
connection.send(connectionInfo);
connection.send(sessionInfo);
consumerInfo = createConsumerInfo(sessionInfo, destination);
connection.send(consumerInfo);
// No messages should be delivered.
assertNoMessagesLeft(connection);
m = receiveMessage(connection);
assertNull(m);
}
示例13: testQueueTransactedAck
import org.apache.activemq.command.MessageAck; //導入方法依賴的package包/類
public void testQueueTransactedAck() throws Exception {
// Setup a first connection
StubConnection connection1 = createConnection();
ConnectionInfo connectionInfo1 = createConnectionInfo();
SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
connection1.send(connectionInfo1);
connection1.send(sessionInfo1);
connection1.send(producerInfo1);
destination = createDestinationInfo(connection1, connectionInfo1, destinationType);
ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
consumerInfo1.setPrefetchSize(100);
connection1.send(consumerInfo1);
// Send the messages
for (int i = 0; i < 4; i++) {
Message message = createMessage(producerInfo1, destination, deliveryMode);
connection1.send(message);
}
// Begin the transaction.
LocalTransactionId txid = createLocalTransaction(sessionInfo1);
connection1.send(createBeginTransaction(connectionInfo1, txid));
// Acknowledge the first 2 messages.
for (int i = 0; i < 2; i++) {
Message m1 = receiveMessage(connection1);
assertNotNull("m1 is null for index: " + i, m1);
MessageAck ack = createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE);
ack.setTransactionId(txid);
connection1.request(ack);
}
// Commit the transaction.
connection1.send(createCommitTransaction1Phase(connectionInfo1, txid));
//due to async tx operations, we need some time for message count to go down
Thread.sleep(1000);
ArtemisBrokerWrapper wrapper = (ArtemisBrokerWrapper) broker.getBroker();
long messageCount = wrapper.getAMQueueMessageCount(destination);
// The queue should now only have the remaining 2 messages
assertEquals(2, messageCount);
}