Added on the consumer MQ configuration file, the configuration key code is ACKNOWLEDEG = "Manual"
, meaning that the consumer's ACK is manually (at this point the queue has been bound to the producer's exchange through a routekey)
<rabbit:listener-container connection-factory= "connectionfactory" acknowledge= "Manual" > <rabbit:listener Queues= "queue_xxx" ref= "Mqconsumer"/> <rabbit:listener queues= "queue_xxx" ref= "MqConsumer2"/> </rabbit :listener-container>
Create a new class Mqconsumer, implement the interface Channelawaremessagelistener, implement the OnMessage method, and do not need to specify a method.
Key points after implementing the Channelawaremessagelistener OnMessage method, there are 2 parameters.
One is the message (the messaging entity), and the channel is the current one.
Many places are not clear how to go to manual ack, in fact, the manual ack is in the current channel inside the call Basicask method, and incoming current message tagid on it.
Note that if you throw an exception or unack (and Requeue is true), the message will always be re-queued, accidentally xxxxx a lot of messages repeatedly.
The identity of the message, false only confirms that the current message was received, and true confirms that all consumer received the message (normal consumption)
Channel.basicack (Message.getmessageproperties (). Getdeliverytag (), false);
ACK returns false and goes back to the queue, which is clearly explained in the API (local exception)
Channel.basicnack (Message.getmessageproperties (). Getdeliverytag (), false, true);
Reject Message
Channel.basicreject (Message.getmessageproperties (). Getdeliverytag (), true);