-
Notifications
You must be signed in to change notification settings - Fork 1
/
consumer.py
29 lines (17 loc) · 999 Bytes
/
consumer.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
import asyncio
import stompman
server = stompman.ConnectionParameters(host="0.0.0.0", port=61616, login="admin", passcode=":=123") # noqa: S104
async def handle_message(message_frame: stompman.MessageFrame) -> None:
message_content = message_frame.body.decode()
if "Hi" not in message_content:
error_message = "Producer is not friendly :("
raise ValueError(error_message)
await asyncio.sleep(0.1)
print(f"received and processed friendly message: {message_content}") # noqa: T201
def handle_suppressed_exception(exception: Exception, message_frame: stompman.MessageFrame) -> None:
print(f"caught an exception, perhaps, producer is not friendly: {message_frame.body=!r} {exception=}") # noqa: T201
async def main() -> None:
async with stompman.Client(servers=[server]) as client:
await client.subscribe("DLQ", handler=handle_message, on_suppressed_exception=handle_suppressed_exception)
if __name__ == "__main__":
asyncio.run(main())