Skip to content

Instantly share code, notes, and snippets.

@darth30joker
Last active August 29, 2015 14:04
Show Gist options
  • Save darth30joker/e07da7279cdf099471da to your computer and use it in GitHub Desktop.
Save darth30joker/e07da7279cdf099471da to your computer and use it in GitHub Desktop.
It's an example of pika to send messages to rabbitmq
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