I couldn't find enough information about artemis transactions in the documentation. It was not clear to me how artemis transactions work so I would like to clarify it.
There are two methods in org.apache.activemq.artemis.api.core.client.ClientSession
class:
/**
* Commits the current transaction, blocking.
*
* @throws ActiveMQException if an exception occurs while committing the transaction
*/
void commit() throws ActiveMQException;
and
/**
* Rolls back the current transaction.
*
* @throws ActiveMQException if an exception occurs while rolling back the transaction
*/
void rollback() throws ActiveMQException;
I cannot find any method that begins transaction and I do not know what exactly is a transaction in artemis. What operations can be committed or rollbacked?
I have tested several scenarios and I have my conclusions. Thera are two operations which can be commited or rollbacked: message sending and message receiving (acknowledgment). Methods ClientSession#commit
and ClientSession#rollback
are only for committing and rollbacking messages sending and acknowledgment. No method is needed to begin transaction. There are only uncommitted messages which can be committed or rollbacked. Two arguments autoCommitSends and autoCommitAcks that can be used during session creation are essential for artemis transaction.
Let's consider message sending.
If autoCommitSends is set to true then ClientSession#commit
and ClientSession#rollback
do nothing.
If autoCommitSends is set to false then ClientSession#commit
method has to be called after sending message (ClientProducer#send
) to really send massage. Method ClientSession#commit
commits all sent (in this session) and uncommitted messages. Messages can be rollbacked by calling ClientSession#rollback
method. Method ClientSession#rollback
rollbacks all sent (in this session) and uncommitted messages.
Let's consider message receiving.
If autoCommitAcks is set to true then ClientSession#commit
and ClientSession#rollback
do nothing.
If autoCommitAcks is set to false then ClientSession#commit
method has to be called after message acknowledgment (ClientMessage#acknowledge
) to really acknowledge massage. Method ClientSession#commit
commits all acknowledged (in this session) and uncommitted messages. Messages acknowledgments can be rollbacked by calling ClientSession#rollback
method. Method ClientSession#rollback
rollbacks all acknowledged (in this session) and uncommitted messages.
Are my conclusions correct?
===EDIT===
I delete part of this question related to acknowledge and individualAcknowledge because it was unrelated to main question and made my question too complex.
acknowledge
andindividualAcknowledge
relate in this question, and create a new questions about how you start a transaction, how auto-commit works, etc. – Justin Bertram