[英]Exceeded the maximum number of allowed receivers per partition Error in eventhub
Like the code below, I am continuously receiving data from azure eventhub.像下面的代码一样,我不断地从 azure eventthub 接收数据。 Often I am seeing the error saying "Exceeded the maximum number of allowed receivers per partition" which I know where it comes from.
我经常看到错误说“超出了每个分区允许的最大接收器数量”,我知道它来自哪里。
import os
import sys
import logging
import time
from azure.eventhub import EventHubClient, Receiver, Offset
logger = logging.getLogger("azure")
ADDRESS = ""
USER = ""
KEY = ""
CONSUMER_GROUP = "$default"
OFFSET = Offset("@latest")
PARTITION = "0"
total = 0
last_sn = -1
last_offset = "-1"
client = EventHubClient(ADDRESS, debug=False, username=USER, password=KEY)
receiver = client.add_receiver(CONSUMER_GROUP, PARTITION, prefetch=0, offset=OFFSET)
client.run()
start_time = time.time()
while True:
for event_data in receiver.receive(timeout=5000):
print("Received: {}".format(event_data.body_as_str(encoding='UTF-8')))
a = event_data.body_as_str(encoding='UTF-8')
total += 1
end_time = time.time()
run_time = end_time - start_time
print("Received {} messages in {} seconds".format(total, run_time))
The line here is the one that add receiver and if I add more than five reciever, it hits the limit of the possible number of receiver per partition.这里的行是添加接收器的行,如果我添加超过五个接收器,它会达到每个分区可能接收器数量的限制。
receiver = client.add_receiver(CONSUMER_GROUP, PARTITION, prefetch=0
receiver.client.clients.remove
or receiver.client.clients.clear()
, to clear the receivers added in it before.receiver.client.clients.remove
或receiver.client.clients.clear()
一样,清除之前添加的接收器。 However, none of these methods seems to work. The reason why I see this error is that because I run the whole code above whenever I need to stop running script to debug, so whenever I re-run it, I have to run the line receiver = client.add_receiver(CONSUMER_GROUP, PARTITION, prefetch=0
我看到这个错误的原因是因为每当我需要停止运行脚本进行调试时我都会运行上面的整个代码,所以每当我重新运行它时,我必须运行行
receiver = client.add_receiver(CONSUMER_GROUP, PARTITION, prefetch=0
client.run()
start_time = time.time()
while True:
for event_data in receiver.receive(timeout=5000):
print("Received: {}".format(event_data.body_as_str(encoding='UTF-8')))
a = event_data.body_as_str(encoding='UTF-8')
total += 1
end_time = time.time()
run_time = end_time - start_time
print("Received {} messages in {} seconds".format(total, run_time))
However, I see another error saying that EventHubError: This receive handler is now closed.
但是,我看到另一个错误说
EventHubError: This receive handler is now closed.
Any possible ways to fix this issue?任何可能的方法来解决这个问题?
After struggling, I think this may be a solution to this issue.经过挣扎,我认为这可能是解决此问题的方法。
For the line 22 above, I could simplly add 'keep_alive' input to it, something like:对于上面的第 22 行,我可以简单地添加“keep_alive”输入,例如:
receiver = client.add_receiver(CONSUMER_GROUP, PARTITION, prefetch=0, offset=OFFSET, keep_alive = 10000000)
In this way, I can leave the client receiver opened and not get the error message "EventHubError: This receive handler is now closed.", then simply run the only part from below:这样,我可以让客户端接收器保持打开状态,而不会收到错误消息“EventHubError:此接收处理程序现已关闭。”,然后只需运行下面的唯一部分:
start_time = time.time()
while True:
for event_data in receiver.receive(timeout=5000):
print("Received: {}".format(event_data.body_as_str(encoding='UTF-8')))
a = event_data.body_as_str(encoding='UTF-8')
total += 1
end_time = time.time()
run_time = end_time - start_time
print("Received {} messages in {} seconds".format(total, run_time))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.