JMS (ActiveMQ) - Event to be consumed only after another event was consumed

351 views Asked by At

I have 2 events basically:

UserCreatedEvent.class And UserUpdatedEvent.class

I have a flow that produces these two events at once (remember this is only an example) Is it possible to make sure (with some configuration) that the 2nd event will be consumed only after the first event will be consumed? (I don't want the update event to be processed before the create event was processed.)

P.S these 2 events are being produced to different queues.

Lastly I would like to point out that i'm using JMSTemplate (spring) for events. with activemq.

1

There are 1 answers

0
retroq On

You can add correlation id to UpdateEvent with id of CreateEvent. Consumer should not consume UpdateEvent if correlation id is set but CreateEvent with that id was not consumed yet.

If you have several consumers, you should add new event CreateEventProcessingFinished[id] which will be caught by UpdateEvent consumer and considered as permission for consuming event with given correlation id.

But i think it is much better to avoid message synchronization by changing architecture (if it is possible).