Commit b05b8172 authored by Dan Jones's avatar Dan Jones
Browse files

Merge branch '1-prototype' into 'dev'

prototype soar backbone implementation

Closes #1

See merge request !3
parents c3325b03 73f478a0
#!/usr/bin/env python
import pika
import json
import sys
def get_connection():
return pika.BlockingConnection(pika.ConnectionParameters(host="localhost"))
def deliver(body, topic, publish_exchange):
print("publish on topic: %s" % topic)
deliver_connection = get_connection()
deliver_channel = deliver_connection.channel()
deliver_channel.exchange_declare(exchange=publish_exchange, exchange_type="topic")
deliver_channel.basic_publish(
exchange=publish_exchange, routing_key=topic, body=body
)
deliver_connection.close()
def listen(queue_name, publish_exchange):
def pub_callback(ch, method, properties, body):
message = json.loads(body.decode())
topic = message["topic"]
deliver(body, topic, publish_exchange)
ch.basic_ack(delivery_tag=method.delivery_tag)
listen_connection = get_connection()
listen_channel = listen_connection.channel()
listen_channel.queue_declare(queue=queue_name, durable=True)
listen_channel.basic_consume(queue=queue_name, on_message_callback=pub_callback)
listen_channel.start_consuming()
def publish(queue_name, publish_exchange="soar_publish"):
listen(queue_name, publish_exchange)
if __name__ == "__main__":
queue_name = sys.argv[1]
publish(queue_name)
#!/usr/bin/env python
import pika
def get_connection():
return pika.BlockingConnection(pika.ConnectionParameters(host="localhost"))
def subscribe(
queue_name,
topic,
publish_exchange="soar_publish",
broadcast_exchange="soar_broadcast",
):
adm_connection = get_connection()
admin_channel = adm_connection.channel()
admin_channel.exchange_declare(exchange=broadcast_exchange, exchange_type="fanout")
admin_channel.queue_bind(exchange=broadcast_exchange, queue=queue_name)
sub_connection = get_connection()
subscriber_channel = sub_connection.channel()
subscriber_channel.exchange_declare(
exchange=publish_exchange, exchange_type="topic"
)
subscriber_channel.queue_bind(
exchange=publish_exchange, queue=queue_name, routing_key=topic
)
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