如何为 Azure Functions EventHub 侦听器配置 Receiver 批处理大小?
How to configure Receiver batch size for Azure Functions EventHub listener?
来自事件中心的最新 Microsoft.Azure.WebJobs.ServiceBus package, it gives you the ability to receive batches of messages。我想设置批量接收多少条消息
核心 ServiceBus 库允许您重载 Receive()
函数并提供 batch size。
如何在 initial config of an EventHubs receiver 中做到这一点,或者是否需要其他东西?
斯蒂芬
MaxBatchSize
可以通过EventProcessorOptions, you can pass it as a parameter when creating a new 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;
}
您可以通过 host.json
中的 eventHub
配置块在 Functions 中执行此操作,如 here 所述。例如:
{
"eventHub": {
"maxBatchSize": 500,
"prefetchCount": 100
}
}
我们在创建 EventProcessorHost
时将这些配置设置应用于 EventProcessorOptions
(请参阅 here)。
来自事件中心的最新 Microsoft.Azure.WebJobs.ServiceBus package, it gives you the ability to receive batches of messages。我想设置批量接收多少条消息
核心 ServiceBus 库允许您重载 Receive()
函数并提供 batch size。
如何在 initial config of an EventHubs receiver 中做到这一点,或者是否需要其他东西?
斯蒂芬
MaxBatchSize
可以通过EventProcessorOptions, you can pass it as a parameter when creating a new 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;
}
您可以通过 host.json
中的 eventHub
配置块在 Functions 中执行此操作,如 here 所述。例如:
{
"eventHub": {
"maxBatchSize": 500,
"prefetchCount": 100
}
}
我们在创建 EventProcessorHost
时将这些配置设置应用于 EventProcessorOptions
(请参阅 here)。