[英]How to get PartitionId in event hub triggered Azure function?
I have an Azure Function triggered by Event Hub. 我有一个由事件中心触发的Azure函数。 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. 我在host.json中配置了功能应用程序,MaxBatchSize为32。我的事件中心有6个分区,我不希望事件被处理两次。
So, I need partition ID and sequence number to identify the event uniquely. 因此,我需要分区ID和序列号来唯一标识事件。 I would like to save PartitionID and SequenceNumber in my database as primary keys. 我想将PartitionID和SequenceNumber作为主键保存在数据库中。 My function is triggered in input with Array of EventData. 我的函数是在EventData数组的输入中触发的。 Iterating on the array, I can get the SequenceNumber for each message, but I don't know how to get per PartitionID. 在数组上进行迭代,我可以获得每个消息的SequenceNumber,但是我不知道如何获取每个PartitionID。 I tried to include parameter of type PartitionContext among input parameters but it doesn't work. 我试图在输入参数中包括PartitionContext类型的参数,但是它不起作用。
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? 如何获得每个处理的消息的PartitionID?
Define the EventHub trigger to include Event Metadata . 定义EventHub触发器以包括事件元数据 。 Then use the receiverRuntimeInfo on the context object. 然后在上下文对象上使用receiverRuntimeInfo 。
PartitionContext.RuntimeInfo.PartitionId
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.