ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » TIBCO JAVA Application and 2016

Post new topic  Reply to topic
 TIBCO JAVA Application and 2016 « View previous topic :: View next topic » 
Author Message
w1ndy
PostPosted: Thu May 06, 2021 7:41 am    Post subject: TIBCO JAVA Application and 2016 Reply with quote

Apprentice

Joined: 19 Jan 2011
Posts: 38

Hi all. Fingers crossed someone has seen this before coz I haven't

Messages are being processed by TIBCO JAVA application.

Queue get inhibited

Application gets the 2016

Queue get enabled

Connection re-established however no more messages are processed and merely queue until the application is restarted.

Any pointers or help gratefully received.

kind regards

Andrew
Back to top
View user's profile Send private message Send e-mail
RogerLacroix
PostPosted: Thu May 06, 2021 10:21 am    Post subject: Re: TIBCO JAVA Application and 2016 Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3252
Location: London, ON Canada

It sounds like the application was never tested for this type of situation/issue.

When the application issues an MQGET (i.e. get method call), MQ will throw an exception but the application is either not catching it correctly (percolate too high in the code) or it is treating it as a fatal error.

In Java/MQ applications, it is all about how you code your try/catch. In a lot of Java/MQ I have seen, the programmer has 1 try/catch for all MQ calls which is a really bad design.

w1ndy wrote:
Connection re-established however no more messages are processed and merely queue until the application is restarted.

Just because MQ throw the exception of 2016 (MQRC_GET_INHIBITED) does NOT mean that (1) the queue was closed nor (2) the connection was disconnected. Unless, of course, the application explicitly did it.

Here is a Java/MQ application that is structured correctly with try/catch and I added checking for MQ throwing MQRC_GET_INHIBITED. If it does then the program will sleep for 1 minute and then continue on.

If you don't want to copy and paste the code, you can download it from here.

Code:
import java.io.EOFException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Hashtable;

import com.ibm.mq.MQException;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQGetMessageOptions;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;
import com.ibm.mq.constants.CMQC;

/**
 * Program Name
 *  MQTest12L
 *
 * Description
 *  This java class will connect to a remote queue manager with the
 *  MQ setting stored in a HashTable, loop to retrieve all messages from a queue
 *  then close and disconnect.
 *
 * Sample Command Line Parameters
 * bindings mode
 *  -m MQA1 -q TEST.Q1
 * client mode
 *  -m MQA1 -q TEST.Q1 -h 127.0.0.1 -p 1414 -c TEST.CHL -u UserID -x Password
 *
 * @author Roger Lacroix
 */
public class MQTest12L
{
   private static final SimpleDateFormat  LOGGER_TIMESTAMP = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");

   private Hashtable<String,String> params;
   private Hashtable<String,Object> mqht;

   /**
    * The constructor
    */
   public MQTest12L()
   {
      super();
      params = new Hashtable<String,String>();
      mqht = new Hashtable<String,Object>();
   }

   /**
    * Make sure the required parameters are present.
    * @return true/false
    */
   private boolean allParamsPresent()
   {
      boolean b = params.containsKey("-m") && params.containsKey("-q");

      if (params.containsKey("-c"))
      {
         b = b && params.containsKey("-c") && params.containsKey("-h") && params.containsKey("-p");
      }

      if (b)
      {
         try
         {
            if (params.containsKey("-p"))
               Integer.parseInt((String) params.get("-p"));
         }
         catch (NumberFormatException e)
         {
            b = false;
         }
      }

      return b;
   }

