zoukankan      html  css  js  c++  java
  • RocketMQ分析

    1.可以通过 producer.setRetryTimesWhenSendFailed(count) 来设置生产者发送消息时候失败重试的次数,默认值是2,即失败一次后,会重试两次,总共发送三次消息

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

    2.生产者发送消息重试机制

    贴上源码,客户端版本号是: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
    
  • 相关阅读:
    HTML5 实现Link跳线效果
    在TWaver的Tree节点上画线
    用TWaver加载大型游戏场景一例
    22万个木箱!TWaver 3D极限压榨
    如何在MONO 3D寻找最短路路径
    如何创建TWaver 3D的轮廓选中效果
    巧用TWaver 3D 矢量图形功能
    如何实现TWaver 3D颜色渐变
    HDU 1390 Binary Numbers
    HDU 1328 IBM Minus One
  • 原文地址:https://www.cnblogs.com/HeCG95/p/11761154.html
Copyright © 2011-2022 走看看