Created
February 17, 2016 03:26
-
-
Save kiichi/1a1f94b090828682bfd2 to your computer and use it in GitHub Desktop.
RabbitMQ 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
| #!/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() |
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
| #!/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