diff options
| author | 2018-05-21 18:02:07 +0200 | |
|---|---|---|
| committer | 2018-05-21 18:02:07 +0200 | |
| commit | 964054baf1e02fb017deec9d2f4cd8b65f19944a (patch) | |
| tree | 6ce672a025c5f8c59109888f2299b4cfdf21be9b /runner/publish.py | |
| parent | Initial commit (diff) | |
init commit
Diffstat (limited to 'runner/publish.py')
| -rw-r--r-- | runner/publish.py | 42 | 
1 files changed, 42 insertions, 0 deletions
| diff --git a/runner/publish.py b/runner/publish.py new file mode 100644 index 0000000..fc18d03 --- /dev/null +++ b/runner/publish.py @@ -0,0 +1,42 @@ +import pika +from config import ( +    USERNAME, +    PASSWORD, +    HOST, +    PORT, +    EXCHANGE, +    EXCHANGE_TYPE, +    QUEUE, +    ROUTING_KEY, +) + +def send(message): +    credentials = pika.PlainCredentials(USERNAME, PASSWORD) +    connection = pika.BlockingConnection(pika.ConnectionParameters(HOST, PORT, '/', credentials)) +    properties = pika.BasicProperties(content_type='text/plain', delivery_mode=1) + +    channel = connection.channel() +    channel.queue_declare(queue=QUEUE, durable=False) +    channel.exchange_declare(exchange=EXCHANGE, exchange_type=EXCHANGE_TYPE) +    channel.queue_bind(exchange=EXCHANGE, queue=QUEUE, routing_key=ROUTING_KEY) + +    result = channel.basic_publish( +                exchange=EXCHANGE, +                routing_key=ROUTING_KEY, +                body=message, +                properties=properties +    ) + +    if result: +        print(f"""Connecting to +            host: {HOST} +            port: {PORT} +            exchange: {EXCHANGE} +            queue: {QUEUE}""", flush=True) +        print(f"Sent: '{message}'") +    else: +        print("not delivered") + +    connection.close() + +send('print "bacon is delicious"') | 
