|
1 | 1 | from asyncio import AbstractEventLoop |
| 2 | +from logging import getLogger |
2 | 3 | from typing import Any, AsyncGenerator, Optional, TypeVar |
3 | 4 |
|
4 | 5 | from aio_pika import Channel, ExchangeType, Message, connect_robust |
|
10 | 11 |
|
11 | 12 | _T = TypeVar("_T") |
12 | 13 |
|
| 14 | +logger = getLogger("taskiq.aio_pika_broker") |
| 15 | + |
13 | 16 |
|
14 | 17 | class AioPikaBroker(AsyncBroker): |
15 | 18 | def __init__( |
@@ -84,12 +87,18 @@ async def listen(self) -> AsyncGenerator[BrokerMessage, None]: |
84 | 87 | async for rmq_message in queue_iter: |
85 | 88 | async with rmq_message.process(): |
86 | 89 | try: |
87 | | - yield BrokerMessage.parse_raw( |
88 | | - rmq_message.body, |
89 | | - content_type=rmq_message.content_type or "", |
| 90 | + yield BrokerMessage( |
| 91 | + task_id=rmq_message.headers["task_id"], |
| 92 | + task_name=rmq_message.headers["task_name"], |
| 93 | + message=rmq_message.body, |
| 94 | + headers=rmq_message.headers, |
| 95 | + ) |
| 96 | + except (ValueError, LookupError) as exc: |
| 97 | + logger.debug( |
| 98 | + "Cannot read broker message %s", |
| 99 | + exc, |
| 100 | + exc_info=True, |
90 | 101 | ) |
91 | | - except ValueError: |
92 | | - continue |
93 | 102 |
|
94 | 103 | async def shutdown(self) -> None: |
95 | 104 | await self.connection_pool.close() |
0 commit comments