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 IndexIBM MQ Java / JMSHow do I set a connection timeout?

Post new topicReply to topic
How do I set a connection timeout? View previous topic :: View next topic
Author Message
wojciechb
PostPosted: Fri Jan 12, 2018 5:02 am Post subject: How do I set a connection timeout? Reply with quote

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
View user's profile Send private message
zpat
PostPosted: Fri Jan 12, 2018 10:21 am Post subject: Reply with quote

Jedi Council

Joined: 19 May 2001
Posts: 5658
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
View user's profile Send private message
tczielke
PostPosted: Fri Jan 12, 2018 3:06 pm Post subject: Reply with quote

Shaman

Joined: 08 Jul 2010
Posts: 749
Location: Illinois, USA

This thread talks about how to set the connection timeout for a base Java (IBM MQ Classes for Java) application -> http://www.mqseries.net/phpBB2/viewtopic.php?t=74834&highlight=

Base Java is different than JMS, but perhaps it still applies.
_________________
MQ administrator since 2010.
Back to top
View user's profile Send private message
hughson
PostPosted: Sun Jan 14, 2018 5:26 pm Post subject: Reply with quote

Sentinel

Joined: 09 May 2013
Posts: 863
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
View user's profile Send private message Visit poster's website
Display posts from previous:
Post new topicReply to topic Page 1 of 1

MQSeries.net Forum IndexIBM MQ Java / JMSHow do I set a connection timeout?
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.