Search code examples
jpajmsrollbackoptimistic-lockingactivemq-artemis

ActiveMQ Artemis redelivery delay


Setup:

  • We have a Spring Boot application that is reading messages from an ActiveMQ Artemis JMS queue.
  • The messages are processing in a JPA transaction.
  • When there is an exception triggering a rollback in JPA, it also triggers a JMS rollback in Artemis that is setup with redelivery delay.
  • Our app is running in multiple instances in parallel and this cause optimistic locking issues when processing multiple messages that share common data.

Issue: When X messages are processed in parallel and there is optimistic locking issue, then only 1 message goes through and all the others are re-scheduled with the delay. When redelivery happens, then same as before the X-1 messages will arrive at the same time since the delay is the same and cause the same issue with only one going through.

Question: Does anyone know a way to add variance to the redelivery delay time of ActiveMQ Artemis?

Note: I know that there is an option for that in ActiveMQ 5.x called collisionAvoidanceFactor, but it is missing from ActiveMQ Artemis.


Solution

  • As you note, there is no equivalent for collisionAvoidanceFactor in ActiveMQ Artemis. I know of no way to modify the redelivery delay in a similar manner. There is the redelivery-delay-multiplier, but that is enforced consistently across redeliveries and would not provide the variance that you're looking for.

    You may consider using message grouping so that "messages that share common data" are consumed serially by the same consumer and therefore avoid the locking issues in the first place.

    After looking at what it would take to implement this feature I opened ARTEMIS-2364. I'll be sending a pull-request soon so it will likely be in the next version of Artemis (i.e. 2.10).