Worker¶
The Worker class for Topic subscription and Rpc Replies.
-
class
amqppy.consumer.Worker(broker, heartbeat_sec=None)[source]¶ This class handles a worker that listens for incoming Topics and Rpc requests.
Parameters: broker (str) – The URL for connection to RabbitMQ. Eg: ‘amqp://serviceuser:password@rabbit.host:5672//’ -
add_request(routing_key, on_request_callback, exchange='amqppy', durable=False, auto_delete=True, exclusive=False)[source]¶ Registers a new consumer for a RPC reply task. These tasks will be executed when a RPC request is invoked by publisher.Rpc.request().
Parameters: - rounting_key (str) – It defines the subscription interest. In terms of AMQP the routing key to bind on
- on_request_callback (method) – Called when a Rpc request is invoked, it should return the reply.
- exchange (str) – The exchange you want to publish the message.
- durable (bool) – Queue messages survives a reboot of RabbitMQ.
- auto_delete (bool) – Queues will auto-delete after use.
- exclusive (bool) – Ensures that is the unique consumer
-
add_topic(routing_key, on_topic_callback, queue=None, exclusive=False, exchange='amqppy', durable=False, auto_delete=True, no_ack=True, **kwargs)[source]¶ Registers a new consumer for a Topic subscriber. These tasks will be executed when a Topic is published by publisher.Topic.publish().
Parameters: - rounting_key (str) – The routing key to bind on.
- on_topic_callback (method) – Called when a topic is published.
- queue (str) – The name of the queue. If it is not provided the queue will be named the same as the ‘routing_key’.
- exclusive (bool) – Only one consumer is allowed.
- exchange (str) – The exchange you want to publish the message.
- durable (bool) – Queue messages survives a reboot of RabbitMQ.
- auto_delete (bool) – Queues will auto-delete after use.
- no_ack (bool) – Tell the broker that ACK reply is not needed. If it is False, an ACK will be sent automatically each time a message is consumed unless a amqppy.AbortConsume or amqppy.DeadLetterMessage is raised.
-
run()[source]¶ Start worker to listen. This will block the execution until the worker is stopped or an uncaught Exception
-