EventHub异常:无法为当前会话或连接分配更多的句柄 [英] EventHub Exception :Cannot allocate more handles to the current session or connection

查看:171
本文介绍了EventHub异常:无法为当前会话或连接分配更多的句柄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have C# console application through which I am sending data to event hub frequently.This console application basically read some data from SQL storage and start pushing data to event hub.

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

This entire program run in endless loop/fashion like in while control whenever it receive any data in SQL it pulls data from there and start sending to Event hub.

但是有一段时间我遇到了这个错误.

But at some moment I got this error.

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

"Cannot allocate more handles to the current session or connection.The maximum number of handles allowed is 4999.Please free up resources any try again. at Microsoft.ServiceBus.Common......

当我重新启动该控制台应用程序时,它可以正常工作.但是我不知道为什么会出现此错误.

When I restarted this console application its working fine.But I don't know why I got this error .

请帮助我.

感谢&问候

RK

推荐答案

TLDR:在发送至EventHub逻辑"中,确保您正在重用(缓存)相同的发送者实例.

原因:

EventHubs旨在支持超大规模的高吞吐量低延迟事件处理系统.因此,我们选择对所有运行时操作都依赖高性能的协议-即 Amqp协议在基于其构建的应用程序充分利用其优势时起作用.这是EventHubs对象模型映射到Amqp工件的方式:

EventHubs is designed to support very large scale high-thruput low-latency event'ing systems. Hence, we chose to rely on a very performant protocol for all Runtime Operations - namely Amqp. The goodness of Amqp Protocol comes into play when the application built on top of it fully leverages its strengths. This is how EventHubs Object Model maps to Amqp artifacts:

  1. EventHubClient映射到一个单独的AmqpConnection.基数是1:1.如果在创建 EventHubClient.CreateFromConnectionString -底层的物理套接字将被共享-但是amqp Artifact-AmqpConnection仍然不同.
  2. 每当客户端调用EventHubClient.Send(EventData)时,在内部EventHubClient都会在EventHubClient创建的AmqpConnection上在该会话中创建 1 AmqpSession 1 AmqpLink .只要相同的EventHubClient实例用于后续的Sends,此Session和Link将被重复使用.
  3. 每当在EventHubClient上执行任何管理操作时-因为mgmt.操作(例如getPartitionInfo)始终是请求-响应,并且需要双向通信-EventHubClient在该会话中创建 1 AmqpSession 2 AmqpLink-请求和链接的一个链接响应的其他链接(例如,想象一下REST Get调用的结果).
  4. 只要从EventHubClient创建任何子实体-就像EventHubSenderEventHubReceiver-EventHubClient都会创建全新的AmqpSession && 该会话中的AmqpLink .
  1. EventHubClient maps to one single AmqpConnection. Cardinality is 1:1. If exact same ConnectionString is specified while Creating EventHubClient.CreateFromConnectionString - The underlying physical socket will be shared - but the amqp Artifact - AmqpConnection is still different.
  2. Whenever client invokes EventHubClient.Send(EventData), internally, EventHubClient creates 1 AmqpSession and 1 AmqpLink in that Session on the AmqpConnection created by EventHubClient. This Session and Link are re-used as long as the same EventHubClient instance is used for subsequent Sends.
  3. Whenever any Management operation is performed on the EventHubClient - since, mgmt. operations (like getPartitionInfo) are always request-response and require 2-way communication - EventHubClient creates 1 AmqpSession and 2 AmqpLink's in that Session - one Link for the Request & other link for Response (Ex: imagine the result of a REST Get call).
  4. Whenever, any child entities are Created from EventHubClient - like EventHubSender or EventHubReceiver - EventHubClient creates a brand new AmqpSession && an AmqpLink in that Session.

使用eventhub SDK的客户端应用程序的主要收获是:

每次创建EventHubClient实例-在其下创建一个实际的物理套接字.

Every Time an EventHubClient instance is created - a real physical socket is created underneath.

每次创建EventHubSenderEventHubReceiver实例时,都会重复使用由EventHubClient创建的套接字,并在其之上: (a)创建了一个AmqpSession-不.的AmqpSession每次连接数上限为5k-我想这是您的客户端应用程序所能达到的极限. (b)AmqpLink是在该会话内创建的,这将触发EventHubs Service中的实体解析(与在现有的EventHubSender上发送相比,有点贵).

Every Time an EventHubSender or an EventHubReceiver instance is created that socket created by EventHubClient is re-used and on top of it: (a) an AmqpSession is created - no. of AmqpSessions are limited to 5k per connection - I guess this is the limit your client application is hitting above. (b) AmqpLink is created inside that Session - which will inturn trigger Entity Resolution in EventHubs Service (which is a tiny bit expensive compared to sending on an existing EventHubSender).

有关事件中心的更多信息.

这篇关于EventHub异常:无法为当前会话或连接分配更多的句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