I know delivery of a single event hub message to a consumer is at-least-once and I can see plenty of documentation around this. However, if I'm the event publisher do I have any guarantees of my event being published to the stream exactly once?
Given I can fail to receive the response indicating publishing the message was a success or not, I have no choice but to retry. Is there anything preventing my event being duplicated on the hub?
CodePudding user response:
No; there are no guarantees of exactly-once within the Event Hubs ecosystem.
That said, if you're willing to take a dependency on a beta version, Azure.Messaging.EventHubs introduced a new buffered producer in v5.7.0-beta.x which supports idempotent retries. When this feature is enabled, the implicit retries that the producer uses will help to guard against duplicates.
It's important to note, however, that this is best effort and does not change the at-least-once guarantee. Regardless of duplicates when publishing, consumers should expect and guard against reading duplicate events.
To enable it, you'd configure the buffered producer similar to:
var connectionString = "<< CONNECTION STRING FOR THE EVENT HUBS NAMESPACE >>";
var eventHubName = "<< NAME OF THE EVENT HUB >>";
var options = new EventHubBufferedProducerClientOptions
{
EnableIdempotentRetries = true
};
var producer = new EventHubBufferedProducerClient(
connectionString,
eventHubName,
options);
More information on the buffered producer can be found in the Publishing Events sample for the SDK.
We do not yet have a firm date for its stable release, though we're currently aiming for early May. Please be aware that we do not recommend using beta packages in critical production scenarios.