分区0是否正确?还是我必须为每个分区添加4个接收器?
#!/usr/bin/python3
import os
import sys
import logging
import time
from azure.eventhub import EventHubClient, Receiver, Offset
logger = logging.getLogger("azure")
ADDRESS = "amqps://xxxxx.servicebus.windows.net/insights-operational-logs"
CONSUMER_GROUP = "myConsumerGrp"
OFFSET = Offset("-1")
PARTITION = "0"
total = 0
last_sn = -1
last_offset = "-1"
client = EventHubClient(ADDRESS, debug=False, username="xxxx", password="xxxx")
try:
receiver = client.add_receiver(CONSUMER_GROUP, PARTITION, prefetch=5000, offset=OFFSET)
client.run()
start_time = time.time()
for event_data in receiver.receive(timeout=100):
last_offset = event_data.offset
last_sn = event_data.sequence_number
print("Received: offset {}, sn {}, (BODY LEN: {})".format(last_offset.value, last_sn, len(event_data.body_as_str())))
print(" Body: {}".format(event_data.body_as_str()))
print("")
total += 1
end_time = time.time()
client.stop()
run_time = end_time - start_time
print("Received {} messages in {} seconds".format(total, run_time))
except KeyboardInterrupt:
pass
finally:
client.stop()
答案 0 :(得分:1)
分区是Event Hub分配负载的方式。因此,如果为Event Hub分配了4个分区,则默认行为是发送给它的消息是在分配的分区之间轮流分配的。
您将需要使用4个读取器,或者定期从另一个分区读取一个(或多个)读取器来处理所有消息。
更多信息可在the docs
中找到