Announcement Announcement Module
No announcement yet.
Multiple Bindings and Dynamic Bindings Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiple Bindings and Dynamic Bindings


    I have a requirement to bind my queues to exchanges with multiple routing keys. Currently I have defined binding as spring bean, like :
    public Binding testBinding() {
    		return BindingBuilder.bind(testQueue()).to(testExchange()).with("testRoutingKey1");

    Question 1: How can I bind my exchange and queue with multiple routing keys? Like I want to add testRoutingKey2, testRoutingKey3 and testRoutingKey4

    Question 2: How can I create bindings dynamically? For example I have 4 routing keys that binds my exchange and queue, and now I want to add 2 more routing keys between this exchange and queue dynamically.

    If I am not wrong it can be achieved by AmqpAdmin/RabbitAdmin but I am not sure how to do it, any example?

    I saw the logic of initialize() method of RabbitAdmin class and found that it looks for AMQP entities (Exchanges, Queues and Bindings) in ApplicationContext and then creates them on broker. This initialize() method gets called every time a connection is created. It makes me think that my bindings (dynamically created bindings) should be present in ApplicationContext for the logic under initialize() to create them on broker.


  • #2

    Any thoughts, I need solution.



    • #3
      Regarding Question 1: you can use the BindingBuilder to create as many routingKey-based bindings as necessary for the same Exchange/Queue.

      Regarding Question 2: yes, you can use the RabbitAdmin instance's declareBinding(..) method and pass it a result of using BindingBuilder exactly as you have within your @Bean methods in the config code.

      Hope that helps.