In the cluster consumption mode, after message consumption fails, the Broker redelivers the message through message retry.

The Broker will retry automatically only if the consumption mode is messagemodel.clustering, not broadcast mode.

What is a message consumption failure?

  1. Consumers return ConsumeConcurrentlyStatus RECONSUME_LATER
  2. The consumer returns NULL
  3. The consumer threw an exception and was not caught

After the maximum number of retries (16) is reached for messages that have been unsuccessfully consumed, they are delivered to the dead-letter queue and set to be consumed successfully

Message consumption retry

// messageDelayLevel definition private String messageDelayLevel ="1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h"; If the number of retries is 1, the interval for sending the first message is 10 seconds, and so onCopy the code

RocketMQ uses a “time-decay strategy” for message redelivery, where the more retries, the less likely the message will be consumed successfully.

For the retry message, a new message is copied and the backup Topic and QueueId are posted to the Topic SCHEDULE_TOPIC_XXXX. The scheduled task then schedules the retry and restores the queue to the original queue

Message sending retry

If the message fails to be sent, the system automatically retries the message twice by default.

You can use the message record table to record message information and sending status and compensate for messages that fail to be sent

/** Sets the maximum number of retries when a message fails to be sent. The default number is 2. */ public voidsetRetryTimesWhenSendFailed(int retryTimesWhenSendFailed) { this.retryTimesWhenSendFailed = retryTimesWhenSendFailed; } /** Send messages synchronously, */ Public SendResult send(Message MSG,long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {return this.defaultMQProducerImpl.send(msg, timeout);
}
Copy the code