Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why need messageId in AMQP?

In the Spring AMQP Project, if messageProperties does not have messageId, they always create messageId.

Like This..

if (this.createMessageIds && messageProperties.getMessageId()==null) {
  messageProperties.setMessageId(UUID.randomUUID().toString());
}

I want to know what messageId is. So, I try to find out where messageId is used. But I couldn't find it in Spring AMQP Source.

What happens if messageId does not exist? Why is messageId needed in AMQP?

like image 458
Minwoo Avatar asked May 28 '16 02:05

Minwoo


1 Answers

The message id is only created if the converter's createMessageIds is true - it is false by default.

It is normally not required, unless you are using stateful retry on the consumer side.

When using stateful retry and a delivery fails, the message is rejected and redelivered by the broker. Since RabbitMQ does not include the number of retries in a header, we have to keep track of how many times the delivery has been attempted so that we can give up after the maxAttempts is reached. The message id is used to look up the retry state for this message.

like image 130
Gary Russell Avatar answered Nov 14 '22 22:11

Gary Russell