   /**
    * Extract the command-line parameters and initialize the MQ HashTable.
    * @param args
    * @throws IllegalArgumentException
    */
   private void init(String[] args) throws IllegalArgumentException
   {
      int port = 1414;
      if (args.length > 0 && (args.length % 2) == 0)
      {
         for (int i = 0; i < args.length; i += 2)
         {
            params.put(args[i], args[i + 1]);
         }
      }
      else
      {
         throw new IllegalArgumentException();
      }

      if (allParamsPresent())
      {
         if (params.containsKey("-c"))
         {
            try
            {
               port = Integer.parseInt((String) params.get("-p"));
            }
            catch (NumberFormatException e)
            {
               port = 1414;
            }
           
            mqht.put(CMQC.CHANNEL_PROPERTY, params.get("-c"));
            mqht.put(CMQC.HOST_NAME_PROPERTY, params.get("-h"));
            mqht.put(CMQC.PORT_PROPERTY, new Integer(port));
            if (params.containsKey("-u"))
               mqht.put(CMQC.USER_ID_PROPERTY, params.get("-u"));
            if (params.containsKey("-x"))
               mqht.put(CMQC.PASSWORD_PROPERTY, params.get("-x"));
         }

         // I don't want to see MQ exceptions at the console.
         MQException.log = null;
      }
      else
      {
         throw new IllegalArgumentException();
      }
   }

   /**
    * Connect, open queue, loop and get all messages then close queue and disconnect.
    *
    */
   private void testReceive()
   {
      String qMgrName = (String) params.get("-m");
      String inputQName = (String) params.get("-q");
      MQQueueManager qMgr = null;
      MQQueue queue = null;
      int openOptions = CMQC.MQOO_INPUT_AS_Q_DEF + CMQC.MQOO_INQUIRE + CMQC.MQOO_FAIL_IF_QUIESCING;
      MQGetMessageOptions gmo = new MQGetMessageOptions();
      gmo.options = CMQC.MQGMO_WAIT + CMQC.MQGMO_FAIL_IF_QUIESCING;
      gmo.waitInterval = 100;
      MQMessage receiveMsg = null;
      int msgCount = 0;
      boolean getMore = true;

      try
      {
         if (params.containsKey("-c"))
            qMgr = new MQQueueManager(qMgrName, mqht);
         else
            qMgr = new MQQueueManager(qMgrName);
         MQTest12L.logger("successfully connected to "+ qMgrName);

         queue = qMgr.accessQueue(inputQName, openOptions);
         MQTest12L.logger("successfully opened "+ inputQName);

         while(getMore)
         {
            receiveMsg = new MQMessage();

            try
            {
               // get the message on the queue
               queue.get(receiveMsg, gmo);
               msgCount++;

               if (CMQC.MQFMT_STRING.equals(receiveMsg.format))
               {
                  String msgStr = receiveMsg.readStringOfByteLength(receiveMsg.getMessageLength());
//                  MQTest12L.logger("["+msgCount+"] " + msgStr);
               }
               else
               {
                  byte[] b = new byte[receiveMsg.getMessageLength()];
                  receiveMsg.readFully(b);
//                  MQTest12L.logger("["+msgCount+"] " + new String(b));
               }
            }
            catch (MQException e)
            {
               if ( (e.completionCode == CMQC.MQCC_FAILED) &&
                    (e.reasonCode == CMQC.MQRC_NO_MSG_AVAILABLE) )
               {
                  // All messages read.
                  getMore = false;
                  break;
               }
               else if ( (e.completionCode == CMQC.MQCC_FAILED) &&
                         (e.reasonCode == CMQC.MQRC_GET_INHIBITED) )
               {
                  MQTest12L.logger("Queue is get inhibited. : CC=" + e.completionCode+" RC="+e.reasonCode);
                  try
                  {
                     Thread.sleep(60 * 1000);  // sleep for 1 minute
                  }
                  catch(Exception e1)
                  {}
               }
               else if ( (e.completionCode == CMQC.MQCC_WARNING) &&
                         (e.reasonCode == CMQC.MQRC_TRUNCATED_MSG_ACCEPTED) )
                {
                  // its ok - we got part of a message - continue on.

                  msgCount++;

                  try
                  {
                     if (CMQC.MQFMT_STRING.equals(receiveMsg.format))
                     {
                        String msgStr = receiveMsg.readStringOfByteLength(receiveMsg.getMessageLength());
                        MQTest12L.logger("["+msgCount+"] " + msgStr);
                     }
                     else
                     {
                        byte[] b = new byte[receiveMsg.getMessageLength()];
                        receiveMsg.readFully(b);
                        MQTest12L.logger("["+msgCount+"] " + new String(b));
                     }
                  }
                  catch (EOFException e1)
                  {
                     MQTest12L.logger("EOFException: " + e1.getLocalizedMessage());
                  }
                  catch (IOException e1)
                  {
                     MQTest12L.logger("IOException: " + e1.getLocalizedMessage());
                  }
                }
               else
               {
                  MQTest12L.logger("MQException: " + e.getLocalizedMessage());
                  MQTest12L.logger("CC=" + e.completionCode + " : RC=" + e.reasonCode);
                  getMore = false;
                  break;
               }
            }
            catch (IOException e)
            {
               MQTest12L.logger("IOException:" +e.getLocalizedMessage());
            }
         }
      }
      catch (MQException e)
      {
         MQTest12L.logger("CC=" +e.completionCode + " : RC=" + e.reasonCode);
      }
      finally
      {
         MQTest12L.logger("read " + msgCount + " messages");

         try
         {
            if (queue != null)
            {
               queue.close();
               MQTest12L.logger("closed: "+ inputQName);
            }
         }
         catch (MQException e)
         {
            MQTest12L.logger("CC=" +e.completionCode + " : RC=" + e.reasonCode);
         }
         try
         {
            if (qMgr != null)
            {
               qMgr.disconnect();
               MQTest12L.logger("disconnected from "+ qMgrName);
            }
         }
         catch (MQException e)
         {
            MQTest12L.logger("CC=" +e.completionCode + " : RC=" + e.reasonCode);
         }
      }
   }

   /**
    * A simple logger method
    * @param data
    */
   public static void logger(String data)
   {
      String className = Thread.currentThread().getStackTrace()[2].getClassName();

      // Remove the package info.
      if ( (className != null) && (className.lastIndexOf('.') != -1) )
         className = className.substring(className.lastIndexOf('.')+1);

      System.out.println(LOGGER_TIMESTAMP.format(new Date())+" "+className+": "+Thread.currentThread().getStackTrace()[2].getMethodName()+": "+data);
   }

   /**
    * main line
    * @param args
    */
   public static void main(String[] args)
   {
      MQTest12L write = new MQTest12L();

      try
      {
         write.init(args);
         write.testReceive();
      }
      catch (IllegalArgumentException e)
      {
         System.err.println("Usage: java MQTest12L -m QueueManagerName -q QueueName [-h host -p port -c channel] [-u UserID] [-x Password]");
         System.exit(1);
      }

      System.exit(0);
   }
}


Regards,
Roger Lacroix
Capitalware Inc.
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
bruce2359
PostPosted: Thu May 06, 2021 11:11 am    Post subject: Re: TIBCO JAVA Application and 2016 Reply with quote

Poobah

Joined: 05 Jan 2008
Posts: 9394
Location: US: west coast, almost. Otherwise, enroute.

w1ndy wrote:

Queue get inhibited

Application gets the 2016

Queue get enabled

You didn't offer much detail here. For example, did you get-inhibit the queue as part of your testing?

If not, then I'd suggest that you enable configuration events to discover who get-inhibited the queue. Queue attributes can be enabled/inhibited by application programs and/or administrators.
_________________
I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live.
Back to top
View user's profile Send private message
w1ndy
PostPosted: Fri May 07, 2021 12:53 am    Post subject: Reply with quote

Apprentice

Joined: 19 Jan 2011
Posts: 38

Thanks very much Roger.

Bruce, we are testing the application and that is where the behaviour was observed.

Thanks both.

Andrew
Back to top
View user's profile Send private message Send e-mail
bruce2359
PostPosted: Fri May 07, 2021 5:22 am    Post subject: Reply with quote

Poobah

Joined: 05 Jan 2008
Posts: 9394
Location: US: west coast, almost. Otherwise, enroute.

w1ndy wrote:
Thanks very much Roger.

Bruce, we are testing the application and that is where the behaviour was observed.

Thanks both.

Andrew

Sorry, but I don’t understand your reply. Did you get-inhibited the queue? Or observe that something/someone get-inhibited the queue? This is an important point.
_________________
I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » TIBCO JAVA Application and 2016
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.