• 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();
            }
        }
    
        //......
    }

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

  • 相关阅读:
    Lavarel之环境配置 .env
    总结:关于留学网站使用laravel框架的总结
    新版 OSGi 即将发布
    Flex 4 的十大变化
    NetBeans IDE 6.8 Milestone 1 已经可用!
    JSF 2 简介,第 2 部分: 模板及复合组件
    JSF 2 简介,第 2 部分: 模板及复合组件
    Flex 4 的十大变化
    JSF 2 简介,第 1 部分: 流线化 Web 应用程序开发
    JSF 2 简介,第 3 部分: 事件处理、JavaScript 和 Ajax
  • 原文地址:https://www.cnblogs.com/onlyzhangmeng/p/16253753.html
Copyright © 2020-2023  润新知