Created
May 10, 2011 15:49
-
-
Save matagus/964727 to your computer and use it in GitHub Desktop.
Publishing to a rabbitmq exchange using pika BlockingConnection
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
# -*- coding: UTF-8 -*- | |
from pika import PlainCredentials, ConnectionParameters, BasicProperties | |
from pika.adapters import BlockingConnection | |
from django.conf import settings | |
credentials = PlainCredentials( | |
settings.RABBIT["userid"], settings.RABBIT["password"]) | |
parameters = ConnectionParameters(credentials=credentials, | |
host=settings.RABBIT["host"], port=settings.RABBIT["port"], | |
virtual_host=settings.RABBIT["virtual_host"]) | |
connection = BlockingConnection(parameters) | |
channel = connection.channel() | |
channel.queue_declare(queue=settings.RABBIT["queue"], | |
durable=True, exclusive=False, auto_delete=False) | |
channel.basic_publish(exchange=settings.RABBIT["exchange"], | |
routing_key="mts.00000069", body=serialized_message, properties=BasicProperties( | |
content_type="application/octect-stream", delivery_mode=2)) | |
connection.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment