I have an Azure Function triggered by Event Hub. I configured the function app in the host.json with a MaxBatchSize of 32. My Event Hub has 6 partitions, and I don't want an event to be processed twice.
So, I need partition ID and sequence number to identify the event uniquely. I would like to save PartitionID and SequenceNumber in my database as primary keys. My function is triggered in input with Array of EventData. Iterating on the array, I can get the SequenceNumber for each message, but I don't know how to get per PartitionID. I tried to include parameter of type PartitionContext among input parameters but it doesn't work.
Here it is my code:
[FunctionName("EventHubTriggeredFunction")]
public static void Run([EventHubTrigger("events", Connection = "EventHubConnection")]EventData[] eventHubMessages, TraceWriter log)
{
foreach (var message in eventHubMessages)
{
using (Stream stream = message.GetBodyStream())
{
using (StreamReader reader = new StreamReader(stream))
{
try
{
//... do something
//SequenceNumber: message.SequenceNumber
Save(reader.ReadToEnd(), message);
//... do something else
}
}
}
}
How can I get PartitionID for each message processed?