使用指定 binder

在一些场景中,我们会配置多个消息实现,比如同时集成 rocketmq、rabbitmq 或者多个 rabbitmq 实例,在使用时候我们期望使用指定的消息队列实例,就需要指定 binder

yml 配置文件

spring:
  # Rabbitmq 配置
  rabbitmq:
    host: 192.168.31.100
    port: 5672
    username: admin
    password: admin
    virtual-host: /
    publisher-confirm-type: simple
    #启动消息失败返回,比如路由不到队列时触发回调
    publisher-returns: true
    listener:
      simple:
        #NONE:自动确认;AUTO:根据情况确认;MANUAL:手动确认
        acknowledge-mode: auto
      direct:
        #NONE:自动确认;AUTO:根据情况确认;MANUAL:手动确认
        acknowledge-mode: auto
  cloud:
    stream:
      bindings:
        sms-output:
          # 指定要使用的 Exchange 名称
          destination: ramq.sms.output
          #设置消息类型
          content-type: application/json
          #要绑定的消息服务的实例名
          binder: rabbit1
          producer:
            #分区关键字 对象中的id,对象
            partition-key-expression: payload
            #分区大小
            partition-count: 2
      binders:
        rabbit1:
          type: rabbit
          environment:
            spring:
              rabbitmq:
                host: 192.168.31.100
                port: 5672
                username: admin
                password: admin
                virtual-host: /
                publisher-confirm-type: simple
                #启动消息失败返回,比如路由不到队列时触发回调
                publisher-returns: true
                listener:
                  simple:
                    #NONE:自动确认;AUTO:根据情况确认;MANUAL:手动确认
                    acknowledge-mode: auto
                  direct:
                    #NONE:自动确认;AUTO:根据情况确认;MANUAL:手动确认
                    acknowledge-mode: auto
作者:Jeebiz  创建时间:2023-04-04 09:44
最后编辑:Jeebiz  更新时间:2024-09-23 10:03