Paddy
Paddy

Reputation: 1

Getting MQJCA1025 Error while starting MQ Listener

Getting MQJCA1025 error while starting up the Asynchronous Listener/reader on IBM-MQ as -

com.ibm.msg.client.jms.DetailedIllegalStateException: MQJCA1025: The message consumer must not have a message listener. An application attempted to set a message listener for a JMS message consumer. This exception occurs only if the application is running in a managed environment. Modify the application so that it does use a message listener.

Below is the init method where listener setup is done -

  public void init(){
              ConnectionFactory qConnectionFactory = null;
              Connection connection = null;
              try{
                     Context ctx = new InitialContext();
                     qConnectionFactory = (ConnectionFactory) ctx.lookup("java:jboss/Connection");
                     Destination receiverQueue = null;
                     if(null != qConnectionFactory){
                           connection = qConnectionFactory.createConnection();
                           if(null !=connection){
                                  receiverQueue = (Destination) ctx.lookup("java:jboss/RESPONSE");
                                  if(null != receiverQueue){
                                         Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
                                         if(null != session){            
                                                MessageConsumer consumer = session.createConsumer(receiverQueue);
                                                consumer.setMessageListener(this);
                                                connection.start();
                                         }
                                  }
                           }
                     }
              }
              catch(Exception e){
                    System.out.println(e);
              }
       }

IBM resolution at http://www-01.ibm.com/support/docview.wss?uid=swg21610734 doesn't mentions the fix to be made at listener/client side

Upvotes: 0

Views: 368

Answers (2)

Axel Podehl
Axel Podehl

Reputation: 4323

In other words, your Application Server does the hookup for you :-) Your fix would be to NOT set the listener yourself, but instead make sure you implement a MessageDrivenBean and the application server will do the registration for you. You only need to implement onMessage(). See here for an example with JBoss.

Upvotes: 0

Roger
Roger

Reputation: 7506

MQJCA1025 error message says don't do the following:

consumer.setMessageListener(this);

The link you give is very clear:

Cause

Calling setMessageListener() method in a managed environment is a violation of J2EE specification, and therefore should not be used.

Resolving the problem

Your JMS application needs to be altered to not call setMessageListener() method. Instead, Activation Specifications are provided for the functionality which this method provides

Upvotes: 1

Related Questions