Message reliability of rabbitmq message response and persistence

Ack message response

Introduced in front of rabbitmq There are two modes ack

  • Automatic ACK : rabbitmq messages sent from the queue to the consumer from the queue memory to delete the message. At this time, if the consumer is down and other reasons not had time to complete consumption message, the message is lost.
  • Manual ack : Consumers ack again in the future to determine complete consumption of news, rabbitmq server receives ack before from memory deletes the message queue, this way, we can ensure that messages are not lost in this part of the consumer and the queue. Note that doing so might result in duplication consumer information, consumer power and other processing needs to be done.

If you are using manual answer needs to be done in two steps:

  1. Consumers basicConsume method to turn off automatic response, the second argument is false:channel.basicConsume(QUEUE_NAME, false, consumer);
  2. Consumers back off function com.rabbitmq.client.DefaultConsumer#handleDeliveryto submit the manual ack receiptchannel.basicAck(envelope.getDeliveryTag(), false);

Endurance of

Note that the above messages are deleted from memory rabbitmq server's memory is unreliable, power loss data. Then you need the message persistence to ensure the reliability of the message.

Want to declare a persistent queue is very easy to modify channel.queueDeclarethe second argument is true you can:

channel.queueDeclare(QUEUE_NAME, true, false, false, null);

Note: For a non-persistent queue, can not directly be amended to persist, otherwise it will not start service error. The solution is to create a new queue, or queue will be deleted from the old server.

Published 233 original articles · won praise 211 · views 900 000 +

Guess you like

Origin blog.csdn.net/fgyibupi/article/details/104401647