azure-functions - Azure EventHubTrigger 函数应用中的偏移量

标签 azure-functions azure-iot-hub azure-eventhub azure-iot-edge

期待:
使用具有 EventHubTrigger-CSharp 模板的函数应用会在新事件进入时运行。
实现:
使用来自 https://azure.microsoft.com/en-us/documentation/articles/functions-bindings-event-hubs/ 的非常基本的示例
结果:
解释方法:

public static void Run(string myEventHubMessage, TraceWriter log)
{
    log.Info($"C# Event Hub trigger function processed a message: {myEventHubMessage}");
}
确实提供了事件队列中的“第一个”而不是当前的。
附加:
  • 我添加了一个消费者组(所以不是从 $Default 读取)
  • 根据此博客:http://www.yourcloudbuddy.com/2016/04/azure-functions-and-event-hubs.html '目前无法将其配置为启动特定偏移量'。

  • 问题:
    如何在我的函数应用中接收集线器上的最新事件?
    更多信息:
    我需要将新信号从事件中心转发到外部 mqtt api(到目前为止有效)。可能我需要另一种方法?

    最佳答案

    现在有办法了。

    注意:为此,您必须删除存储在 azure-webjobs-eventhub 中的消费者组数据。在您连接到函数应用的存储帐户中。

    我们现在可以使用 Microsoft.Azure.Functions.Extensions 在 Azure Functions 中使用依赖注入(inject)。 nuget 包。

    这为我们开辟了一种方法,可以通过执行以下操作来控制 Azure Function App 从何处开始处理我们的事件中心:

    using System;
    using Microsoft.Azure.EventHubs;
    using Microsoft.Azure.Functions.Extensions.DependencyInjection;
    using Microsoft.Azure.WebJobs.EventHubs;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Logging;
    
    [assembly: FunctionsStartup(typeof(EventHubOffsetTest.Startup))]
    
    namespace EventHubOffsetTest
    {
        public class Startup : FunctionsStartup
        {
            public override void Configure(IFunctionsHostBuilder builder)
            {
                builder.Services.PostConfigure<EventHubOptions>(o => o.EventProcessorOptions.InitialOffsetProvider = GetInitialOffset);
            }
    
            private static EventPosition GetInitialOffset(string partitionId)
            {
                return EventPosition.FromEnd();
            }
        }
    }
    

    关于azure-functions - Azure EventHubTrigger 函数应用中的偏移量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40274359/

    相关文章:

    azure - 如何从 Azure Function 中删除 Azure 表存储条目?

    c# - 对于使用 .net 6.0 的 Azure 函数,我需要做什么将 PnP.Core.Services 替换为 CSOM

    azure - VS Code Azure 扩展 : Infinite loading loop

    azure - 如何将 customDimensions 中的更多条目添加到 Azure Function 中的 Application Insights Telemetry

    azure - IoT 中心 - 修改复杂的 token 创建(通过 MQTT)

    azure - 如何在 Azure Function 中写入 Azure 事件网格主题

    azure - 事件中心 API POST : 40103: Invalid authorization token signature

    Azure IOT ExportDevicesAsync 内部服务器错误

    azure-iot-hub - 物联网中心模拟器?

    python - Databricks 与 Azure 事件中心连接