绑定交换以通过Spring云流与Rabbitmq绑定器进行交换

时间:2019-04-10 16:05:14

标签: rabbitmq spring-amqp spring-cloud-stream spring-rabbitmq spring-rabbit

我正在寻找一种通过Spring云流将RabbitMQ交换绑定到另一个交换的方法。我知道我可以通过设置producer.requiredGroups属性来将队列绑定到交换:

spring.cloud.stream.bindings.foo.producer.requiredGroups=queueA queueB

我可以使用哪个属性来创建交换到交换绑定?

1 个答案:

答案 0 :(得分:1)

不是添加必需的组,而是为两个交换添加@Bean,并为绑定添加@Bean

请参见Spring AMQP documentation

@Bean
public TopicExchange destinatioExchange() {
    return new TopicExchange("myDest");
}

@Bean
public DirectExchange boundExchange() {
    return new DirectExchange("bound");
}

@Bean
public Binding binding() {
    return BindingBuilder
            .bind(boundExchange())
            .to(destinatioExchange())
            .with("myRoutingKey");
}

spring.cloud.stream.bindings.output.destination=myDest
spring.cloud.stream.rabbit.bindings.output.producer.routing-key-expression='myRoutingKey'