Skip to content

Instantly share code, notes, and snippets.

@Avalarion
Created December 8, 2012 23:19
Show Gist options
  • Save Avalarion/4242481 to your computer and use it in GitHub Desktop.
Save Avalarion/4242481 to your computer and use it in GitHub Desktop.
Not Running Python RabbitMQ Basis
#!/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