I'm using Spring JMS and ActiveMQ to send message from one sender to multiple listeners asynchronously. All listeners subscribe to an ActiveMQ Topic so that the message can be delivered to them. I want to know if a particular listener gets the message from the sender. Is there a way to achieve this?
Edit: Added the JMS sender and listener classes
This is my message sender class:
public class CustomerStatusSender {
private JmsTemplate jmsTemplate;
private Topic topic;
public void setJmsTemplate(JmsTemplate jmsTemplate) {
this.jmsTemplate = jmsTemplate;
}
public void setTopic(Topic topic) {
this.topic = topic;
}
public void simpleSend(final String customerStatusMessage) {
jmsTemplate.send(topic, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
TextMessage message = session.createTextMessage("hello from sender.");
message.setStringProperty("content", customerStatusMessage);
return message;
}
});
}
}
And this is one of the message listeners:
public class CustomerStatusListener implements MessageListener {
public void onMessage(Message message) {
if (message instanceof TextMessage) {
try {
System.out.println("Subscriber 1 got you! The message is: "
+ message.getStringProperty("content"));
} catch (JMSException ex) {
throw new RuntimeException(ex);
}
}
}
}
Upon calling simpleSend()
method in the sender class, all listeners subscribed to this topic will get this message asynchronously. But I want to know if this particular CustomerStatusListener
receives the message from the message sender. How to do it asynchronously? I assume that I can't use ReplyTo
in the sender and listener as suggested in one of the answers if I want to do it asynchronously. What do I need to add in the sender and listener classes to get message receipt confirmation from the listener?