简体   繁体   English

超过每个分区允许的最大接收器数量 eventthub 中的错误

[英]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
  1. So, I tried to remove receiver with functions in it.因此,我尝试删除带有功能的接收器。 like using receiver.client.clients.remove or receiver.client.clients.clear() , to clear the receivers added in it before.就像使用receiver.client.clients.removereceiver.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

  1. I also tried to run only part of the code below "add_receiver" line我还尝试仅运行“add_receiver”行下方的部分代码
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.

相关问题 超过最大允许尺寸 - maximum allowed dimention exceeded 使用 IndexLocator 时超出最大允许大小错误 - Maximum allowed size exceeded error when using IndexLocator 无法完全加载数据,因为超出了每张纸的最大列数 - the data could not be loaded completely because the maximum number of columns per sheet was exceeded Python:通常如何避免出现“超出最大允许尺寸”错误? - Python: How does one typically get around “Maximum allowed dimension exceeded” error? eventhub中的分区是什么? - What is the partition in eventhub? ValueError:超出最大允许尺寸,AgglomerativeClustering fit_predict - ValueError: Maximum allowed dimension exceeded, AgglomerativeClustering fit_predict 雪花连接器 SQL 编译错误:超出列表中的最大表达式数,预计最多 16,384 - snowflake connector SQL compilation error: maximum number of expressions in a list exceeded, expected at most 16,384 “退出:超过最大迭代次数。” 一个一个解决多个优化问题时出错 - “EXIT: Maximum Number of Iterations Exceeded.” error while solving multiple optimization problem one by one pyinstaller 递归错误:超出最大递归深度 - pyinstaller Recursion error: maximum recursion depth exceeded 大熊猫腌渍错误 - 超出最大递归深度 - Pandas to pickle error - maximum recursion depth exceeded
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM