Last active
August 29, 2015 14:04
-
-
Save darth30joker/e07da7279cdf099471da to your computer and use it in GitHub Desktop.
It's an example of pika to send messages to rabbitmq
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
import pika | |
# create a connection for rabbitmq using localhost | |
connection = pika.BlockingConnection(pika.ConnectionParameters( | |
'localhost')) | |
channel = connection.channel() # create a channel | |
# declare an exchange | |
channel.exchange_declare(exchange='messages', type='direct') | |
# a routing is a label for a message | |
# receiver will decide which message to get according to routing | |
routings = ['info', 'warning', 'error'] | |
for routing in routings: | |
message = '%s message.' % routing | |
channel.basic_publish(exchange='messages', | |
routing_key=routing, | |
body=message) | |
print message | |
connection.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment