Created
March 7, 2019 10:59
-
-
Save samsee/b2492fc09e3adaed49a8588560dcc23a to your computer and use it in GitHub Desktop.
RabbitMQ message send/receive
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
import pika | |
IP = __YOUR_RABBITMQ_IP__ | |
PORT = __YOUR_RABBITMQ_PORT__ | |
connection = pika.BlockingConnection(pika.ConnectionParameters(host=IP, port=PORT)) | |
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 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
import pika | |
IP = __YOUR_RABBITMQ_IP__ | |
PORT = __YOUR_RABBITMQ_PORT__ | |
connection = pika.BlockingConnection(pika.ConnectionParameters(host=IP, port=PORT)) | |
channel = connection.channel() | |
channel.queue_declare(queue='hello') | |
channel.basic_publish(exchange='', | |
routing_key='hello', | |
body="Hello World!") | |
print(" [x] Sent 'Hello World!'") | |
connection.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment