| Author | 
		  Message
		 | 
		
		  | Bokie | 
		  
		    
			  
				 Posted: Mon Aug 13, 2012 5:56 am    Post subject: Manual Reconnect | 
				     | 
			   
			 
		   | 
		
		
		   Newbie
 
 Joined: 13 Aug 2012 Posts: 8
  
  | 
		  
		    
			  
				Hi,
 
 
I am using the WebSphere MQ V7.0.1.8 JMS client library to connect to an MQSeries V7.0 broker on an iSeries.
 
 
My listener works fine when I start my service and a working connection is established.
 
 
I am trying to manually reconnect when the ExeceptionListener that I've attached to the connection gets notified of any error - an execption is always thrown every Sunday when IPL is performed on the iSeries.
 
 
The reconnection process I've setup attempts to reconnect every 30 seconds. However, I have not been able to re-establish a connection even after the iSeries, Broker and corresponding QueueManager are up and running - the only way to establish a connection is to re-start my entire service.
 
 
The following is the setup for my QueueConnectionFactory:
 
   
	| Code: | 
   
  
	factory = new MQQueueConnectionFactory();
 
factory.setHostName(host);
 
factory.setPort(Integer.parseInt(port, 10));
 
factory.setQueueManager(queueManager);
 
factory.setChannel(channel);
 
factory.setTransportType(WMQConstants.WMQ_CM_CLIENT);
 
factory.setClientReconnectOptions(WMQConstants.WMQ_CLIENT_RECONNECT_DISABLED);
 
factory.setCCSID(Integer.valueOf(ccsid));
 
 | 
   
 
 
 
The following are the steps I perform after the ExeceptionListener gets notified (every 30 seconds if a connection cannot be established):
 
   
	| Code: | 
   
  
	01. receiver.close()
 
02. session.close()
 
03. connection.close()
 
// I've even gone as far as nullifying all messaging components
 
04. receiver = null;
 
05. queue = null;
 
06. session = null;
 
07. connection = null;
 
// ask for new connection
 
08. connection = queueConnectionFactoryProvider.getQueueConnectionFactory().createQueueConnection();
 
09. connection.setExceptionListener(exceptionListener);
 
10. session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
 
11. queue = session.createQueue(AsyncRequester.instance().config.get(ConfigKey.MESSAGING_RESPONSEQ.publishedName()));
 
12. receiver = session.createReceiver(queue);
 
13. receiver.setMessageListener(messageListener);
 
14. connection.start();
 
 | 
   
 
 
 
Am I missing something here; does a manual reconnect require anything special.
 
 
Thanks and regards,
 
Bokie | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Bokie | 
		  
		    
			  
				 Posted: Mon Aug 13, 2012 6:00 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Newbie
 
 Joined: 13 Aug 2012 Posts: 8
  
  | 
		  
		    
			  
				The site did not allow me to post the exception on my first post - something like "you need 1 post before you can post URL's/links"
 
 
The 30 second loop goes on and on even when the broker is fully operational with the following exception logged:
 
   
	| Code: | 
   
  
	2012-08-12 23:59:59,578||ERROR||my.domain.messaging||listener start error, attempting a reconnect in 30 SECONDS
 
com.ibm.msg.client.jms.DetailedJMSException: JMSWMQ0018: Failed to connect to queue manager 'Q-MANAGER-NAME' with connection mode 'Client' and host name 'xxx.xxx.xxx.xxx(1415)'.
 
   at com.ibm.msg.client.wmq.common.internal.Reason.reasonToException(Reason.java:608) ~[na:na]
 
   at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:236) ~[na:na]
 
   at com.ibm.msg.client.wmq.internal.WMQConnection.<init>(WMQConnection.java:452) ~[na:na]
 
   at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createV7ProviderConnection(WMQConnectionFactory.java:7192) ~[na:na]
 
   at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createProviderConnection(WMQConnectionFactory.java:6583) ~[na:na]
 
   at com.ibm.msg.client.jms.admin.JmsConnectionFactoryImpl.createConnection(JmsConnectionFactoryImpl.java:295) ~[na:na]
 
   at com.ibm.mq.jms.MQConnectionFactory.createCommonConnection(MQConnectionFactory.java:6232) ~[na:na]
 
   at com.ibm.mq.jms.MQQueueConnectionFactory.createQueueConnection(MQQueueConnectionFactory.java:115) ~[na:na]
 
   at my.domain.messaging.impl.AsyncRequester$ResponseListener$1.run(AsyncRequester.java:211) ~[na:na]
 
   at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[na:1.7.0_05]
 
   at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) ~[na:1.7.0_05]
 
   at java.util.concurrent.FutureTask.run(Unknown Source) ~[na:1.7.0_05]
 
   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source) ~[na:1.7.0_05]
 
   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) ~[na:1.7.0_05]
 
   at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) ~[na:1.7.0_05]
 
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) ~[na:1.7.0_05]
 
   at java.lang.Thread.run(Unknown Source) ~[na:1.7.0_05]
 
Caused by: com.ibm.mq.MQException: JMSCMQ0001: WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2009' ('MQRC_CONNECTION_BROKEN').
 
   at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:223) ~[na:na]
 
   ... 15 common frames omitted
 
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2009;AMQ9204: Conexão ao host 'xxx.xxx.xxx.xxx(1415)' rejeitada. [1=com.ibm.mq.jmqi.JmqiException[CC=2;RC=2009;AMQ9213: Ocorreu um erro de comunicação em  .],3=xxx.xxx.xxx.xxx(2000),5=RemoteConnection.receiveAsyncTsh]
 
   at com.ibm.mq.jmqi.remote.internal.RemoteFAP.jmqiConnect(RemoteFAP.java:2072) ~[na:na]
 
   at com.ibm.mq.jmqi.remote.internal.RemoteFAP.jmqiConnect(RemoteFAP.java:1286) ~[na:na]
 
   at com.ibm.msg.client.wmq.internal.WMQConnection.<init>(WMQConnection.java:367) ~[na:na]
 
   ... 14 common frames omitted
 
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2009;AMQ9213: Ocorreu um erro de comunicação em  .
 
   at com.ibm.mq.jmqi.remote.internal.system.RemoteConnection.receiveAsyncTsh(RemoteConnection.java:3192) ~[na:na]
 
   at com.ibm.mq.jmqi.remote.internal.system.RemoteConnection.receiveTSH(RemoteConnection.java:2782) ~[na:na]
 
   at com.ibm.mq.jmqi.remote.internal.system.RemoteConnection.initSess(RemoteConnection.java:1496) ~[na:na]
 
   at com.ibm.mq.jmqi.remote.internal.system.RemoteConnection.connect(RemoteConnection.java:1165) ~[na:na]
 
   at com.ibm.mq.jmqi.remote.internal.system.RemoteConnectionPool.getConnection(RemoteConnectionPool.java:353) ~[na:na]
 
   at com.ibm.mq.jmqi.remote.internal.RemoteFAP.jmqiConnect(RemoteFAP.java:1660) ~[na:na]
 
   ... 16 common frames omitted
 
 | 
   
 
 
 
 
Am I missing something here; does a manual reconnect require anything special.
 
 
Thanks and regards,
 
Bokie | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | fjb_saper | 
		  
		    
			  
				 Posted: Mon Aug 13, 2012 4:59 pm    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 18 Nov 2003 Posts: 20768 Location: LI,NY 
  | 
		  
		    
			  
				you did not specify... My guess is you are using a pool and returning the connection to the pool. Set the policy to purge the pool when you get the exception. This way a true new connection can be created, instead of trying to reuse a dead one...   _________________ MQ & Broker admin | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Bokie | 
		  
		    
			  
				 Posted: Tue Aug 14, 2012 1:07 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Newbie
 
 Joined: 13 Aug 2012 Posts: 8
  
  | 
		  
		    
			  
				Hi fjb_saper,
 
 
How can I "Set the policy to purge the pool when you get the exception" programatically; is this set on the MQQueueConnectionFactory object?
 
 
Thanks | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | fjb_saper | 
		  
		    
			  
				 Posted: Tue Aug 14, 2012 7:19 pm    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 18 Nov 2003 Posts: 20768 Location: LI,NY 
  | 
		  
		    
			  
				If you are using WAS it is set in JNDI where you define the ConnectionFactory...
 
 
Have fun   _________________ MQ & Broker admin | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Bokie | 
		  
		    
			  
				 Posted: Thu Aug 16, 2012 4:42 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Newbie
 
 Joined: 13 Aug 2012 Posts: 8
  
  | 
		  
		    
			  
				Thanks fjb_saper,
 
 
And if we're not using WAS?
 
 
What if we need to set it programmatically? | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | fjb_saper | 
		  
		    
			  
				 Posted: Thu Aug 16, 2012 6:40 pm    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 18 Nov 2003 Posts: 20768 Location: LI,NY 
  | 
		  
		    
			  
				
   
	| Bokie wrote: | 
   
  
	Thanks fjb_saper,
 
 
And if we're not using WAS?
 
 
What if we need to set it programmatically? | 
   
 
 
 
Check with your J2EE / pool provider.
 
