Difference between revisions of "RabbitMQ"
From Christoph's Personal Wiki
(Created page with "'''RabbitMQ''' is an open source message broker software (sometimes called message-oriented middleware) that implements the Advanced Message Queuing Protocol (AMQP). ==Exampl...") |
(→External links) |
||
Line 37: | Line 37: | ||
==External links== | ==External links== | ||
* [https://www.rabbitmq.com/ Official website] | * [https://www.rabbitmq.com/ Official website] | ||
+ | * [http://www.rabbitmq.com/tutorials/tutorial-one-python.html RabbitMQ with Python] (tutorial) | ||
[[Category:Linux Command Line Tools]] | [[Category:Linux Command Line Tools]] |
Latest revision as of 03:20, 29 April 2016
RabbitMQ is an open source message broker software (sometimes called message-oriented middleware) that implements the Advanced Message Queuing Protocol (AMQP).
Examples
This section gives sample programs written in Python for sending and receiving messages using a queue.
Sending
The following code fragment establishes a connection, makes sure the recipient queue exists, then sends a message and finally closes the connection.
#!/usr/bin/env python import pika connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) channel = connection.channel() channel.queue_declare(queue='hello') channel.basic_publish(exchange='', routing_key='hello', body='Hello World!') print " [x] Sent 'Hello World!'" connection.close()
Receiving
Similarly, the following program receives messages from the queue and prints them on the screen:
#!/usr/bin/env python import pika connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost')) channel = connection.channel() channel.queue_declare(queue='hello') print ' [*] Waiting for messages. To exit press CTRL+C' def callback(ch, method, properties, body): print " [x] Received %r" % (body,) channel.basic_consume(callback, queue='hello', no_ack=True) channel.start_consuming()
External links
- Official website
- RabbitMQ with Python (tutorial)