简体   繁体   中英

Spring JMS Producer and Consumer interaction

如何确定使用者是否已经从生产者那里收到消息,或者如何通知生产者该消息已经在Spring JMS中发送/使用了?

you need to use request/reply by using org.springframework.jms.core.JmsTemplate.sendAndReceive(...) on the producer side and on the consumer side the MessageListener method set in the container must return a value.

or make your producer subscribing to ActiveMQ.Advisory.MessageConsumed.Queue to be notified when the message is consumed by having access to some properties like orignalMessageId , take a look here http://activemq.apache.org/advisory-message.html

you can use it like this :

            Destination advisoryDestination = org.apache.activemq.advisory.AdvisorySupport
                    .getMessageConsumedAdvisoryTopic(session.createQueue("yourQueue"));
            MessageConsumer consumer = session.createConsumer(advisoryDestination);
            consumer.setMessageListener(new MessageListener() {
                @Override
                public void onMessage(Message msg) {
                    System.out.println(msg);
                    System.out.println(((ActiveMQMessage) msg).getMessageId());
                    ActiveMQMessage aMsg = (ActiveMQMessage) ((ActiveMQMessage) msg).getDataStructure();
                    System.out.println(aMsg.getMessageId());
                }
            });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM