首页 文章

EventHub异常:无法为当前会话或连接分配更多句柄

提问于
浏览
4

我有C#控制台应用程序,通过它我经常将数据发送到事件中心 . 这个控制台应用程序基本上从SQL存储读取一些数据并开始将数据推送到事件中心 .

整个程序以无限循环/方式运行,就像在控制中一样,只要它在SQL中接收任何数据,它就从那里提取数据并开始发送到事件中心 .

但是有一刻我得到了这个错误 .

“无法为当前会话或连接分配更多句柄 . 允许的最大句柄数为4999.请释放资源再试一次 . 在Microsoft.ServiceBus.Common ......

当我重新启动这个控制台应用程序时它工作正常 . 但我不知道为什么我得到这个错误 .

请帮我 .

感谢和问候,

RK

2 回答

  • 8

    TLDR: In the 'send to EventHub logic', make sure that you are reusing (cache'ing) the same sender instance.

    The Why

    EventHubs旨在支持超大规模的高吞吐量低延迟事件系统 . 因此,我们选择依靠一个非常高性能的协议来进行所有运行时操作 - 即Amqp . Amqp Protocol的优点在构建于其上的应用程序充分利用其优势时发挥作用 . 这就是EventHubs对象模型映射到Amqp工件的方式:

    • EventHubClient 映射到一个AmqpConnection . 基数为1:1 . 如果在创建EventHubClient.CreateFromConnectionString时指定完全相同的ConnectionString - 将共享底层物理套接字 - 但amqp工件 - AmqpConnection仍然不同 .

    • 每当客户端在内部调用 EventHubClient.Send(EventData) 时, EventHubClientEventHubClient 创建的AmqpConnection上创建 1 AmqpSession1 AmqpLink in that Session . 只要将相同的 EventHubClient 实例用于后续发送,就会重新使用此会话和链接 .

    • 每当对 EventHubClient 执行任何管理操作时 - 从,mgmt . 操作(如getPartitionInfo)始终是请求 - 响应并且需要双向通信 - EventHubClient 创建 1 AmqpSession2 AmqpLink's in that Session - one Link for the Request & other link for Response (Ex: imagine the result of a REST Get call) .

    • 每当,任何子实体都是从 EventHubClient 创建的 - 如 EventHubSenderEventHubReceiver - EventHubClient 创建 a brand new AmqpSession && an AmqpLink in that Session .

    Key takeaways for the Client Application using eventhub SDK are

    每次创建 EventHubClient 实例时 - 在下面创建一个真实的物理套接字 .

    每次创建 EventHubSenderEventHubReceiver 实例时, EventHubClient 创建的套接字被重用并在其上面:(a)创建AmqpSession - 否 . 每个连接的AmqpSessions限制为5k - I guess this is the limit your client application is hitting above . (b)在该会话内创建AmqpLink - 这将在EventHubs服务中触发实体解析(与现有 EventHubSender 上的发送相比, a tiny bit expensive ) .

  • 0

    问题现在已解决我只创建Event hub客户端的单个实例,用于发送所有消息/事件,而不是为每个消息/事件创建Event hub客户端实例 .

相关问题