apache / rocketmq-client-go

Apache RocketMQ go client
https://rocketmq.apache.org/
Apache License 2.0
1.29k stars 415 forks source link

集群环境下,不同机器获取到同一个topic的消息队列顺序不一致 #1092

Closed gougousha closed 11 months ago

gougousha commented 1 year ago

问题:集群环境下,发现不同机器 func (p *defaultProducer) UpdateTopicPublishInfo函数存储同一个topic的Mqlist顺序不一致 eg: 机器A topic为test的Mqlist是 broke-a, broke-b, broke-a 机器B topic为test的Mqlist是 broke-b, broke-a, broke-c

原因分析: UpdateTopicRouteInfoWithDefault 函数返回的TopicRouteData. OrderTopicConf 字段不一致 。 可能需要查看内部queryTopicRouteInfoFromServer函数同一个topic返回的为啥不一致

解决方案:目前处理方式是在存储mqlist信息前进行排序

sort.Slice(info.MqList, func(i, j int) bool {
        if info.MqList[i].BrokerName != info.MqList[j].BrokerName {
            return strings.Compare(info.MqList[i].BrokerName, info.MqList[j].BrokerName) < 0
        }

        return info.MqList[i].QueueId < info.MqList[j].QueueId
    })
cserwen commented 12 months ago

see #1077