Skip to content

Instantly share code, notes, and snippets.

@tomconte
Created March 31, 2015 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomconte/e2a4667185a9bf674f59 to your computer and use it in GitHub Desktop.
Save tomconte/e2a4667185a9bf674f59 to your computer and use it in GitHub Desktop.
Based on the Proton AMQP Python examples (https://qpid.apache.org/releases/qpid-proton-0.8/messenger/python/examples/index.html), here is a script that will listen on all 16 partitions for a single Event Hub and print all messages. You need to have the "async.py" script from the examples in the same directory.
#!/usr/bin/python
# Receive messages from an Azure Event Hub using the Apache Qpid Proton AMQP library.
import sys
from async import *
# Event Hub address & credentials
# amqps://<keyname>:<key>@<namespace>.servicebus.windows.net/<eventhubname>/ConsumerGroup/<consumergroup>/Partitions/<partition>
# You can find <keyname> and <key> in your Service Bus connection information
# <namespace> is your SB top-level namespace
# <eventhubname> is the name of your Event Hub
# <consumergroup> is the name of an existing Consumer Group; use $Default for the default
# <partition> is a partition ID; a default Event Hub has partitions numbered from 0 to 15
nb_partitions = 16
args = []
for i in xrange(0,nb_partitions):
args.append("amqps://RootManageSharedAccessKey:xxxx4WbZxxxxyMEAxxxxrEd8xxxxdMlixxxxwVzmxxxx@tomhub-ns.servicebus.windows.net/loadbbb/ConsumerGroups/$Default/Partitions/" + str(i))
print args
class App(CallbackAdapter):
def on_start(self):
print "Started"
for a in args:
print "Subscribing to:", a
self.messenger.subscribe(a)
self.messenger.recv()
def on_recv(self, msg):
print "Received:", msg
if msg.body == "die":
self.stop()
def on_stop(self):
print "Stopped"
a = App(Messenger())
a.run()
@srgrn
Copy link

srgrn commented Oct 19, 2015

Hi, I have tried using this example but i don't get anything out of the event hub, should the key be url encoded?
Any help would be appriciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment