Let's say I have
Service A
that publishesMessage 1
to be processed byConsumer A
- The same
service A
that publishesMessage 2
to be processed byConsumer B
I need to make sure that consumer B
processes Message 2
only after Message 1
has been fully processed. What is the common or best approach to this kind of situation ?
I was thinking that maybe I would need to generate a unique identifier and pass it in both messages and store it in the database so that Consumer A
can update the status of the process and Consumer B
can look up the status and only starts processing Message 2
after Consumer A
has finished, otherwise it would push the message back into the queue. Would that be feasible ?
1 Answer 1
Firstly, you cant guarantee order of events being processed. It sounds like you have one of two problems.
- Your services are dependent on each other - a problem
- You're misunderstanding the purpose of the events - easily done. An event should be "this happened". Your other services should react accordingly by updating their internal data store. If you have services that rely on other services to be able to fulfil their tasks you need to rethink why and adjust your architecture accordingly. Alternatively, this could be a valid situation, in which case - raise a different event and listen to that.
Explore related questions
See similar questions with these tags.
Consumer A
can notify backService A
once processed and thenService A
can send toConsumer B
?service A
to just push the message to the queue and immediately return a response without waiting for anything