I have an event hub trigger function linked to an event hub and I have set it up to receive events. The receive message works fine, and I am able to process the message when it is fired from the source, but recently I have started noticing duplicate events getting processed at the receiver.
How do I determine if these are unique events, with possibly the same payload or the same event processed multiple times? I have read about partition Ids, but seems like that only tells us which partition the message was picked up from. It is very possible that both the messages were picked up from the same partition at interval of some time.
My event hub trigger implementation looks something like follows:
[FunctionName("function-name")]
public async Task RunAsync(
[EventHubTrigger("az_eventhubname",
Connection = "connection-string-path", ConsumerGroup = "%AzureEventHubConsumerName%")] EventData ed,
ExecutionContext eCtx, PartitionContext PartitionContext)
{
var messageBody = Encoding.UTF8.GetString((ed).Body);
// other tasks ...
}
I am able to bind both ExecutionContext
and PartitionContext
but none of them provide a message id or event id property, neither does EventData
EventData
provides only Sequence Number, Offset and Enque Time, in itsSystemProperties
.PartitionContext
provides the partiton id and other info such as host id, offset, epoch, token, etc.ExecutionContext
provides an invocation id
If Event Hub Triggers do not provide message ids or event ids, how can I distinguish between 2 messages having the same payload?
CodePudding user response:
There is no strong concept of an event identity within Event Hubs; the responsibility of defining what makes an event unique falls to the application. The closest approximation using just the Event Hubs service data would be the combination of the sequence number assigned to the event and the partition that it was read from.
Generally, it is encouraged that publishers and consumers coordinate on an item set in the Properties
dictionary that is meaningful within the application context to identify the data.