RocketMQ Analysis - end of message retry mechanism production

1 by producer.setRetryTimesWhenSendFailed(count)the number of messages sent by the producer to set the retry time to failure, the default value 2, i.e. after a failure, twice retried, the message transmitted three times in total

# com.alibaba.rocketmq.client.producer.DefaultMQProducer
private int retryTimesWhenSendFailed = 2;

2. The message sent by the producer retry mechanism

Paste the source code, the client version number is:3.2.6

# com.alibaba.rocketmq.client.impl.producer.DefaultMQProducerImpl#sendDefaultImpl
int timesTotal = 1 + this.defaultMQProducer.getRetryTimesWhenSendFailed();
int times = 0;
String[] brokersSent = new String[timesTotal];
for (; times < timesTotal && (endTimestamp - beginTimestamp) < maxTimeout; times++) {
    String lastBrokerName = null == mq ? null : mq.getBrokerName();
    MessageQueue tmpmq = topicPublishInfo.selectOneMessageQueue(lastBrokerName);
    if (tmpmq != null) {
        mq = tmpmq;
        brokersSent[times] = mq.getBrokerName();
        try {
            sendResult = this.sendKernelImpl(msg, mq, communicationMode, sendCallback, timeout);
            endTimestamp = System.currentTimeMillis();
            switch (communicationMode) {
            case ASYNC:
                return null;
            case ONEWAY:
                return null;
            case SYNC:
                if (sendResult.getSendStatus() != SendStatus.SEND_OK) {
                    if (this.defaultMQProducer.isRetryAnotherBrokerWhenNotStoreOK()) {
                        continue;
                    }
                }

                return sendResult;
            default:
                break;
            }
        }
        catch (Exception e) {
            endTimestamp = System.currentTimeMillis();
            continue;
        }
    }
    else {
        break;
    }
} // end of

Guess you like

Origin www.cnblogs.com/HeCG95/p/11761154.html