Base
BaseRabbitMQ
A base class for interacting with RabbitMQ.
Attributes:
| Name | Type | Description |
|---|---|---|
_sd |
The service discovery instance. |
|
url |
The RabbitMQ connection URL. |
|
connection |
The RabbitMQ connection. |
|
exchange |
The RabbitMQ exchange. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the BaseRabbitMQ object. |
_connect |
Connect to RabbitMQ. |
connect |
Retry connecting to RabbitMQ until successful. |
on_connection_error |
Handle connection errors. |
create_channel |
Create a new channel in the RabbitMQ connection. |
declare_exchange |
Declare a RabbitMQ exchange. |
create_queue |
Create a RabbitMQ queue and bind it to an exchange. |
close_connection |
Close the RabbitMQ connection. |
publish_message |
Publish a message to a RabbitMQ exchange. |
Source code in libs/python/resources/py-rabbitmq/pyrabbitmq/base.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
connect(max_retries=5)
async
Retry connecting to RabbitMQ until successful.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_retries |
int
|
The maximum number of connection retries. |
5
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If failed to connect to RabbitMQ after multiple retries. |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in libs/python/resources/py-rabbitmq/pyrabbitmq/base.py
on_connection_error(error)
Handle connection errors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error |
Exception
|
The connection error. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in libs/python/resources/py-rabbitmq/pyrabbitmq/base.py
declare_exchange(channel, exchange_name)
async
Declare a RabbitMQ exchange.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel |
Channel
|
The channel to declare the exchange on. |
required |
exchange_name |
str
|
The name of the exchange. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in libs/python/resources/py-rabbitmq/pyrabbitmq/base.py
create_queue(channel, queue_name, exchange_name, routing_key)
async
Create a RabbitMQ queue and bind it to an exchange.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel |
Channel
|
The channel to create the queue on. |
required |
queue_name |
str
|
The name of the queue. |
required |
exchange_name |
str
|
The name of the exchange to bind the queue to. |
required |
routing_key |
str
|
The routing key to use for binding. |
required |
Returns:
| Type | Description |
|---|---|
Queue
|
aio_pika.Queue: The created queue. |
Source code in libs/python/resources/py-rabbitmq/pyrabbitmq/base.py
close_connection()
async
Close the RabbitMQ connection.
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in libs/python/resources/py-rabbitmq/pyrabbitmq/base.py
publish_message(exchange_name, routing_key, message)
async
Publish a message to a RabbitMQ exchange.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exchange_name |
str
|
The name of the exchange to publish to. |
required |
routing_key |
str
|
The routing key for the message. |
required |
message |
str
|
The message to publish. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |