In [ ]:
# Import the RabbitMQ Client Library
import rabbitpy
In [ ]:
# Specify the URL to connect to
url = 'amqp://guest:guest@localhost:5672/%2F'
In [ ]:
# Connect to RabbitMQ using the URL above
connection = rabbitpy.Connection(url)
In [ ]:
# Open a new channel on the connection
channel = connection.channel()
In [ ]:
# Create a new exchange object, passing in the channel to use
exchange = rabbitpy.Exchange(channel, 'chapter2-example')
In [ ]:
# Declare the exchange on the RabbitMQ server
exchange.declare()
In [ ]:
# Create a new queue object, passing in the channel to use
queue = rabbitpy.Queue(channel, 'example')
In [ ]:
# Declare the queue on the RabbitMQ server
queue.declare()
In [ ]:
# Bind the queue to the exchange on the RabbitMQ server
queue.bind(exchange, 'example-routing-key')
In [ ]:
for message_number in range(0, 10):
message = rabbitpy.Message(channel,
'Test message #%i' % message_number,
{'content_type': 'text/plain'},
opinionated=True)
message.publish(exchange, 'example-routing-key')