Spring boot stream bind queue with multiple routing keys

后端 未结 1 924
粉色の甜心
粉色の甜心 2021-01-16 13:44

I need to bind single queue with multiple routing keys.

I have configuration in application.properties:

spring.cloud.stream.bindings.some-channel1.de         


        
相关标签:
1条回答
  • 2021-01-16 14:04

    You can't do it with stream properties, but you can always add extra bindings with normal Spring AMQP declarations...

    @SpringBootApplication
    @EnableBinding(Sink.class)
    public class So50526298Application {
    
        public static void main(String[] args) {
            SpringApplication.run(So50526298Application.class, args);
        }
    
        @StreamListener(Sink.INPUT)
        public void listen(String in) {
            System.out.println(in);
        }
    
        // extra bindings...
    
        @Bean
        public TopicExchange exch() {
            return new TopicExchange("exch");
        }
    
        @Bean
        public Queue queue() {
            return new Queue("exch.a-queue");
        }
    
        @Bean
        public Binding extraBinding1() {
            return BindingBuilder.bind(queue()).to(exch()).with("event-domain2");
        }
    
    }
    

    There is also a third party "advanced" boot starter that allows you to add declarations in a yaml file. I haven't tried it, but it looks interesting.

    0 讨论(0)
提交回复
热议问题