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

前端 未结 3 927
盖世英雄少女心
盖世英雄少女心 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:29

    The difference is that MessageConsumer is used to receive messages synchronously:

    MessageConsumer mc = s.createConsumer(queue);
    Message msg = mc.receive();
    

    For asynchronous delivery, we can register a MessageListener object with a message consumer:

    mc.setMessageListener(new MessageListener() {
        public void onMessage(Message msg) {
            ...
        }
    });
    

提交回复
热议问题