This is a feature of the pool implementation...   _________________ MQ & Broker admin | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Bokie | 
		  
		    
			  
				 Posted: Fri Sep 07, 2012 12:23 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Newbie
 
 Joined: 13 Aug 2012 Posts: 8
  
  | 
		  
		    
			  
				I am not running the solution in any J2EE server and I am using the pool provider that the "WebSphere MQ V7.0 Clients" components provides at http://www-01.ibm.com/support/docview.wss?rs=171&uid=swg24019253&loc=en_US&cs=utf-8&lang=en
 
 
I have tried several approaches - the most recent one, recreating a brand new com.ibm.mq.jms.MQQueueConnectionFactory when the ExceptionListener is notified, and still cannot recover from a comunications,connection error unless the I restart the entire application i.e. a new JVM instance. This smells like a series of singleton pattern implementations throughout the entire stack (factories, connection pools, session pools?? etc) - so how on God's green earth am I ever going to be able to recover from an error if the "stale" components can never be "replaced". | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | fjb_saper | 
		  
		    
			  
				 Posted: Fri Sep 07, 2012 2:50 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 18 Nov 2003 Posts: 20768 Location: LI,NY 
  | 
		  
		    
			  
				You did not specify if you are running stand alone or in a framework: J2EE, Spring, etc...
 
If running in a framework look at the framework provider for ways to purge the pool. If running stand alone you have created a pool. You need to hold on to the pool handle in order to be able to purge it...   _________________ MQ & Broker admin | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Bokie | 
		  
		    
			  
				 Posted: Fri Sep 07, 2012 6:12 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Newbie
 
 Joined: 13 Aug 2012 Posts: 8
  
  | 
		  
		    
			  
				Hi fjb_saper,
 
 
I'm currently using the OSGI bundles provided in the "WebSphere MQ V7.0 Clients" download.
 
 
The MQQueueConnectionFactory has a getter and setter to specify whether or not pooling should be used "setUseConnectionPooling(boolean)" - here I don't specify and from the docs "true" is the default value.
 
 
I am not providing any Pool implementation - there is no way to do it through the factory and I'm assuming that there is a default implementation being used.
 
 
Do you know of any documentation for these OSGI bundles? Is there any service being registered - a connection factory perhaps?
 
 
Thanks | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | fjb_saper | 
		  
		    
			  
				 Posted: Sat Sep 08, 2012 7:27 pm    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 18 Nov 2003 Posts: 20768 Location: LI,NY 
  | 
		  
		    
			  
				Sorry haven't played much with the OSGi bundles. You need to find how to access the pool implementation. It should have a method to purge the pool.   _________________ MQ & Broker admin | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Bokie | 
		  
		    
			  
				 Posted: Sun Sep 09, 2012 9:08 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Newbie
 
 Joined: 13 Aug 2012 Posts: 8
  
  | 
		  
		    
			  
				Hi fjb_saper,
 
 
I'm starting to think that there may be a bug in the IBM client API.
 
 
My factory is configured as follows:
 
      MQQueueConnectionFactory factory = new MQQueueConnectionFactory();
 
      factory.setStringProperty(WMQConstants.WMQ_CONNECTION_NAME_LIST, host+"("+port+")");
 
      factory.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER, queueManager);
 
      factory.setStringProperty(WMQConstants.WMQ_CHANNEL, channel);
 
      factory.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);
 
      factory.setIntProperty(WMQConstants.ASYNC_EXCEPTIONS, WMQConstants.ASYNC_EXCEPTIONS_CONNECTIONBROKEN);
 
      factory.setIntProperty(WMQConstants.WMQ_CLIENT_RECONNECT_OPTIONS, WMQConstants.WMQ_CLIENT_RECONNECT_DISABLED);
 
      factory.setStringProperty(WMQConstants.WMQ_CCSID, ccsid);
 
 
When I shutdown the queue manager at the iseries my exception listener gets notified of the following exception (stack trace removed for brevity):
 
  com.ibm.msg.client.jms.DetailedJMSException: JMSCMQ0002: The method 'MQCTL' failed. A WebSphere MQ call failed. Please see the linked exception for more information.
 
  Caused by: com.ibm.mq.MQException: JMSCMQ0001: WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2009' ('MQRC_CONNECTION_BROKEN').
 
  Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2009
 
  Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2009;AMQ9208: Error on receive from host '/xxx.xxx.xxx.xxx:1415 (domain.com)'. [1=-1,2=ffffffff,3=/xxx.xxx.xxx.xxx:1415 (domain.com),4=TCP]
 
 
SO FAR SO GOOD...
 
 
When I restart the queue manager at the iseries and my reconnection logic asks for a new QueueConnection I get the follwowing exception (stack trace removed for brevity):
 
  com.ibm.msg.client.jms.DetailedIllegalStateException: JMSWMQ0018: Failed to connect to queue manager 'TIMA' with connection mode 'Client' and host name 'xxx.xxx.xxx.xxx(1415)'. Check the queue manager is started and if running in client mode, check there is a listener running. Please see the linked exception for more information.
 
  Caused by: com.ibm.mq.MQException: JMSCMQ0001: WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2059' ('MQRC_Q_MGR_NOT_AVAILABLE').
 
  Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2059;AMQ9204: Connection to host 'xxx.xxx.xxx.xxx(1415)' rejected. [1=com.ibm.mq.jmqi.JmqiException[CC=2;RC=2059;AMQ9213: A communications error for  occurred. [1=java.net.ConnectException[Connection refused: connect],3=domain.com]],3=xxx.xxx.xxx.xxx(1415),5=RemoteTCPConnection.connnectUsingLocalAddress]
 
  Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2059;AMQ9213: A communications error for  occurred. [1=java.net.ConnectException[Connection refused: connect],3=domain.com]
 
  Caused by: java.net.ConnectException: Connection refused: connect
 
 
  AFTER A SHORT WHILE I GET...
 
 
  com.ibm.msg.client.jms.DetailedJMSException: JMSWMQ0018: Failed to connect to queue manager 'TIMA' with connection mode 'Client' and host name 'xxx.xxx.xxx.xxx(1415)'. Check the queue manager is started and if running in client mode, check there is a listener running. Please see the linked exception for more information.
 
  Caused by: com.ibm.mq.MQException: JMSCMQ0001: WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2009' ('MQRC_CONNECTION_BROKEN').
 
  Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2009;AMQ9204: Connection to host 'xxx.xxx.xxx.xxx(1415)' rejected. [1=com.ibm.mq.jmqi.JmqiException[CC=2;RC=2009;AMQ9213: A communications error for  occurred.],3=xxx.xxx.xxx.xxx(1415),5=RemoteConnection.receiveAsyncTsh]
 
  Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2009;AMQ9213: A communications error for  occurred.
 
 
The last four exceptions are exactly the same as when I start off with the factory configured as follows (note the WMQ_CLIENT_RECONNECT_XXX properties):
 
Our iseries is not configured for automatic reconnect.
 
 
      MQQueueConnectionFactory factory = new MQQueueConnectionFactory();
 
      factory.setStringProperty(WMQConstants.WMQ_CONNECTION_NAME_LIST, host+"("+port+")");
 
      factory.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER, queueManager);
 
      factory.setStringProperty(WMQConstants.WMQ_CHANNEL, channel);
 
      factory.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);
 
      factory.setIntProperty(WMQConstants.ASYNC_EXCEPTIONS, WMQConstants.ASYNC_EXCEPTIONS_CONNECTIONBROKEN);
 
      factory.setIntProperty(WMQConstants.WMQ_CLIENT_RECONNECT_OPTIONS, WMQConstants.WMQ_CLIENT_RECONNECT_Q_MGR);
 
      factory.setIntProperty(WMQConstants.WMQ_CLIENT_RECONNECT_TIMEOUT, 3600);
 
      factory.setStringProperty(WMQConstants.WMQ_CCSID, ccsid); | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Bokie | 
		  
		    
			  
				 Posted: Sun Sep 09, 2012 9:13 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Newbie
 
 Joined: 13 Aug 2012 Posts: 8
  
  | 
		  
		    
			  
				Forgot to mention that I can successfully recover from network failures, e.g. unplugging the network cable.
 
 
Thanks
 
Bokie | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Vitor | 
		  
		    
			  
				 Posted: Sun Sep 09, 2012 9:28 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA 
  | 
		  
		    
			  
				
   
	| Bokie wrote: | 
   
  
	| I'm starting to think that there may be a bug in the IBM client API. | 
   
 
 
 
To which the appropriate response is always a PMR. _________________ Honesty is the best policy.
 
Insanity is the best defence. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | mqjeff | 
		  
		    
			  
				 Posted: Sun Sep 16, 2012 8:49 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Grand Master
 
 Joined: 25 Jun 2008 Posts: 17447
  
  | 
		  
		    
			  
				I would take some steps to ensure you have really actually asked for a new connection and are not trying to reuse an existing cached session or connection handle.
 
 
Once you've eliminated that, if you see the same behavior, then take a trace and see if you can make anything useful out of it.  If not, open a PMR. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | 
		    
		   |