Spring Cloud Streaming - 生产者和消费者的独立连接

Spring Cloud Streaming - Separate Connection for Producer & Consumer

我有一个使用 RabbitMQ 的 Spring 云流转换器应用程序。它从 Rabbit 队列中读取数据,进行一些转换,然后写入 Rabbit 交换器。我已将我的应用程序部署到 PCF 并绑定到 Rabbit 服务。

这工作正常,但现在我需要一个单独的连接来使用和生成消息。 (我想使用一个连接从 Rabbit 队列中读取,并使用不同的连接写入 Rabbit 交换器)。我将如何配置这个?是否可以使用 1 作为生产者和 1 作为消费者将我的应用程序绑定到 2 个不同的 Rabbit 服务?

嗯,从版本 1.3 开始,Rabbit Binder 确实为生产者创建了一个单独的 ConnectionFactoryhttps://docs.spring.io/spring-cloud-stream/docs/Ditmars.RELEASE/reference/htmlsingle/#_rabbitmq_binder

Starting with version 1.3, the RabbitMessageChannelBinder creates an internal ConnectionFactory copy for the non-transactional producers to avoid dead locks on consumers when shared, cached connections are blocked because of Memory Alarm on Broker.

所以,升级到 Spring Cloud Stream Ditmars 后,这对您来说可能已经足够了。

更新

How would I go about configuring this internal ConnectionFactory copy with different connection properties?

不,那是另一回事。你需要的叫multi-binder支持:https://docs.spring.io/spring-cloud-stream/docs/Ditmars.RELEASE/reference/htmlsingle/#multiple-binders

您应该为不同的连接工厂声明几个块:

spring.cloud.stream.bindings.input.binder=rabbit1
spring.cloud.stream.bindings.output.binder=rabbit2

...

spring:
  cloud:
    stream:
      bindings:
        input:
          destination: foo
          binder: rabbit1
        output:
          destination: bar
          binder: rabbit2
      binders:
        rabbit1:
          type: rabbit
          environment:
            spring:
              rabbitmq:
                host: <host1>
        rabbit2:
          type: rabbit
          environment:
            spring:
              rabbitmq:
                host: <host2>