JMS guarantees the delivery of a message by nature, if the message is sent, then it will be delivered to the consumer, if there is, no matter what happens, MOM is designed to ensure this fact. In any case, delivery is not required, which means it is being processed.
Reliability is provided through various mechanisms:
- the first is to store the message in a queue (queue AND the message should be marked as constant, which is the default value), which ensures that the message will not be lost in case of a system interruption.
- then you have a confirmation and retry policy, the message will be stored in the queue until the consumer confirms this and in the case of a transaction session is not delivered until the consumer processes the message or the maximum retry is reached. After that, the error message can be redirected to the dead letter queue for analysis.
To ensure consistency between the two data sources, you must use transaction XA, at least on the producer side (you have at least 2 resources implied in the transaction database A and JMS queue) to ensure that the message will not be sent in the queue, if the commit in database A fails or the database will not be updated if the message is not queued. Message consumption must also be met to ensure re-delivery in the event of a rollback.
Within the transaction boundaries, both the consumer and the producer will never be included, since this contradicts the asynchronous nature of the messaging system, you cannot block resources on the producer's side until the consumer processes the message, because you have no guarantee on when this will happen .
NB: if your database does not support XA (or to improve performance), and if you have only 2 resources that are implied in the transaction (in the database and in the JMS queue), you can take a look at logging the last transaction of resources
source share