aboutsummaryrefslogtreecommitdiffstats
path: root/rmq/publisher.py
diff options
context:
space:
mode:
authorGravatar Christopher Baklid <[email protected]>2018-05-25 14:21:10 +0200
committerGravatar Christopher Baklid <[email protected]>2018-05-25 14:21:10 +0200
commit85dbc20a80a2b4c233708be1460da7909e205388 (patch)
tree36d98fca1d490ffe4af0b07defe979389fbe5390 /rmq/publisher.py
parentgenerate new queue based on session id to lock user to their own event chain (diff)
lint
Diffstat (limited to 'rmq/publisher.py')
-rw-r--r--rmq/publisher.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/rmq/publisher.py b/rmq/publisher.py
index 4ba9db9..1a9a5cf 100644
--- a/rmq/publisher.py
+++ b/rmq/publisher.py
@@ -1,6 +1,16 @@
import pika
-def publish(message, username='guest', password='guest', host='localhost', port=5672, queue='', routingkey='', exchange='', exchange_type=''):
+
+def publish(message,
+ username='guest',
+ password='guest',
+ host='localhost',
+ port=5672,
+ queue='',
+ routingkey='',
+ exchange='',
+ exchange_type=''):
+
credentials = pika.PlainCredentials(username, password)
connection = pika.BlockingConnection(pika.ConnectionParameters(host, port, '/', credentials))
properties = pika.BasicProperties(content_type='text/plain', delivery_mode=1)
@@ -11,10 +21,10 @@ def publish(message, username='guest', password='guest', host='localhost', port=
channel.queue_bind(exchange=exchange, queue=queue, routing_key=routingkey)
result = channel.basic_publish(
- exchange=exchange,
- routing_key=routingkey,
- body=message,
- properties=properties
+ exchange=exchange,
+ routing_key=routingkey,
+ body=message,
+ properties=properties
)
if result:
@@ -23,4 +33,3 @@ def publish(message, username='guest', password='guest', host='localhost', port=
print("not delivered")
connection.close()
-