concept consumer in category rabbitmq

This is an excerpt from Manning's book RabbitMQ in Depth.
As I detail the advantages of a messaging-based architecture, it’s important to note that these advantages could also impact the performance of systems like the login architecture described. Any number of problems may impact publisher performance, from networking issues to RabbitMQ throttling message publishers. When such events happen, your application will see degraded performance. In addition to horizontally scaling consumers, it’s wise to plan for horizontal scaling of message brokers to allow for better message throughput and publisher performance.
Basic.Reject is an AMQP-specified RPC response to a delivered message that informs the broker that the message couldn’t be processed. Like Basic.Ack, it carries with it the delivery tag created by RabbitMQ to uniquely identify the message on the channel on which your consumer is communicating with RabbitMQ. When a consumer rejects a message, you can instruct RabbitMQ to either discard the message or to requeue the message with the requeue flag. When the requeue flag is enabled, RabbitMQ will put the message back into the queue to be processed again.
I often use this feature in writing consumer applications that communicate with other services, such as databases or remote APIs. Instead of writing logic in my consumer for retrying on failure due to a remote exception, such as a disconnected database cursor or failure to contact a remote API, I simply catch the exception and reject the message with requeue set to True. This allows me to simplify my code paths in a consumer, and when used in conjunction with a stats program such as Graphite, I can see trends in exception behavior by watching the requeue velocity.
The following example, from the “5.3.1 Message Rejection” notebook, demonstrates how when a message is requeued, the redelivered flag is set in the message, informing the message’s next consumer that it had been previously delivered. I’ve used this functionality to implement a “two-strikes and you’re out” policy. A malformed message may cause havoc in a consumer, but if you’re uncertain whether the problem is due to the message or something else in the consumer, inspecting the redelivered flag is a good way to determine if you should reject the message to be requeued or discarded when an error is encountered.
import rabbitpy for message in rabbitpy.consume('amqp://guest:guest@localhost:5672/%2f', 1 'test-messages'): message.pprint() 2 print('Redelivered: %s' % message.redelivered) 3 message.reject(True) 41 Iterates over messages as a consumer
The AMQP specification calls for channels to have a quality of service (QoS) setting where a consumer can ask for a prespecified number of messages to be received prior to the consumer acknowledging receipt of the messages. The QoS setting allows RabbitMQ to more efficiently send messages by specifying how many messages to preallocate for the consumer.
Unlike a consumer with acknowledgments disabled (no_ack=True), if your consumer application crashes before it can acknowledge the messages, all the prefetched messages will be returned to the queue when the socket closes.
At the protocol level, sending a Basic.QoS RPC request on a channel specifies the quality of service. As part of this RPC request, you can specify whether the QoS setting is for the channel it’s sent on or all channels open on the connection. The Basic.QoS RPC request can be sent at any time, but as illustrated in the following code from the “5.2.2 Specifying QoS” notebook, it’s usually performed prior to a consumer issuing the Basic.Consume RPC request.