Spring JMS Producer and Consumer interaction

余生长醉 提交于 2019-12-12 03:55:55

问题


How can i determine if the consumer already received the message from the producer or how can i notify the producer that the message have already been sent/consumed in Spring JMS?


回答1:


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());
                }
            });


来源:https://stackoverflow.com/questions/42415468/spring-jms-producer-and-consumer-interaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!