首页 > 解决方案 > 如何在带有 Kotlin 的 Spring RabbitMQ 中使用多个消费者绑定

问题描述

这是一个 Kotlin REST API 项目。这是 application.yml

 cloud:
    stream:
      bindings:
        eventStateOne-in-0:
          destination: eventStateOne-events
          binder: rabbit_mq
          group: eventStateOne_sub
          
        eventStateOneConsumer-out-0:
          destination: eventOne-events
          binder: rabbit_mq
          group: eventOneConsumer
          
        eventStateTwo-in-0:
          destination: eventStateTwo-events
          binder: rabbit_mq
          group: eventStateTwo_sub
          
        eventStateTwoConsumer-out-0:
          destination: eventTwo-events
          binder: rabbit_mq
          group: eventTwoConsumer
          
      binders:
        rabbit_mq:
          type: rabbit
          environment:
            spring:
              rabbitmq:
                host: <host>
                port: <port>
                username: <name>
                password: <pass>
                

在代码中,我有 2 个 bean

@Bean
fun eventStateOneConsumer(): Consumer<EventState>


@Bean
fun eventStateTwoConsumer(): Consumer<EventState>

每个 bean 都应该处理 eventStateOne-in-0 和 eventStateTwo-in-0 队列中的消息。当我启动应用程序时,它显示错误

Can't determine default function definition. Please use 'spring.cloud.function.definition' property to explicitly define it.

我知道有 2 个相同类型的 bean,应用程序不知道应该使用哪种类型,但我不知道如何解决这个问题。请帮我解决这个问题

标签: springkotlinconfigurationrabbitmqjavabeans

解决方案


推荐阅读