Results 1 to 3 of 3

Thread: Multiple Bindings and Dynamic Bindings

Hybrid View

  1. #1
    Join Date
    Jun 2012
    Posts
    11

    Default Multiple Bindings and Dynamic Bindings

    Hi,

    I have a requirement to bind my queues to exchanges with multiple routing keys. Currently I have defined binding as spring bean, like :
    Code:
    @Bean
    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.

    Thanks

  2. #2
    Join Date
    Jun 2012
    Posts
    11

    Default

    Hi,

    Any thoughts, I need solution.

    Thanks

  3. #3
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    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.
    -Mark

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •