Exception thrown while starting consumer - (Cannot assign same group name for different channels in a microservice )

老子叫甜甜 提交于 2021-01-28 07:52:22

问题


I am a newbie in Spring cloud stream and rabbitmq. Recently I got an Exception after started one of my microservice. It is stating that could not register object because it is already registered, I think it is is because of the group name that assigned for each channel, please check the exception,

 2018-05-28 10:01:38.420 ERROR 10244 --- [ask-scheduler-2] o.s.cloud.stream.binding.BindingService  : Failed to create consumer binding; retrying in 30 seconds
 org.springframework.cloud.stream.binder.BinderException: Exception thrown while starting consumer: 
     at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.doBindConsumer(AbstractMessageChannelBinder.java:326) ~[spring-cloud-stream-2.0.0.RC3.jar:2.0.0.RC3]
     at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.doBindConsumer(AbstractMessageChannelBinder.java:77) ~[spring-cloud-stream-2.0.0.RC3.jar:2.0.0.RC3]
     at org.springframework.cloud.stream.binder.AbstractBinder.bindConsumer(AbstractBinder.java:129) ~[spring-cloud-stream-2.0.0.RC3.jar:2.0.0.RC3]
     at org.springframework.cloud.stream.binding.BindingService.lambda$rescheduleConsumerBinding$0(BindingService.java:154) ~[spring-cloud-stream-2.0.0.RC3.jar:2.0.0.RC3]
     at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[na:1.8.0_101]
     at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_101]
     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) ~[na:1.8.0_101]
     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) ~[na:1.8.0_101]
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_101]
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_101]
     at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_101]
 Caused by: java.lang.IllegalStateException: Could not register object [org.springframework.integration.handler.advice.ErrorMessageSendingRecoverer@70a0362b] under bean name 'org.nets.ups.alertService.errors.recoverer': there is already object [org.springframework.integration.handler.advice.ErrorMessageSendingRecoverer@cfd5cd2] bound
     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.registerSingleton(DefaultSingletonBeanRegistry.java:126) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
     at org.springframework.beans.factory.support.DefaultListableBeanFactory.registerSingleton(DefaultListableBeanFactory.java:932) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
     at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.registerErrorInfrastructure(AbstractMessageChannelBinder.java:519) ~[spring-cloud-stream-2.0.0.RC3.jar:2.0.0.RC3]
     at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.registerErrorInfrastructure(AbstractMessageChannelBinder.java:478) ~[spring-cloud-stream-2.0.0.RC3.jar:2.0.0.RC3]
     at org.springframework.cloud.stream.binder.rabbit.RabbitMessageChannelBinder.createConsumerEndpoint(RabbitMessageChannelBinder.java:391) ~[spring-cloud-stream-binder-rabbit-2.0.0.RC3.jar:2.0.0.RC3]
     at org.springframework.cloud.stream.binder.rabbit.RabbitMessageChannelBinder.createConsumerEndpoint(RabbitMessageChannelBinder.java:104) ~[spring-cloud-stream-binder-rabbit-2.0.0.RC3.jar:2.0.0.RC3]
     at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.doBindConsumer(AbstractMessageChannelBinder.java:279) ~[spring-cloud-stream-2.0.0.RC3.jar:2.0.0.RC3]
     ... 11 common frames omitted

It is happening when I gave same group name fro each channels in this microservice. something like this,

 spring:
   cloud:
     stream:
       bindings:
         useroperation:
           destination: org.nets.ups
           content-type: application/json
           group: alertService
         departmentoperation:
           destination: org.nets.ups
           content-type: application/json
           group: alertService
         roleoperation:
           destination: org.nets.ups
           content-type: application/json
           group: alertService
         rabbit:
           bindings:
             useroperation:
               consumer:
                 bindingRoutingKey: 'adminservice.user.#'
             departmentoperation:
                consumer:
                  bindingRoutingKey: 'adminservice.department.#'
             roleoperation:
               consumer:
                 bindingRoutingKey: 'adminservice.role.#'

I can remove this exception by removing the group name, But a group name will be always perfect to get a known queue name and better load balance. If I did something wrong or if you need java code (it is just a stream listener for each channel that is it) please let me know.

Thank you.


回答1:


Your YAML is not well formed. It should be...

spring:
  cloud:
    stream:
      bindings:
        useroperation:
          destination: org.nets.ups
          content-type: application/json
          group: alertService
        departmentoperation:
          destination: org.nets.ups
          content-type: application/json
          group: alertService
        roleoperation:
          destination: org.nets.ups
          content-type: application/json
          group: alertService
      rabbit:
        bindings:
          useroperation:
            consumer:
              bindingRoutingKey: 'adminservice.user.#'
          departmentoperation:
            consumer:
              bindingRoutingKey: 'adminservice.department.#'
          roleoperation:
           consumer:
             bindingRoutingKey: 'adminservice.role.#'

EDIT

Oh, I see; yes, looks like a bug; we can't register the error infrastructure if multiple bindings use the same destination and group. Please open a github issue against spring-cloud-stream. We should add another property to allow the use of the same group.

The work around would be to use a different group in each place.



来源:https://stackoverflow.com/questions/50559187/exception-thrown-while-starting-consumer-cannot-assign-same-group-name-for-di

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!