Created
March 31, 2015 13:46
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.