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

  • SimpleMessageListenerContainer


    I am new to messaging system and have queries on SimpleMessageListenerContainer. Actually our team is developing a messaging system using RabbitMQ, but now we want to take benefits of Spring AMQP, so we have decided to do some prototyping.

    Queries (My questions may be irrelevant because I am new to this topic, so please ........ )

    Can I have multiple SimpleMessageListenerContainer's in my application context?

    Can I add more than one "Message-driven POJO" (aka Delegate/Handler/Actual Consumer) in SimpleMessageListenerContainer?

    Can I do something like configuring multiple Consumers with one Queue?


  • #2

    There is no limit to how many listener containers you have in a context; each container has 1 listener; the container can be configured to receive messages from a list of queues (or just one).

    Each container can be configured with more than one consumer - setConcurrentConsumers(); your listener must be stateless, or at least be coded to handle multiple threads if you have more than one consumer.

    I hope that answers your questions.


    • #3
      Thanks a lot Gary, yes I got answers to my questions.


      • #4
        I'm confused about this answer. I can see that programmatically the listener container only allows a single listener to be set on the container but in the app context it supports multiple listeners e.g

            <rabbit:listener-container id="listenerContainer"  connection-factory="connectionFactory"  message-converter="jsonMessageConverter" >
                <rabbit:listener queues="msg.consumer" ref="consumerHandler" method="handleIt" />
                <rabbit:listener queues="msg.square" ref="squareHandler" method="handleSquare" />
        And this does appear to work. Can you explain?


        • #5
          The namespaces is simply a convenience - a shortcut for making configuration easier.

          While it "looks" like this is a single container with multiple listeners, it actually generates a container for each listener, with each container using the same "common" configuration declared at the top element level (connection factory etc).


          • #6
            Ah, quite simple really. Thanks