版本:4.2.0
producer在发送消息之前并不知道broker的健康状态,如果broker正在繁忙的处理消息,大量的发送请求会增加broker的负担,MQ为了缓解这个问题增加了broker故障机制,利用发送的时长来预测broker的可用时间
默认是关闭的,可以通过这个是打开:
defaultMQProducer.setSendLatencyFaultEnable(true);
先来看看如何预测broker的不用时间的
private SendResult sendDefaultImpl(Message msg, CommunicationMode communicationMode, SendCallback sendCallback, long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { 。。。 try { beginTimestampPrev = System.currentTimeMillis(); sendResult = this.sendKernelImpl(msg, mq, communicationMode, sendCallback, topicPublishInfo, timeout); endTimestamp = System.currentTimeMillis(); this.updateFaultItem(mq.getBrokerName(), endTimestamp - beginTimestampPrev, false); switch(communicationMode) { case ASYNC: return null; case ONEWAY: return null; case SYNC: if (sendResult.getSendStatus() == SendStatus.SEND_OK || !this.defaultMQProducer.isRetryAnotherBrokerWhenNotStoreOK()) { return sendResult; } } } catch (RemotingException var24) { endTimestamp = System.currentTimeMillis(