|
Summary: After started a local transaction, you can create a QueueSender or TopicPublisher and send() or publish() messages.
OverviewAfter you've started a local transaction, through creating a transacted session, you can create a QueueSender or a TopicPublisher. With these methods you can send() or publish() messages, similar to a non-transacted session. Such a commit is atomic. In other words, if the commit fails none of the messages are sent. An atomic commit is an "all or nothing" action. The code below demonstrates two text messages sent to a queue within one local transaction (topics work in a similar way). Only when commit() occurs are the two text messages actually sent. // queueConnection is an instance of QueueConnection // create a transacted QueueSession boolean isTransacted = true; int acknowledgeMode = 0; QueueSession queueSession = queueConnection.createQueueSession (isTransacted,acknowledgeMode); // obtain a queue // GSJMSAdmin.getQueue is a javax.naming.Context Queue queue = GSJMSAdmin.getQueue(queueName); // create a QueueSender on the queue QueueSender queueSender = queueSession.createSender(queue); // start the JMS connection queueConnection.start(); // create a TextMessage TextMessage tm1 = queueSession.createTextMessage ("This is message 1"); // Send the message queueSender.send(tm1); // create a second TextMessage TextMessage tm2 = queueSession.createTextMessage ("This is message 2"); // Send the message queueSender.send(tm2); // commit the transaction - this actually sends the messages queueSession.commit() In the event of an error, and you don't want to commit the transaction, use call rollback() instead to cease all message sends performed during the transaction. If the client crashes without committing the session is automatically rolled back. // roll back the transaction
queueSession.rollback()
|
Wiki Content Tree
Your Feedback Needed!
We need your help to improve this wiki site. If you have any suggestions or corrections, write to us at techw@gigaspaces.com. Please provide a link to the wiki page you are referring to.
Add Comment