JmsListener method not triggered IBM MQ with Spring Boot

Viewed 182

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

  1. I have add these dependencies in pom.xml

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

  1. Added annotations @EnableJms in the spring boot application class
  2. 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

  1. 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

  1. 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

2 Answers

It's odd that you are not seeing any error messages, it suggests that nothing is getting through. Have you checked the error logs on your MQ Server on localhost? I am guessing that you are running a container, so based on the cheat sheet at - https://developer.ibm.com/articles/mq-dev-cheat-sheet/

docker exec -ti <container_id> /bin/bash

and

cd /var/mqm/qmgrs/<your_queue_manager_name>/errors/

Some observations on your setup.

You have

<version>2.0.9</version>

which is quite dated, current latest is 2.7.2

You are listening for a JMS Message then casting it into a TextMessage.

@JmsListener(destination = "CDB_Queue")
public void receive(Message message) throws JMSException {
    TextMessage textMessage = (TextMessage) message;
              
    // business logic 
}

This is unsafe, you should check that the cast is possible before casting.

@JmsListener(destination = "CDB_Queue")
public void receive(Message message) throws JMSException {
   if (message instanceof TextMessage) {
       TextMessage textMessage = (TextMessage) message;
              
       // business logic 
   }
}

Your JmsListenerConfig doesn't do anything beyond the default, so it isn't actually needed. You can safely remove it.

You can switch on trace on the client side. See https://github.com/ibm-messaging/mq-jms-spring#logging--tracing

You can enable tracing of this specific component in your application's properties file by setting logging.level.com.ibm.mq.spring.boot=TRACE. Otherwise it uses the standard inheritance of logging configuration from logging.level.rootdownwards.

Thanks @Chughts for your support, finally we resolved this issue by making two small change in code

  1. Change the application properties key from mq.queue-name to mq.queueName
  2. Listener method name from receive(Message message) to receiveMQMsg(Message message)
  3. 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.

Related