Rabbitmq publisher
RabbitMQ publisher implementation (optional dependency).
Uses aio-pika to publish events to an exchange with a routing key.
Dependency: aio-pika
Not installed by default; install extra: pip install pyagenity[rabbitmq]
.
Classes:
Name | Description |
---|---|
RabbitMQPublisher |
Publish events to RabbitMQ using aio-pika. |
Attributes:
Name | Type | Description |
---|---|---|
logger |
|
Attributes¶
Classes¶
RabbitMQPublisher
¶
Bases: BasePublisher
Publish events to RabbitMQ using aio-pika.
Attributes:
Name | Type | Description |
---|---|---|
url |
str
|
RabbitMQ connection URL. |
exchange |
str
|
Exchange name. |
routing_key |
str
|
Routing key for messages. |
exchange_type |
str
|
Type of exchange. |
declare |
bool
|
Whether to declare the exchange. |
durable |
bool
|
Whether the exchange is durable. |
_conn |
Connection instance. |
|
_channel |
Channel instance. |
|
_exchange |
Exchange instance. |
Methods:
Name | Description |
---|---|
__init__ |
Initialize the RabbitMQPublisher. |
close |
Close the RabbitMQ connection and channel. |
publish |
Publish an event to RabbitMQ. |
sync_close |
Synchronously close the RabbitMQ connection. |
Source code in pyagenity/publisher/rabbitmq_publisher.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
Attributes¶
Functions¶
__init__
¶
__init__(config=None)
Initialize the RabbitMQPublisher.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
dict[str, Any] | None
|
Configuration dictionary. Supported keys: - url: RabbitMQ URL (default: "amqp://guest:guest@localhost/"). - exchange: Exchange name (default: "pyagenity.events"). - routing_key: Routing key (default: "pyagenity.events"). - exchange_type: Exchange type (default: "topic"). - declare: Whether to declare exchange (default: True). - durable: Whether exchange is durable (default: True). |
None
|
Source code in pyagenity/publisher/rabbitmq_publisher.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
close
async
¶
close()
Close the RabbitMQ connection and channel.
Source code in pyagenity/publisher/rabbitmq_publisher.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
publish
async
¶
publish(event)
Publish an event to RabbitMQ.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
EventModel
|
The event to publish. |
required |
Returns:
Type | Description |
---|---|
Any
|
True on success. |
Source code in pyagenity/publisher/rabbitmq_publisher.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
sync_close
¶
sync_close()
Synchronously close the RabbitMQ connection.
Source code in pyagenity/publisher/rabbitmq_publisher.py
131 132 133 134 135 136 |
|