AMQP / RabbitMQ

In [17]:
parameters = pika.URLParameters('amqp://guest:[email protected]:5672/%2F')
connection = pika.BlockingConnection(parameters)
In [3]:
import pika

connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')

channel.basic_publish(exchange='', routing_key='hello', body='World1!')
channel.basic_publish(exchange='', routing_key='hello', body='World2b!')
channel.basic_publish(exchange='', routing_key='hello', body='World3b!')
connection.close()
docker exec rabbitmq rabbitmqctl list_queues

Listing queues ... hello 1

In [1]:
# https://www.rabbitmq.com/tutorials/tutorial-four-python.html

import pika
import sys

connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()

channel.exchange_declare(exchange='direct_logs',
                         type='direct')

severity = sys.argv[1] if len(sys.argv) > 2 else 'info'
message = ' '.join(sys.argv[2:]) or 'Hello World!'
channel.basic_publish(exchange='direct_logs',
                      routing_key=severity,
                      body=message)
print(" [x] Sent %r:%r" % (severity, message))
connection.close()
 [x] Sent '-f':'/root/.local/share/jupyter/runtime/kernel-39351ee5-5352-4665-9bc3-db9075c95ad4.json'