Skip to content

Commit c7da350

Browse files
author
Alan Christie
committed
test: Better ampq-publisher
1 parent 9cc114a commit c7da350

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

ampq_publisher.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env python
22
"""A simple RabbitMQ message publisher for local testing.
3-
Takes a 'routing key' and sends a message to the 'expected' AS exchange
4-
on a localhost RabbitMQ server. The AMPQ URL is specified below and is expected
3+
4+
Takes a 'routing key' and sends a built-in message to the 'event-streams' AS exchange
5+
on a RabbitMQ server. The AMPQ URL is specified below and is expected
56
to match the ESS_AMPQ_URL value used in the project's docker-compose file.
67
It can be changed by providing a second argument on the command line.
78
@@ -48,6 +49,9 @@
4849

4950
async def main() -> None:
5051
"""Publish a message."""
52+
body_str: str = f"{_MESSAGE_CLASS}|{_MESSAGE_STRING}"
53+
print(f"Sending {body_str} (to {_AMPQ_URL})...")
54+
5155
connection = await aio_pika.connect_robust(_AMPQ_URL)
5256
async with connection:
5357
channel = await connection.channel()
@@ -58,7 +62,7 @@ async def main() -> None:
5862
durable=True,
5963
)
6064
await es_exchange.publish(
61-
aio_pika.Message(body=f"{_MESSAGE_CLASS}|{_MESSAGE_STRING}".encode()),
65+
aio_pika.Message(body_str.encode()),
6266
routing_key=_ROUTING_KEY,
6367
)
6468

0 commit comments

Comments
 (0)