python script which subscribes/listens to Azure Event Hub?

℡╲_俬逩灬. 提交于 2019-12-11 12:13:39

问题


I am interested in listening to an Event Hub from a Python script and executing some code when an inbound message is detected.

On Ubuntu, using Python 2.7 with https://pypi.python.org/pypi/python-qpid-proton/0.10 and the example "receiver" script, I attempt to subscribe to a URI that looks like:

amqps://<key name>:<key>@<namespace>.servicebus.windows.net/<event hub name>/ConsumerGroups/$Default/Partitions/0

The following error is returned:

proton.MessengerException: Cannot subscribe to <...>

I believe that my Event Hub is set up correctly because I am able to send events into it using a separate "send" script and the Azure dashboard shows that events have arrived. But I am unable to connect as a subscriber to receive messages.


回答1:


I tried to reproduce your issue on Ubuntu Server, but failed.

Although you said set up your event hub correctly, I still suggest you can check the key name & key again via the CONFIGURE tab page of your event hub on Azure old portal and make sure the policy name key name defined that has the permission Listen in the Shared access policies. Or you can use RootManageSharedAccessKey & its key in the access connection information of your service bus to try again.

Also, you can refer to the sample event_hubs_receive_many.py at https://gist.github.com/tomconte/e2a4667185a9bf674f59 (it based on the proton sample async.py at https://qpid.apache.org/releases/qpid-proton-0.8/messenger/python/examples/async.py.html) to check your code.




回答2:


Take a look at https://github.com/Azure/azure-event-hubs-python

Try ./examples/recv.py to see if it works. Note that the SAS key needs to be URL encoded and the associated policy has Listen action defined. ADDRESS needs to be updated from your event hub configuration.



来源:https://stackoverflow.com/questions/34667183/python-script-which-subscribes-listens-to-azure-event-hub

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!