-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemit_log.py
36 lines (25 loc) · 922 Bytes
/
emit_log.py
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
import asyncio
import sys
from aio_pika import DeliveryMode, ExchangeType, Message, connect
async def main() -> None:
# Perform connection
connection = await connect("amqp://guest:guest@localhost/")
async with connection:
channel = await connection.channel()
topic_logs_exchange = await channel.declare_exchange(
"topic_logs",
ExchangeType.TOPIC,
)
routing_key = sys.argv[1] if len(sys.argv) > 2 else "anonymous.info"
message_body = (
b" ".join(arg.encode() for arg in sys.argv[2:]) or b"Hello World!"
)
message = Message(
message_body,
delivery_mode=DeliveryMode.PERSISTENT,
)
# Sending the message
await topic_logs_exchange.publish(message, routing_key=routing_key)
print(f" [x] Sent {message!r}")
if __name__ == "__main__":
asyncio.run(main())