Created
December 8, 2012 23:19
-
-
Save Avalarion/4242481 to your computer and use it in GitHub Desktop.
Not Running Python RabbitMQ Basis
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
#!/usr/bin/env python | |
import pika | |
class rabbitmq_basis(object): | |
def __init__(self, host, port, user, password, vhost ): | |
self.host = host | |
self.port = port | |
self.user = user | |
self.password = password | |
self.vhost = vhost | |
credentials = pika.PlainCredentials(user, password) | |
conn_params = pika.ConnectionParameters(host = host, port = port, credentials = credentials) | |
self.conn = pika.BlockingConnection(conn_params) | |
def __del__(self): | |
self.conn.close() | |
self.conn = None | |
self = None | |
def publish(self, queue, message): | |
ch = self.conn.channel() | |
ch.exchange_declare(queue, "fanout", TRUE, FALSE) | |
msg = amqp.Message(message) | |
msg.properties["content_type"] = "text/plain" | |
msg.properties["delivery_mode"] = 2 | |
ch.basic_publish(queue, "", message) | |
ch.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment