• RocketMQ中MessageExt属性


    https://blog.csdn.net/shi_hong_fei_hei/article/details/115585793?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0.topblog&spm=1001.2101.3001.4242.1&utm_relevant_index=3

    https://blog.csdn.net/Nicholas___/article/details/108689772

    这两篇比较全了。

    还有一点是setMaxReconsumeTimes  这个参数

    //在默认的消费者里 消费重试次数 -1代表16次,不是无限次数
    defaultMQPushConsumer.setMaxReconsumeTimes(-1);
    public class DefaultMQPushConsumerImpl implements MQConsumerInner {
    
        //......
    
        public void sendMessageBack(MessageExt msg, int delayLevel, final String brokerName)
            throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
            try {
                String brokerAddr = (null != brokerName) ? this.mQClientFactory.findBrokerAddressInPublish(brokerName)
                    : RemotingHelper.parseSocketAddressAddr(msg.getStoreHost());
                this.mQClientFactory.getMQClientAPIImpl().consumerSendMessageBack(brokerAddr, msg,
                    this.defaultMQPushConsumer.getConsumerGroup(), delayLevel, 5000, getMaxReconsumeTimes());
            } catch (Exception e) {
                log.error("sendMessageBack Exception, " + this.defaultMQPushConsumer.getConsumerGroup(), e);
    
                Message newMsg = new Message(MixAll.getRetryTopic(this.defaultMQPushConsumer.getConsumerGroup()), msg.getBody());
    
                String originMsgId = MessageAccessor.getOriginMessageId(msg);
                MessageAccessor.setOriginMessageId(newMsg, UtilAll.isBlank(originMsgId) ? msg.getMsgId() : originMsgId);
    
                newMsg.setFlag(msg.getFlag());
                MessageAccessor.setProperties(newMsg, msg.getProperties());
                MessageAccessor.putProperty(newMsg, MessageConst.PROPERTY_RETRY_TOPIC, msg.getTopic());
                MessageAccessor.setReconsumeTime(newMsg, String.valueOf(msg.getReconsumeTimes() + 1));
                MessageAccessor.setMaxReconsumeTimes(newMsg, String.valueOf(getMaxReconsumeTimes()));
                newMsg.setDelayTimeLevel(3 + msg.getReconsumeTimes());
    
                this.mQClientFactory.getDefaultMQProducer().send(newMsg);
            } finally {
                msg.setTopic(NamespaceUtil.withoutNamespace(msg.getTopic(), this.defaultMQPushConsumer.getNamespace()));
            }
        }
    
        private int getMaxReconsumeTimes() {
            // default reconsume times: 16
            if (this.defaultMQPushConsumer.getMaxReconsumeTimes() == -1) {
                return 16;
            } else {
                return this.defaultMQPushConsumer.getMaxReconsumeTimes();
            }
        }
    
        //......
    }

    默认消费者是无序消息 ,没有消费顺序的。

  • 相关阅读:
    Highcharts之饼图
    设计模式学习之原型模式
    jQuery学习之结构解析
    JS学习之闭包的理解
    JS学习之prototype属性
    JS学习之事件冒泡
    Mybatis学习之JDBC缺陷
    Spring学习之Aop的基本概念
    Struts学习之值栈的理解
    Struts学习之自定义结果集
  • 原文地址:https://www.cnblogs.com/onlyzhangmeng/p/16253753.html
Copyright © 2020-2023  润新知