0
votes

On my below code connect() method is able to catch the 2009 and 2059 exceptions. But when I make my queue manager or connection down to generate 2009 or 2059 MQ exception in getMessage() method , program is getting hung or it didn't throws it . It is waiting in line queue.get(retrievedMessage, getOptions);.

Do we need to add additional open option to make the code aware if a connection or queue manager is broken ?

Connect()
{

MQEnvironment.hostname = hostName; MQEnvironment.channel = channelName; MQEnvironment.port = portName; try { qMgr = new MQQueueManager(EvtqManager); // define a queue manager object LOGGER.debug("Queue Manager " +EvtqManager+ " Instance Initialized"); int openOptions = MQC.MQOO_INQUIRE + MQC.MQOO_FAIL_IF_QUIESCING+ MQC.MQOO_INPUT_SHARED; queue = qMgr.accessQueue(queueName, openOptions, null,null,null); LOGGER.debug("IBM MQQueue:"+queueName+" is accessed"); getOptions = new MQGetMessageOptions(); getOptions.options = MQC.MQGMO_NO_WAIT; getMessage(); } catch(){ if(MQex.reasonCode==2009 || MQex.reasonCode==2059){ shutDown(); Connect(); } }

getMessage(){ MQMessage retrievedMessage; while (true) { try { retrievedMessage = new MQMessage(); queue.get(retrievedMessage, getOptions); PCFMessage pcfMessage = new PCFMessage(retrievedMessage); } catch (MQException MQex) { if(MQex.reasonCode==2009 || MQex.reasonCode==2059){ shutDown(); Connect(); } } }

`
1
@Vignesh: I am also looking for a solution which should hel me to know whether the queue is down for maintainance or any other problem while making connection.Our queues are also on mainframe.Please advise!!!NeverGiveUp161

1 Answers

1
votes

No additional options are required. If a MQ method call is in progress and a connection to a queue manager breaks, then the method will return with reason code 2009 or other connection error related reason codes. The reason codes returned will depend on how the connection was broken, for example MQRC_Q_MGR_QUIESCING/MQRC_Q_QMGR_STOPPING will be returned if queue manager is being shutdown.

The hang could be due to the time taken to detect a socket failure. So you may want to check how long does the call wait.

MQRC 2059 is returned when connecting to queue manager but not while receiving messages. So you can remove the check for 2059.

I am just puzzled a bit on your code. You have calls to shutdown() and Connect() inside Connect and getMessage methods. Don't you think this leads to recursion?