【发布时间】:2021-06-04 06:49:14
【问题描述】:
我正在使用这个简单的 foreach 循环将事件发送到 Azure EventHub,问题是它看起来很慢并且只发送 1-2 个事件/秒,所以我觉得我一定错过了一些东西,我怎样才能加快速度?我是异步发送它们还是我做错了什么?
if (!apiInputPutCalendarService.TimeSlotIdsToClose.Any())
{
return new BadRequestObjectResult(new
{
Status = "NOK",
Error = "There are no timeslots to close",
Result = ""
});
}
else
{
foreach (String calendarTimeSlotId in apiInputPutCalendarService.TimeSlotIdsToClose)
{
EventHubCDSSoftDeleteTriggerModel scanMsg = new EventHubCDSSoftDeleteTriggerModel
{
TimeSlotId = calendarTimeSlotId
};
var scanMessageJsonString = JsonConvert.SerializeObject(scanMsg);
await EventHubHelper.SendEventToEventHubAsync(_eventHubClient, scanMessageJsonString);
log.LogInformation($"Message: {scanMessageJsonString} sent!");
}
}
这是一条如此简单的小消息,我预计每秒至少要发送 100 条消息
我在这里错过了什么?
【问题讨论】:
-
从变量命名来看,您使用的是旧版事件中心 SDK。我建议升级到当前一代的软件包
Azure.Messaging.EventHubs,这就是彼得在下面的答案中所展示的。 -
除了 Peter 关于批量发布的建议之外,您可能还需要考虑您正在使用的 throughput units 的数量以及应用于每个事件中心层的 quotas。这些共同限制入口和出口流量,并可能导致大负载或非常频繁的发布受到限制。
标签: c# azure foreach azure-eventhub