[英]Error while trying to connect to azure event hub using amqp
我正在嘗試使用 python 和質子庫作為訂閱者(用於接收消息)連接到 azure 事件中心。
我找到了一個示例代碼,最終得到了:
import sys
import optparse
from proton import *
import urllib
mng = Messenger()
mng.start()
nb_partitions = 8
sasKeyName = "NAME"
sasPolicyKey = "KEY"
# safeSasPolicyKey = urllib.quote(sasPolicyKey, "")
safeSasPolicyKey = sasPolicyKey
args = []
for i in range(0, nb_partitions):
address = "amqps://%s:%s@clienteventhub-ns.servicebus.windows.net/NAME/ConsumerGroups/$Default" % (
sasKeyName, safeSasPolicyKey)
args.append(address + "/Partitions/" + str(i))
print(args)
for a in args:
# mng.subscribe(a)
mng.subscribe(a)
print "Subscribed to %s" % (a)
msg = Message()
while True:
mng.recv()
while mng.incoming:
try:
mng.get(msg)
except Exception, e:
print e
else:
print msg.address, msg.subject or "(no subject)", msg.properties, msg.body
我正在使用 pip 安裝的 python-qpid-proton (0.10) 在 macosx 上運行此代碼。
但我無法獲得事件中心的任何消息我知道我每分鍾從一個有效的不同腳本發送一條消息。 我做了以下我打印的輸出
訂閱 amqps://NAME:KEY@clienteventhub-ns.servicebus.windows.net/NAME/ConsumerGroups/$Default/Partitions/0 訂閱 amqps://NAME:KEY@clienteventhub-ns.servicebus.windows.net/ NAME/ConsumerGroups/$Default/Partitions/1 訂閱了 amqps://NAME:KEY@clienteventhub-ns.servicebus.windows.net/NAME/ConsumerGroups/$Default/Partitions/2 訂閱了 amqps://NAME:KEY@ clienteventhub-ns.servicebus.windows.net/NAME/ConsumerGroups/$Default/Partitions/3 訂閱 amqps://NAME:KEY@clienteventhub-ns.servicebus.windows.net/NAME/ConsumerGroups/$Default/Partitions/4訂閱 amqps://NAME:KEY@clienteventhub-ns.servicebus.windows.net/NAME/ConsumerGroups/$Default/Partitions/5 訂閱 amqps://NAME:KEY@clienteventhub-ns.servicebus.windows.net/ NAME/ConsumerGroups/$Default/Partitions/6 訂閱 amqps://NAME:KEY@clienteventhub-ns.servicebus.windows.net/NAME/ConsumerGroups/$Default/Partitions/7
你知道為什么這段代碼不能工作嗎? 謝謝
您無法接收消息的原因可能有多種。 這也可能是原因之一請檢查事件中心使用的出站端口 5671 /9352未被防火牆阻止。
參考這個鏈接
改變消費者組 --> $Default
到$default
address = "amqps://%s:%s@%s.servicebus.windows.net/%s/ConsumerGroups/$default" % (sasKeyName, safeSasPolicyKey,name_space,eventhub)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.