【问题标题】:How to configure Receiver batch size for Azure Functions EventHub listener?如何为 Azure Functions EventHub 侦听器配置接收器批处理大小?
【发布时间】:2016-11-18 12:10:58
【问题描述】:

在最新的Microsoft.Azure.WebJobs.ServiceBus package 中,它使您能够从 eventthubs 中receive batches of messages。我想设置批量接收多少条消息。

核心 ServiceBus 库允许您重载 Receive() 函数并提供 batch size

如何在initial config of an EventHubs receiver 中做到这一点,还是需要其他东西?

【问题讨论】:

    标签: c# azure azure-webjobssdk azure-functions


    【解决方案1】:

    您可以通过host.json 中的eventHub 配置块在函数中执行此操作,如here 所述。例如:

    {
        "eventHub": {
            "maxBatchSize": 500,
            "prefetchCount": 100
        }
    }
    

    我们在创建EventProcessorHost 时将这些配置设置应用于EventProcessorOptions(请参阅here)。

    【讨论】:

      【解决方案2】:

      斯蒂芬,

      MaxBatchSize可以通过EventProcessorOptions进行配置,可以在新建EventHubConfiguration时作为参数传递。

      var options = EventProcessorOptions.DefaultOptions;
      options.MaxBatchSize = 50;
      var eventHubConfig = new EventHubConfiguration(options);
      string eventHubName = "MyHubName";
      eventHubConfig.AddSender(eventHubName, "Endpoint=sb://test.servicebus.windows.net/;SharedAccessKeyName=SendRule;SharedAccessKey=xxxxxxxx");
      eventHubConfig.AddReceiver(eventHubName, "Endpoint=sb://test.servicebus.windows.net/;SharedAccessKeyName=ReceiveRule;SharedAccessKey=yyyyyyy");
      
      config.UseEventHub(eventHubConfig);
      JobHost host = new JobHost(config);
      

      您可以在EventHubConfiguration.cs 的源代码中注意到,如果未指定EventProcessorOptions,则MaxBatchSize 默认设置为1000,而不是10

      public EventHubConfiguration(
              EventProcessorOptions options, 
              PartitionManagerOptions partitionOptions = null)
      {
          if (options == null)
          {
              options = EventProcessorOptions.DefaultOptions;
              options.MaxBatchSize = 1000;
           }
           _partitionOptions = partitionOptions;
      
           _options = options;
      }
      

      【讨论】:

        猜你喜欢
        • 2021-08-31
        • 1970-01-01
        • 2014-05-16
        • 2017-05-08
        • 1970-01-01
        • 2017-03-28
        • 1970-01-01
        • 1970-01-01
        • 2021-09-14
        相关资源
        最近更新 更多