Reputation: 9664
Sorry for the fussy question, I'll try to ellaborate by showing you a use-case (which is not my real world case, so please don't take note of event-/service- names or responsibilities):
Consider a system with the services (among others): "Store" and "Economy". The store service processes item-purchases and publishes three events: "CustomerBoughtItem", "CustomerReturnedItem" and "StoreIsClosed". Now, the economy service picks up those events and creates a financial report on a daily basis. The report should be created immediately after the shop is closed. It is crucial that all events from the store service included in the daily report, which means that the economy service can not create its financial report before all events from the store has been processed. How can I deterministically ensure that all "CustomerBoughtItem" and "CustomerReturnedItem" events have been processed at the end point before I start processing the "StoreIsClosed" event?
Upvotes: 1
Views: 160
Reputation: 5530
you can use the following pattern:
open a saga and receive these three messages. every message has a sequential id (for example as int). save all sequential ids and determine on every of these messages received that:
if these two conditions are met send the last message to your saga via .SendLocal (CreateDailyReportMessage).
edit for better formatting and to answer the comment:
I assume by "StoreIsClosed" event published by another service you mean: that the other service does not now, what the last SequentialId is or more general the service that is responsible for the event, that an StoreIsClosed does not know anything about customer transactions.
so store service must implicitly or explicitly send you more context information so that the economy service
examples:
Upvotes: 1