Created
November 3, 2012 03:47
-
-
Save quiver/4005759 to your computer and use it in GitHub Desktop.
rabbitmq : mirrored-queue sample code
This file contains hidden or 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
from pika.adapters import BlockingConnection | |
connection = BlockingConnection() | |
channel = connection.channel() | |
def callback(ch, method, properties, body): | |
print " [x] Received %r" % (body,) | |
channel.basic_consume(callback, | |
queue='test_queue', | |
no_ack=True) | |
channel.start_consuming() |
This file contains hidden or 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
# http://karlgrz.blogspot.jp/2012/10/rabbitmq-highly-available-queues-and.html | |
from pika.adapters import BlockingConnection | |
from pika import BasicProperties | |
connection = BlockingConnection() | |
channel = connection.channel() | |
client_params = {"x-ha-policy": "all"} | |
exchange_name = 'public' | |
queue_name = 'test_queue' | |
routing_key = 'test_routing_key' | |
channel.exchange_declare(exchange=exchange_name, type='topic') | |
channel.queue_declare(queue=queue_name, durable=True, arguments=client_params ) | |
channel.queue_bind(exchange=exchange_name, queue=queue_name, routing_key=routing_key) | |
channel.basic_publish(exchange=exchange_name, routing_key=routing_key, body='testing mirroring!', properties=BasicProperties(content_type="text/plain", delivery_mode=2)) | |
# delivery_mode 1 : nonpersistent | |
# delivery_mode 2 : persistent | |
print "publish complete" | |
connection.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment