Results 1 to 8 of 8

Thread: Multiple ConnectionFactory and multiple SimpleMessageListenerContainer best practices

  1. #1
    Join Date
    Jun 2012
    Posts
    11

    Default Multiple ConnectionFactory and multiple SimpleMessageListenerContainer best practices

    Hi,

    I have below queries on Spring AMQP:

    We have one CachingConnectionFactory per virtual host. We are creating CachingConnectionFactory dynamically and are not defined in app context, we are self maintaining them in a map.

    Now CachingConnectionFactory is needed by three components:
    1) AmqpAdmin/RabbitTemplate
    2) SimpleMessageListenerContainer
    3) *MessageSender classes that uses RabbitTemplate and extends RabbitGatewaySupport

    1) How would you like to recommend configuring SimpleMessageListenerContainer and *MessageSender classes? because single *MessageSender class can send messages to any virtual host thus *MessageSender should know which CachingConnectionFactory to use dynamically. We have *MessageSender as singleton.

    2) Similarly, how would you like to recommend configuring SimpleMessageListenerContainer while receiving messages? because SimpleMessageListenerContainer should know about the appropriate CachingConnectionFactory. One SimpleMessageListenerContainer is not gone work here.

    3) What are the areas we need to keep in mind while creating such a design?

    Our initial understanding here is that if we have five CachingConnectionFactory then we need to end up with five SimpleMessageListenerContainer. But the notable thing here is that we dont know how many CachingConnectionFactory to create on app startup. These are lazily created.

    Thanks in advance

  2. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,029

    Default

    1. If you want some form of dynamic sender, then don't subclass RabbitGatewaySupport, use your own support class that supports multiple RabbitTemplates.

    2. You need a separate listener container for each connection factory.

    You could define your factory and listener container in its own config file; use property placeholders for the configurable details; instantiate the context and make the main context the parent context; that enables each child to reference beans in the main context. You can pass in properties for the placeholders using the Spring 3.1 environment support...

    Code:
    ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
    		new String[] { "/META-INF/spring/integration/configurable-listener-context.xml" },
    		false,
    		mainContext);
    
    StandardEnvironment env = new StandardEnvironment();
    Properties props = new Properties();
    props.setProperty("foo", "bar");
    ...
    
    PropertiesPropertySource pps = new PropertiesPropertySource("ftpprops", props);
    env.getPropertySources().addLast(pps);
    ctx.setEnvironment(env);
    ctx.refresh();
    Last edited by Gary Russell; Jul 15th, 2012 at 01:23 PM.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    Jun 2012
    Posts
    11

    Default

    Thanks a lot Gary, Regarding your first point we also think that we should not extend RabbitGatewaySupport, rather create our own support class or achieve the same (multiple rabbit templates) by some other design.

  4. #4

    Default

    Is it possible to have multiple listener-container, each pointing to the same connectionfactory ?

  5. #5
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,029

    Default

    Yes; that is a completely normal situation.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  6. #6

    Default

    If it is ok to have multiple DMLC listener-containers (each referencing the same queueconnectionfactory) then is it also ok if each of those DMLCs contains listeners listening on the same queue ?
    Eg. DMLC-1 contains listener01 with destination jms/queue01 and DMLC-02 contains another listener pointing to the same destination jms/queue01.
    Is that a configuration that will work reliably ? Is it advisable, will a particular message only be consumed once-and-only-once ?

  7. #7
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,029

    Default

    This is the AMQP forum; you appear to be talking about JMS (there is no DMLC in spring-amqp and you use jms in your queue names).

    Regardless (JMS Vs. AMQP), it is a function of the broker to deliver a message to only one consumer. The fact both consumers are using the same connection is irrelevant.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  8. #8

    Default

    Sorry, I posted to the wrong forum, I'll follow this up on the JMS forum.

Posting Permissions

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