apache / rocketmq

Apache RocketMQ is a cloud native messaging and streaming platform, making it simple to build event-driven applications.
https://rocketmq.apache.org/
Apache License 2.0
21.19k stars 11.67k forks source link

[Bug] AutoBatch bug when connecting multiple RocketMQ clusters. #8806

Closed luozongle01 closed 2 weeks ago

luozongle01 commented 2 weeks ago

Before Creating the Bug Report

Runtime platform environment

macos 11.7.10

RocketMQ version

5.3.0

JDK Version

jdk 1.8

Describe the Bug

If multiple RocketMQ clusters are connected and autoBatch is enabled, messages may be sent to the wrong cluster if multiple clusters happen to have the same theme.

Steps to Reproduce

If I connect to multiple RocketMQ clusters on the same client and enable autoBatch, the topic name happens to be the same.

image

Messages may be sent to the wrong cluster

image

What Did You Expect to See?

The message should be sent to the correct cluster

What Did You See Instead?

When creating a Default MQProducer on the client side, an internal Producer Accumulator is initialized Put the information into the accumulator table map, where key is the client ID and value is the created Producer Accumulator. When initializing, it will first determine whether the Producer Accumulator has been created based on the client ID. But at this time, the user has not had the opportunity to set InstanceName or UnitName. So at this point, the client IDs within the same service are all the same. So currently, multiple Default MQProducers created on the same client internally use the same produceAccumulator. If the topic names of different clusters happen to be the same, it will be sent to the wrong cluster.

Additional Context

No response

humkum commented 2 weeks ago

You should set different instanceName for different producers in this situation.

luozongle01 commented 2 weeks ago

在这种情况下,您应该为不同的生产者设置不同的instanceName。

设置不同的instanceName也不行,因为创建DefaultMQProducer的时候直接把ProduceAccumulator也给创建了,这时候还没执行到设置unitName或者instanceName的代码。😂😂😂