Idempotent Consumer (Deduplication)
Last updated
Was this helpful?
Last updated
Was this helpful?
In order to use Deduplication, install .
The role of deduplication is to safely receive same message multiple times, as there is no guarantee from Message Brokers that we will receive the same Message once. In Ecotone all Messages are identifiable and contains of Message Id. Message Id is used for deduplication. If message was already handled, it will be skipped.
Deduplication is enabled by default and works whenever message is consumed in .
You may also define given Message Handler for deduplication. This will use and deduplicated base on your customer header key. This allows in synchronous and asynchronous scenarios.
This is especially useful when, we receive events from external services e.g. payment or notification events which contains of identifier that we may use deduplication on. For example Sendgrid (Email Service) sending us notifications about user interaction, as there is no guarantee that we will receive same webhook once, we may use "eventId", to deduplicate in case.
paymentId
becomes our deduplication key. Whenever we will receive now Command with same value under paymentId
header, Ecotone will deduplicate that and skip execution of receivePayment method
.
Deduplication happen across given endpointId.
This means that if we would introduce another handler with same deduplication key, it will get it's own deduplication tracking.
As deduplication is tracked within given endpoint id, it means we can change the deduplication key safely without being in risk of receiving duplicates. If we would like to start tracking from fresh, it would be enough to change the endpointId.
To remove expired deduplication history which is kept in database table, Ecotone provides an console command:
By default Ecotone removes message id from deduplication storage after 7 days in batches of 1000. It can be customized in case of need:
It's important to keep removal batch size at small number. As deleting records may result in database index rebuild which will cause locking. Therefore small batch size will ensure our system can continue, while messages are being deleted in background.
As the deduplication is enabled by default, if you want to disable it then make use of DbalConfiguration.