Patrick
Patrick

Reputation: 1040

Handling multiple event dependency in event-driven architecture

What would be best practice if you have an event-driven architecture and a service subscribing to events has to wait for multiple event (of the same kind) before proceeding with creating the next event in the chain?

An example would be a book order handling service that has to wait for each book in the order to have been handled by the warehouse before creating the event that the order has been picked so that the shipping service (or something similar) picks up the order and starts preparing for shipping.

Upvotes: 16

Views: 3473

Answers (2)

Bishoy
Bishoy

Reputation: 4025

Another useful pattern beside the Aggregator that Tom mentioned above is a saga pattern (a mini workflow). I've used it before with messaging library called NServiceBus to handle coordinating multiple messages that are correlated to each other.

the pattern is very useful and fits nicely for long-running processes. even if your correlated messages are different messages, like OrderStarted, OrderLineProcessed, OrderCompleted.

Upvotes: 14

tom redfern
tom redfern

Reputation: 31770

You can use the Aggregator pattern, also called Parallel Convoy.

Essentially you need to have some way of identifying messages which need to be aggregated, and when the aggregated set as a whole has been recieved, so that processing can start.

Without going out and buying the book*, the Apache Camel integration platform website has some nice resource on implementing the aggregator pattern. While this is obviously specific to Camel, you can see what kind of things are involved.

* disclaimer, I am not affiliated in any way with Adison Wesley, or any of the authors of the book...

Upvotes: 8

Related Questions