Results 1 to 5 of 5

Thread: SimpleMessageListenerContainer - onMessage() VS handleMessage()

  1. #1
    Join Date
    Feb 2011
    Posts
    12

    Default SimpleMessageListenerContainer - onMessage() VS handleMessage()

    Hi,

    In consumer application, for listening for asynchronous messages, we can use either onMessage() or handleMessage() method while setting 'SimpleMessageListenerContainer.setMessageListener ()'.

    What is the difference between these two methods and when to use these methods?

  2. #2
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    onMessage() is defined in an interface (MessageListener). handleMessage() is just a naming convention (the default method name in a POJO if you don't specify). It's the same in Spring JMS, which is where the names come from, to make it easy to learn Spring AMQP if you already know JMS.

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

    Default

    Also, if you are using a POJO, you can use any method name you want as long as you provide it via the "defaultListenerMethod" property of the MessageListenerAdapter or the "method" attribute of the <listener> element if using the namespace support.

  4. #4
    Join Date
    Feb 2011
    Posts
    12

    Default

    Mark and Dave, Thanks for your clarifications.

    I have another query on using onMessage(Message msg) method.

    In onMessage() method, how can I find the name of the Queue from which the message was sent?

  5. #5
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    I don't think you can (it's not supported by the protocol). You can find the receivedRoutingKey and receivedExchange in the MessageProperties, but as a consumer you are supposed to know which queue you are listening to.

Posting Permissions

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