【发布时间】:2016-01-24 11:27:47
【问题描述】:
我正在尝试使用 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
你知道为什么这段代码不能工作吗? 谢谢
【问题讨论】:
-
我重现了这个问题。我尝试按照文档msdn.microsoft.com/en-us/library/azure/jj841070.aspx 接收来自EventHubs 的消息,但失败了。我没有找到任何其他文档用于在 Python 中使用 EventHubs 中的事件。所以我建议使用 C#/.Net 的 EventProcessorHost(azure.microsoft.com/en-us/documentation/articles/…) 来做。
-
所以你说我应该把它作为一个支持天蓝色的错误打开?
-
你能设置以下环境变量吗?它应该显示 Proton 协议跟踪:export PN_TRACE_FRM=true
标签: python azure qpid azure-eventhub