我正在尝试使用 python 和质子库作为订阅者(用于接收消息)连接到天蓝色事件中心。
我找到了一个示例代码,最终得到:
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
你知道为什么这段代码不能工作吗?谢谢