Commit 28354233 authored by Alexander Lercher's avatar Alexander Lercher

Working RabbitMQ as message broker

parent 8d0455c7
...@@ -5,7 +5,7 @@ metadata: ...@@ -5,7 +5,7 @@ metadata:
name: rabbit-mq name: rabbit-mq
spec: spec:
replicas: 2 replicas: 1
selector: selector:
matchLabels: matchLabels:
app: rabbit-mq app: rabbit-mq
......
import pika
EXCHANGE_NAME = 'beacon'
connection = pika.BlockingConnection(pika.ConnectionParameters('143.205.173.36', 30302, heartbeat=600, blocked_connection_timeout=300))
channel = connection.channel()
channel.exchange_declare(exchange=EXCHANGE_NAME, exchange_type='fanout')
result = channel.queue_declare(queue='', exclusive=True)
queue_name = result.method.queue
channel.queue_bind(exchange=EXCHANGE_NAME, queue=queue_name, routing_key='')
def callback(ch, method, properties, body):
print(f"### Received: {body}")
ch.basic_ack(delivery_tag=method.delivery_tag)
channel.basic_consume(queue=queue_name,
auto_ack=False,
on_message_callback=callback)
channel.start_consuming()
import pika
import random
EXCHANGE_NAME = 'beacon'
connection = pika.BlockingConnection(pika.ConnectionParameters('143.205.173.36', 30302, heartbeat=600, blocked_connection_timeout=300))
channel = connection.channel()
channel.exchange_declare(exchange=EXCHANGE_NAME, exchange_type='fanout')
message = f'test {random.random()}'
channel.basic_publish(exchange=EXCHANGE_NAME, routing_key='', body=message)
print(f"# Sent {message}")
connection.close()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment