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?
Asked
Active
Viewed 539 times
0
-
If you just want to notify then you can use AUTO_ACK mode but if you need redelivery in case of exception then you should use transacted="true". This has already been asked at SO. Check this: http://stackoverflow.com/questions/9095471/getting-a-simple-spring-jms-client-acknowledge-to-work – Tarun Feb 23 '17 at 12:36
1 Answers
0
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());
}
});

Hassen Bennour
- 3,885
- 2
- 12
- 20