-
-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathbroker.py
More file actions
31 lines (24 loc) · 962 Bytes
/
broker.py
File metadata and controls
31 lines (24 loc) · 962 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
from collections.abc import AsyncGenerator
from taskiq import AckableMessage, AsyncBroker, BrokerMessage
class MyBroker(AsyncBroker):
def __init__(self) -> None:
# Please call this super method to set default values to
# many different fields.
super().__init__()
async def startup(self) -> None:
# Here you can do some startup magic.
# Like opening a connection.
return await super().startup()
async def shutdown(self) -> None:
# Here you can perform shutdown operations.
# Like closing connections.
return await super().shutdown()
async def kick(self, message: BrokerMessage) -> None:
# Send a message.message.
pass
async def listen(self) -> AsyncGenerator[bytes | AckableMessage, None]:
while True:
# Get new message.
new_message: bytes = ... # type: ignore
# Yield it!
yield new_message