alibaba / spring-cloud-alibaba

Spring Cloud Alibaba provides a one-stop solution for application development for the distributed solutions of Alibaba middleware.
https://sca.aliyun.com
Apache License 2.0
28k stars 8.34k forks source link

Hot deployment stream-rocketmq MQClientException: The producer group[mygroup] has been created before #2390

Open frlzk opened 2 years ago

frlzk commented 2 years ago

Which Component spring-cloud-starter-stream-rocketmq

Describe the bug When hot deployment in eclipse throw MQClientException: The producer group[mygroup] has been created before

To Reproduce Steps to reproduce the behavior:

  1. Spring boot application with devtools in Eclipse
  2. Send message using org.springframework.cloud.stream.function.StreamBridge.send
  3. Modify any code trigger spring devtools hot deployment
  4. When send message using org.springframework.cloud.stream.function.StreamBridge.send,Then throw exception

Expected behavior Not throw exception and send message successfully.

Screenshots

streamBridge.send("mytopic-out-0","hello");
org.apache.rocketmq.client.exception.MQClientException: The producer group[mygroup] has been created before, specify another name please.
See http://rocketmq.apache.org/docs/faq/ for further details.
    at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.start(DefaultMQProducerImpl.java:195)
    at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.start(DefaultMQProducerImpl.java:175)
    at org.apache.rocketmq.client.producer.DefaultMQProducer.start(DefaultMQProducer.java:271)
    at com.alibaba.cloud.stream.binder.rocketmq.integration.outbound.RocketMQProducerMessageHandler.start(RocketMQProducerMessageHandler.java:112)
    at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.doBindProducer(AbstractMessageChannelBinder.java:248)
    at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.doBindProducer(AbstractMessageChannelBinder.java:91)
    at org.springframework.cloud.stream.binder.AbstractBinder.bindProducer(AbstractBinder.java:152)
    at org.springframework.cloud.stream.binding.BindingService.doBindProducer(BindingService.java:313)
    at org.springframework.cloud.stream.binding.BindingService.bindProducer(BindingService.java:282)
    at org.springframework.cloud.stream.function.StreamBridge.resolveDestination(StreamBridge.java:200)
    at org.springframework.cloud.stream.function.StreamBridge.send(StreamBridge.java:152)
    at org.springframework.cloud.stream.function.StreamBridge.send(StreamBridge.java:130)

Additional context Linux 、Java8 、spring-cloud-starter-stream-rocketmq:2.2.7.RELEASE 、spring-cloud-stream:3.1.2

Reason Not call MQClientInstance.unregisterProducer when stop application.

sollhui commented 2 years ago

Please assign to me

sollhui commented 1 year ago

@zkzlx I am sorry I have no time to finish it now, I give up it.

jiajun commented 1 year ago

@zkzlx , @HHoflittlefish777 , @steverao,

I have this issue reproduced in spring-cloud-starter-stream-rocketmq:2.2.7.RELEASE and 2.2.9.Release. This issue is due to below piece of code in com.alibaba.cloud.stream.binder.rocketmq.integration.outbound.RocketMQProduceFactory.initRocketMQProducer():

        if (RocketMQProducerProperties.ProducerType.Trans
                .equalsName(producerProperties.getProducerType())) {
                        ......
                }
        else {
            producer = new DefaultMQProducer(producerProperties.getNamespace(),
                    producerProperties.getGroup(), rpcHook,
                    producerProperties.getEnableMsgTrace(),
                    producerProperties.getCustomizedTraceTopic());
        }

In initRocketMQProducer(), the RocketMQ Producer be created by newing a DefaultMQProducer. When some code change cause StreamBridge.send() rerun, the DefaultMQProducer will be new again, which has already been created. So, the Exception raised inside of DefaultMQProducer().

In the current code branch 2.2.x which version now is 2.2.10-RC1, I found this commit https://github.com/alibaba/spring-cloud-alibaba/commit/5e80d7c2c4e048f9eda6a624dadaf5c15c8c6e76 which already replaced the issue code by new ReusableMQProducer(...). The ReusableMQProducer() avoids the RocketMQ Producer be created twice. Finally, I tested it with devtools and the Exception does not occur.

So, I believe this issue has been fixed in 2.2.10-RC1.

Thanks.

JiaJun