我是Spring Cloud Stream和Rabbitmq的新手。最近,在启动我的微服务之一后出现了异常。声明无法注册对象,因为它已经被注册,我认为这是因为为每个通道分配了组名,请检查异常,

 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


当我在此微服务的每个通道中给同一个组名时,就会发生这种情况。像这样

 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.#'


我可以通过删除组名来删除此异常,但是组名对于获得已知队列名和更好的负载平衡而言将始终是完美的。如果我做错了什么,或者您需要Java代码(它只是每个通道的流侦听器),请告诉我。

谢谢。

最佳答案

您的YAML格式不正确。它应该是...

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.#'




编辑

哦,我懂了;是的,看起来像个虫子;如果多个绑定使用相同的目标和组,则无法注册错误基础结构。请针对spring-cloud-stream打开github问题。我们应该添加另一个属性以允许使用同一组。

解决方法是在每个地方使用不同的组。

09-28 10:24