Issue
In my Spring Boot application I have to read message from IBM MQ queue and process those messages, but my JmsListener method (method with annotation @JmsListener) not called or triggered and there is no error message in log. Implementation details are herein
Blockquote
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>mq-jms-spring-boot-starter</artifactId>
<version>2.7.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
Blockquote
- Added annotations @EnableJms in the spring boot application class
- Added the server information to the src/main/resources/application.properties file
Blockquote
ibm.mq.queueManager=XXXX
ibm.mq.channel=XXXXXX
ibm.mq.connName=mq-u100-xx.xx.xyz.com(1444)
ibm.mq.user=XXXXX
ibm.mq.password=XXXXX
Blockquote
- Created Listener class
Blockquote
@Component
public class CDBListener {
@JmsListener(destination = "${mq.queue-name}")
public void receive(Message message) throws JMSException {
TextMessage textMessage = (TextMessage) message;
// business logic
}
}
Blockquote
- Added configuration class
Blockquote
@Configuration
public class JmsListenerConfig implements JmsListenerConfigurer {
@Bean
public DefaultMessageHandlerMethodFactory handlerMethodFactory() {
DefaultMessageHandlerMethodFactory factory = new
DefaultMessageHandlerMethodFactory();
factory.setMessageConverter(messageConverter());
return factory;
}
@Bean
public MessageConverter messageConverter() {
return new MappingJackson2MessageConverter();
}
@Override
public void configureJmsListeners(JmsListenerEndpointRegistrar registrar) {
registrar.setMessageHandlerMethodFactory(handlerMethodFactory());
}
}
Blockquote
It seems I missed something and due to that this issue, help me to resolve the issue
Thanks
Solution
Thanks @Chughts for your support, finally we resolved this issue by making two small change in code
- Change the application properties key from mq.queue-name to mq.queueName
- Listener method name from receive(Message message) to receiveMQMsg(Message message)
- Remove class JmsListenerConfig as suggested by @Chughts as not in use.
Not sure exactly what was the issue, it might be application property key name causing the problem or Listener method name.
Answered By - anuragR
Answer Checked By - Marilyn (JavaFixing Volunteer)