|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
How do I set a connection timeout? |
« View previous topic :: View next topic » |
Author |
Message
|
wojciechb |
Posted: Fri Jan 12, 2018 5:02 am Post subject: How do I set a connection timeout? |
|
|
Newbie
Joined: 09 Jan 2018 Posts: 1
|
How do I set a connection timeout via the JMS API?
So far I have only found a workaround to run it in a thread that I kill:
Code: |
final com.ibm.msg.client.jms.JmsConnectionFactory factory = JmsFactoryFactory
.getInstance(WMQ_PROVIDER)
.createConnectionFactory();
factory.setIntProperty(WMQ_CONNECTION_MODE, WMQ_CM_CLIENT);
factory.setStringProperty(WMQ_HOST_NAME, ibmMqConnectionData.hostname);
factory.setIntProperty(WMQ_PORT, ibmMqConnectionData.port);
factory.setStringProperty(WMQ_QUEUE_MANAGER, ibmMqConnectionData.queueManager);
factory.setStringProperty(WMQ_CHANNEL, ibmMqConnectionData.channel);
// The default timeout on createConnection() is around 2 minutes by the looks of it
// I do not know how to set the timeout on createConnection(), so I am using a ScheduledExecutorService instead.
ScheduledExecutorService executor = Executors.newScheduledThreadPool(2);
final Future<Connection> handler = executor.submit(new Callable<Connection>(){
@Override
public Connection call() throws Exception {
return factory.createConnection(ibmMqConnectionData.username, ibmMqConnectionData.password);
}
});
executor.schedule(new Runnable(){
public void run(){
handler.cancel(true);
}
}, timeout, timeoutUnit);
try {
return handler.get();
} catch (CancellationException e) {
throw new IbmMqConnectionJMSException("Timed out while connecting to " + ibmMqConnectionData.hostname, e);
} catch (InterruptedException | ExecutionException e) {
throw new IbmMqConnectionJMSException("Error connecting to " + ibmMqConnectionData.hostname, e);
} finally {
executor.shutdown();
}
|
|
|
Back to top |
|
 |
zpat |
Posted: Fri Jan 12, 2018 10:21 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
There is a socket timeout setting possible in mqclient.ini - not sure if that will affect JMS or not. _________________ Well, I don't think there is any question about it. It can only be attributable to human error. This sort of thing has cropped up before, and it has always been due to human error. |
|
Back to top |
|
 |
tczielke |
Posted: Fri Jan 12, 2018 3:06 pm Post subject: |
|
|
Guardian
Joined: 08 Jul 2010 Posts: 941 Location: Illinois, USA
|
|
Back to top |
|
 |
hughson |
Posted: Sun Jan 14, 2018 5:26 pm Post subject: |
|
|
 Padawan
Joined: 09 May 2013 Posts: 1959 Location: Bay of Plenty, New Zealand
|
zpat wrote: |
There is a socket timeout setting possible in mqclient.ini - not sure if that will affect JMS or not. |
See IBM MQ Little Gem #13: mqclient.ini.
Connect_Timeout (mqclient.ini file) is used by Java and JMS.
Cheers,
Morag _________________ Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
Get your IBM MQ training here!
MQGem Software |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|