44from contextlib import AsyncExitStack
55from functools import cached_property
66
7- from aio_pika import (
8- Exchange as AioPikaExchange ,
9- RobustChannel ,
10- connect_robust ,
11- )
7+ from aio_pika import Exchange as AioPikaExchange , RobustChannel
128from aio_pika .abc import AbstractRobustConnection
139
1410from icij_common .logging_utils import LogWithNameMixin
1511from icij_worker import ManagerEvent
1612from . import EventPublisher
1713from ..routing_strategy import Routing
18- from ..utils .amqp import AMQPMixin , RobustConnection
14+ from ..utils .amqp import AMQPMixin
1915
2016
2117class AMQPPublisher (AMQPMixin , EventPublisher , LogWithNameMixin ):
2218 def __init__ (
2319 self ,
24- logger : Optional [ logging .Logger ] = None ,
20+ logger : logging .Logger | None = None ,
2521 * ,
2622 broker_url : str ,
2723 connection_timeout_s : float = 1.0 ,
2824 reconnection_wait_s : float = 5.0 ,
2925 is_qpid : bool = False ,
3026 app_id : str | None = None ,
31- connection : Optional [ AbstractRobustConnection ] = None ,
27+ connection : AbstractRobustConnection | None = None ,
3228 ):
3329 super ().__init__ (
3430 broker_url ,
@@ -42,8 +38,8 @@ def __init__(
4238 self ._app_id = app_id
4339 self ._broker_url = broker_url
4440 self ._connection_ = connection
45- self ._channel_ : Optional [ RobustChannel ] = None
46- self ._manager_evt_x : Optional [ AioPikaExchange ] = None
41+ self ._channel_ : RobustChannel | None = None
42+ self ._manager_evt_x : AioPikaExchange | None = None
4743 self ._connection_timeout_s = connection_timeout_s
4844 self ._reconnection_wait_s = reconnection_wait_s
4945 self ._exit_stack = AsyncExitStack ()
@@ -73,13 +69,8 @@ async def _publish_event(self, event: ManagerEvent):
7369
7470 async def _connection_workflow (self ):
7571 self .debug ("creating connection..." )
76- if self ._connection_ is None :
77- self ._connection_ = await connect_robust (
78- self ._broker_url ,
79- timeout = self ._connection_timeout_s ,
80- reconnect_interval = self ._reconnection_wait_s ,
81- connection_class = RobustConnection ,
82- )
72+ if self ._connection is None :
73+ await self ._connect ()
8374 await self ._exit_stack .enter_async_context (self ._connection )
8475 self .debug ("creating channel..." )
8576 self ._channel_ = await self ._connection .channel (
0 commit comments