Publish Subscribe Event Handlers
Publish Subscribe Event Handlers, which means that each of the Handlers receives it's own copy of a Message in order to handle it
Let's consider scenario, when Order Was Placed, we want send order confirmation and reserve products in Stock via HTTP call.
This could potentially look like this:
public function notifyAboutNewOrder(OrderWasPlaced $event, NotificationService $notificationService) : void
public function reserveItemsInStock(OrderWasPlaced $event, StockClient $stockClient): void
Now let's imagine that, our Event goes to
asynchronous_messageschannel (queue), our message is consumed and order confirmation is sent successfully. After sending confirmation we want to reserve items in Stock, however the API call fails. This means that this Event will be replied and we will retry all our handlers once more. Yet this is not what we want, as first Handler was successful, the second needs to be replied only, so let's divine in how Ecotone solves that.
There is a big difference on the fundamental level to how Ecotone's messaging works, comparing to other PHP Messaging Frameworks. In Ecotone each of the Handlers will receive it's own copy of the Event and will handle it in isolation.
This means that under the hood, there would be two messages sent to
asynchronous_messageseach targeting specific Event Handler. This bring safety to retrying events, as we will only retry Handler that actually failed.