Skip to content

Instantly share code, notes, and snippets.

@kiichi
Created February 17, 2016 03:26
Show Gist options
  • Select an option

  • Save kiichi/1a1f94b090828682bfd2 to your computer and use it in GitHub Desktop.

Select an option

Save kiichi/1a1f94b090828682bfd2 to your computer and use it in GitHub Desktop.
RabbitMQ Sample Code
#!/usr/bin/env python
import pika
server = '192.168.64.2'
credentials = pika.PlainCredentials(username='test', password='test')
connection = pika.BlockingConnection(pika.ConnectionParameters(host=server,credentials=credentials))
channel = connection.channel()
channel.queue_declare(queue='hello')
def callback(ch, method, properties, body):
print(" [x] Received %r" % body)
channel.basic_consume(callback,
queue='hello',
no_ack=True)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
#!/usr/bin/env python
import pika
##########################
# Create Test user
# sudo rabbitmqctl add_user test test
# sudo rabbitmqctl set_user_tags test administrator
# sudo rabbitmqctl set_permissions -p / test ".*" ".*" ".*"
##########################
server = '192.168.64.2'
credentials = pika.PlainCredentials(username='test', password='test')
connection = pika.BlockingConnection(pika.ConnectionParameters(host=server,credentials=credentials))
channel = connection.channel()
channel.queue_declare(queue='hello')
channel.basic_publish(exchange='',
routing_key='hello',
body='Hello World!')
connection.close()
print(" [x] Sent 'Hello World!'")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment