Menu Search

1.9. Transactions

Sometimes it is useful to be able to group messages transfers - sent and/or received - on a session into atomic grouping. This can be done be creating the session as transactional. On a transactional session sent messages only become available at the target address on commit. Likewise any received and acknowledged messages are only discarded at their source on commit [8] .

Example 1.13. Transactions

C++:

	Connection connection(broker);
	Session session =  connection.createTransactionalSession();
	...
	if (smellsOk())
	session.commit();
	else
	session.rollback();
	

.NET C#:

	  Connection connection = new Connection(broker);
	  Session session =  connection.CreateTransactionalSession();
	  ...
	  if (smellsOk())
	  session.Commit();
	  else
	  session.Rollback();
	



[8] Note that this currently is only true for messages received using a reliable mode e.g. at-least-once. Messages sent by a broker to a receiver in unreliable receiver will be discarded immediately regardless of transctionality.