0
votes

I am new to IBM MQ,my queue manager uses tcp channel connection and the tcp connections go up extensively, this is the piece of code am using. How to handle connections within the channel in a reusable manner?

I am using 7.5 MQ client, talking to 6.0.5.2 MQ remote server. I close the connection properly, however when i run a netstat it says tcp connections in time_wait state. Are these connection/socket leaks?

MQQueue mqQueue = null; 
MQQueueManager mqQMgr=null;  
try
{
  //Create connection to queue manager
   mqQMgr = new MQQueueManager("Queue Manager name", properties);
  //Access the queue
    mqQueue = mqQMgr.AccessQueue(QueueName, MQC.MQOO_FAIL_IF_QUIESCING | MQC.MQOO_INPUT_SHARED | MQC.MQOO_BROWSE);
   for(int i=1;i<2000;i++)
  {
    //read the messages
    mqMsg=new MQMessage();
    mqQueue.Get(mqMsg);
  }
}
catch(MQException mqe)
{  
  //If no messages in the queue , break. (if not, catch any error)
}
finally
{
     mqQueue.Close(); //Close the MQ Queue
     mqQMgr.Disconnect(); //Disconnect the MQ Manager
}

When i run a netstat, it shows

TCP x.x.x.x:59092    x.x.x.x:1400  TIME_WAIT 
TCP x.x.x.x:59093    x.x.x.x:1400  TIME_WAIT
TCP x.x.x.x:59094    x.x.x.x:1400  TIME_WAIT
TCP x.x.x.x:59095    x.x.x.x:1400  TIME_WAIT
TCP x.x.x.x:59096    x.x.x.x:1400  TIME_WAIT
TCP x.x.x.x:59097    x.x.x.x:1400  TIME_WAIT
TCP x.x.x.x:59098    x.x.x.x:1400  TIME_WAIT
TCP x.x.x.x:59099    x.x.x.x:1400  TIME_WAIT
1
Any inputs will help?Sharpeye500

1 Answers

3
votes

It's not a leak. A socket enters into TIME_WAIT state after it has been closed. It is normal for a socket to be in TIME_WAIT for a longer time, something like 4 minutes and depends on the operating system.