EXCHANGES¶
To declare an Exchange with all parameters in Propan, a special class propan.brokers.rabbit.RabbitExchange is used.
You can use it both when receiving messages and sending them:
from propan.brokers.rabbit import RabbitBroker, RabbitExchange
broker = RabbitBroker()
@broker.handler("test", exchange=RabbitExchange("test"))
async def handler():
...
...
await broker.publish("Hi!", "test", exchange=RabbitExchange("test"))
The RabbitExchange constructor takes the following arguments:
name:str - exchange nametype: propan.brokers.rabbit.RabbitExchange = RabbitExchange.DIRECT - exchange routing typedurable: bool = False - if set to True, restore exchange at RabbitMQ restartedauto_delete: bool = False - if set to True, exchange will be deleted if there are no queues listening to itpassive: bool = False- when set to
False, Propan creates an exchange with the required parameters, or check the corresponding parameters of an already existing exchange with the same name. - when set to
True, Propan will not create an exchange, but only connect to an existing one. In this case, if the requested exchange does not exist, an error occurred
- when set to
internal: bool = False - create exchange object at runtime and don't notify RabbitMQ about exchange creationrobust: bool = True - recreate exchange when reconnecting to RabbitMQtimeout: int | float - response timeout from RabbitMQarguments: dict[str, Any] | None = None - exchange custom arguments
And arguments to bind current exchange to another one
bind_to: RabbitExchange | None = None - parent exchange to bindbind_arguments: dict[str, Any] | None = None - arguments to header exchange routingrouting_key: str = "" - routing key for connecting to exchange