class AsyncRabbitClient: (source)
Constructor: AsyncRabbitClient(rabbit_url, params, resp_queue)
This class implements RabbitMQ Publish and Subscribe async handling.
The RabbitMQ queue mechanism is used so that we can take advantage of good horizontal message scaling when needed.
Note that you only need to specify the rabbit_url parameter when you are sending messages, params and resp_queue are used for subscriptions.
- Functionality is implemented for:
- Sending work queue messages (on default exchange).
- Sending topic messages (on 'topic_routing' exchange).
- Consuming work queue messages using a permanent queue (on default exchange).
- Consuming topic messages using a temporary queue (on 'topic_routing' exchange).
- Consuming topic messages using a permanent queue (on 'topic_routing' exchange).
- Sends the following messages:
- {"msgType": "LinkUp", "host": <RabbitMQ-server>}
- {"msgType": "LinkDown", "host": "<RabbitMQ-server>", "why": "<exception text>"}
- {"msgType": <any>, ...}
| Method | __init__ |
The class initializer. |
| Async Method | publish |
Publish a message on specified work, or topic queue. |
| Async Method | start |
Start the used resources in a controlled way. |
| Async Method | start |
Start a work queue subscription that survives when the subscription ends. |
| Async Method | start |
Start topic queue subscription using subscription_type context. |
| Async Method | status |
Send RabbitMQ connection status on the response queue. |
| Async Method | stop |
Stop the used resources in a controlled way. |
| Instance Variable | channel |
RabbitMQ's connection channel object instance. |
| Instance Variable | conf |
RabbitParams object instance for RabbitMQ config parameters. |
| Instance Variable | connection |
RabbitMQ's connection object instance. |
| Instance Variable | host |
RabbitMQ servername. |
| Instance Variable | link |
LinkDown reported status. |
| Instance Variable | rabbit |
RabbitMQ's connection URL. |
| Instance Variable | resp |
Destination queue for consumed messages. |
| Async Method | _consume |
Consume an incoming subscription message from RabbitMQ. |
| Async Method | _initiate |
Establish communication with RabbitMQ (connection + channel). |
| Method | _on |
Handle unexpectedly closed connection events. |
| Async Method | _on |
Send a LinkUp message when the connection is reconnected. |
str, params: Optional[ RabbitParams] = None, resp_queue: Optional[ asyncio.Queue] = None):
(source)
¶
The class initializer.
| Parameters | |
rabbitstr | RabbitMQ's connection URL. |
params:Optional[ | Configuration parameters. |
respOptional[ | Destination queue for consumed messages. |
dict, topic: Optional[ str] = None, work_queue_name: Optional[ str] = None) -> bool:
(source)
¶
Publish a message on specified work, or topic queue.
Send a LinkDown message when communication fails.
| Parameters | |
message:dict | Message to be published. |
topic:Optional[ | Used for topic queue messages. |
workOptional[ | Used for work queue messages. |
| Returns | |
bool | Publisher delivery confirmation status. |
| Raises | |
AssertError | When a topic and work_queue_name are both empty. |
Start a work queue subscription that survives when the subscription ends.
Send a LinkDown message when communication fails.
Work queue name is defined in self.conf.program during the class initialization.
Start topic queue subscription using subscription_type context.
When permanent=True, a permanent subscription is activated, otherwise a temporary subscription is activated.
Send a LinkDown message when communication fails.
| Parameters | |
routinglist | Subscription topic(s). |
permanent:bool | Indicate a wanted subscription type (default is True). |
| Raises | |
AssertError | When routing_keys is not a list. |
Consume an incoming subscription message from RabbitMQ.
| Parameters | |
message:AbstractIncomingMessage | A message that fits the subscription criteria. |
Establish communication with RabbitMQ (connection + channel).
Send a LinkUp message when communication is established.
Handle unexpectedly closed connection events.
| Parameters | |
_:Any | Undocumented |
error:AMQPConnectionError | AMQP connection error instance. |