What is the difference between a MessageListener and a Consumer in JMS?

前端 未结 3 921
盖世英雄少女心
盖世英雄少女心 2021-01-31 11:51

I am new to JMS. As far as I understood Consumers are capable of picking messages from queue/topic. So why do you need a MessageList

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-31 12:15

    One major difference as per my knowledge not stated in others answers is that MessageConsumer can make use of MessageSelectors and hence has capability to consume messages that it's interested in, where as MessageListener will listen to all messages.

    From the J2EE tutorial doc http://docs.oracle.com/javaee/5/tutorial/doc/bnceh.html

    JMS Message Selectors
    If your messaging application needs to filter the messages it receives, you can use a JMS API message selector, which allows a message consumer to specify the messages it is interested in. Message selectors assign the work of filtering messages to the JMS provider rather than to the application.

提交回复
热议问题