简体   繁体   English

如何在事件中心触发的Azure函数中获取PartitionId?

[英]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.

相关问题 运行事件中心的问题在本地触发 azure function,启动时出现“Out of retries creating lease for partition”错误 - Issues running event hub triggered azure function locally, getting "Out of retries creating lease for partition" error on startup 从ServiceBus触发的Azure功能检索IoT中心双胞胎 - Retrieve IoT Hub Twin from ServiceBus triggered azure function Azure功能-AWS RDS Postgres的事件中心 - Azure Function - Event Hub to AWS RDS Postgres 调试使用事件网格触发的 Azure Function - Debug an Azure Function that is triggered using an Event Grid 如何通过事件触发功能? - How can a function be triggered with an event? Azure事件中心超时 - Azure Event Hub timeouts 如何将 CosmosDB 依赖项跟踪数据从 Azure Function 事件中心触发器发送到 Application Insights - How to send CosmosDB dependency tracking data to Application Insights from Azure Function Event Hub Trigger 使用 Azure 函数从事件中心在 Sql Server 中插入数据 - Insert data in Sql Server from Event Hub using Azure Function Azure Function 事件中心 Output 绑定在部署时不起作用 - Azure Function Event Hub Output Binding not working when deployed 如何获取 Azure IoT-Hub 的 SharedAccessKey - How to get SharedAccessKey for Azure IoT-Hub
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM