You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2021/08/28 07:27:18 UTC

[GitHub] [rocketmq] ZJRui commented on issue #3297: 为什么rocketMQ默认情况下没有将一个JVM内的所有的生产者和消费者都放置在同一个MQClientInstance下?

ZJRui commented on issue #3297:
URL: https://github.com/apache/rocketmq/issues/3297#issuecomment-907586957


   > First of all, it is recommended to use the version later than 4.7.
   > In version 4.7 and above, the clientId generation rules of consumer and producer are the same, which can ensure that the same MQClientInstance is used by default in the same process.
   
   我看了下4.8.0的代码 ,好像并不是像你说的这样。
   4.8.0的代码中 对于DefaultMQPullConsumerImpl的start方法中  会判断MessageModel如果为集群模式,则将instanceName改为Pid
   `   if (this.defaultMQPullConsumer.getMessageModel() == MessageModel.CLUSTERING) {
                       this.defaultMQPullConsumer.changeInstanceNameToPID();
                   }
   
   `
   但是在DefaultMQProducerImpl的start方法中 ,只有当ProducerGroup为指定的group时才会将instanceName改为pid
   `    if (!this.defaultMQProducer.getProducerGroup().equals(MixAll.CLIENT_INNER_PRODUCER_GROUP)) {
                       this.defaultMQProducer.changeInstanceNameToPID();
                   }`
   
   也就是说这样会导致 Consumer和Producer的InstanceName 不同,从而构建的clientId不同,最终导致创建两个MQClientInstance对象。
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org