Announcement Announcement Module
Collapse
No announcement yet.
Can you use more than one connection factory at a time? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can you use more than one connection factory at a time?

    Hi

    Is it possible to create 2 (or more) connection factories then when creating queues, and exchanges, specify which connection factory to use?
    I can see <rabbit:listener-connection> and <rabbit:template> have a connection factory attribute but I can't see anything similar for <rabbit:queue> and <rabbit:exchange>.

    This is for a system which 'straddles' two different application environments each of which have their own RabbitMQ brokers. We can't run both environments on the same broker as there will be name clashing and messages going to the wrong system.

    David/

  • #2
    Currently, no, not in the same application context; the RabbitAdmin auto-declares all the queues/exchanges it finds in the context; so it's the connection factory that's wired into the RabbitAdmin that is used.

    Please feel free to open an 'Improvement' issue; https://jira.springsource.org/browse/AMQP

    You may be able to work around the issue by simply not defining a <rabbit:admin/> in the main context, and do the declarations in smaller contexts that just live long enough to do the declarations. This will only work for durable queues and exchanges though.

    Something like:

    Code:
    main-context.xml
    
    <import "classpath:env1-context.xml" /> 
    <import "classpath:env2-context.xml" />
    
    ...
    
    env1-context.xml
    
    <!-- queues and exchanges -->
    <!-- connection factory -->
    
    env2-context.xml
    
    <!-- queues and exchanges -->
    <!-- connection factory -->
    
    
    bootstrap1-context.xml
    
    <import "classpath:env1-context.xml" /> 
    
    <rabbit:admin .../>
    
    
    bootstrap2-context.xml
    
    <import "classpath:env2-context.xml" /> 
    
    <rabbit:admin .../>

    Just be sure to fire up (and close) the two bootstrap contexts before the main context starts, so all the queues/exhanges are in place.

    Actually, you really don't need to run them every time you start the main context; just run them as an admin process when the queues etc change.

    Comment


    • #3
      Thanks for the suggestion but it won't work for us as we need to use non-durable queues.

      I have raised AMQP-286 for this

      In the meantime I am changing our system to set up the exchanges and queues in code using @Configuration and @Bean annotations.This will enable us to choose which connectionFactory to use when creating them.

      Comment


      • #4
        Hi

        Just an update on this issue. Even though I was using @Configuration and @Bean annotations the RabbitAdmin class was still attempting to auto-declare all exchanges, queue,s and bindings in the the application context.
        I got round this by sub-classing
        Code:
        org.springframework.amqp.rabbit.core.RabbitAdmin
        and overriding the
        Code:
        intialize()
        method to skip the auto-declaring of the entities.

        I'd be interested if you think there is better solution to this.

        David/

        Comment

        Working...
        X