I am developing a spring boot application which should recieve message from IBM MQ and publish the same message onto a topic in SpringBoot JMS. I am able to recieve the Message in the onMessage()
of MessageListener
but not able to publish the same message onto a topic. Need help regarding this.
This is the MessageListener Class implementation
@Component
public class QueueListener implements MessageListener{
@Autowired
private TopicMessageCreator topicCreator;
@Override
public void onMessage(Message message) {
if (message instanceof TextMessage) {
try {
String json = ((TextMessage) message).getText();
topicCreator.pushMessageToTopic(json);
/*************************************************************/
I have tried calling a service from onMessage()
method of the MessageListener
. In the service I am doing jmsTemplate.send
but I get Error message which says "Execution of JMS message listener failed, and no ErrorHandler has been set"
This is the Class which publishes the message to topic
@Service
public class TopicMessageCreator {
@Autowired
@Qualifier("jmsTopicTemplate")
private JmsTemplate jmsTopicTemplate;
@Autowired
private Servers server;
public void pushMessageToTopic(String jsonString) {
jmsTopicTemplate.send(new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
TextMessage text = session.createTextMessage(jsonString);
session.createTopic(server.getTopic());
return text;
}
});
}