forked from fortable1999/pubsubdemo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpub.py
More file actions
36 lines (26 loc) · 816 Bytes
/
pub.py
File metadata and controls
36 lines (26 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
import asyncio
import aioamqp
import json
import logging
async def produce():
try:
transport, protocol = await aioamqp.connect('localhost', 5672)
except aioamqp.AmqpClosedConnection:
print("closed connections")
return
queue_name = 'taas.test_queue'
channel = await protocol.channel()
await asyncio.wait_for(channel.queue(queue_name, durable=False, auto_delete=True), timeout=10)
data = {"id": "1"}
await channel.publish(json.dumps(data), '', queue_name)
print("Pushed")
await protocol.close()
class Tester(object):
def __init__(self, queue_name, host, port):
"""docstring for __"""
pass
def main():
asyncio.get_event_loop().run_until_complete(produce())
if __name__ == '__main__':
main()