Reputation: 486
I'm trying to connect to my MQ servers. I have 2 MQ Server: server 1 and server 2 and set it as connectionNameList
for mqConnectionFactory
. Is there a way for MQ to connect to server 1 if server 2 failed? How can I know if MQ server is connected? I saw that there is clientReconnectOptions
set to 67108864
but I'm not sure what is that.
Upvotes: 2
Views: 4978
Reputation: 10672
The possible settings for ClientReconnectOptions are documented in the IBM MQ Knowledge center page CLIENTRECONNECTOPTIONS
Below is an example using setClientReconnectOptions
to set it so the application can reconnect to any queue manager listing on the two host(port) combinations set in the connectionNameList
.
MQQueueConnectionFactory factory = new MQQueueConnectionFactory();
factory.setQueueManager("QMNAME");
factory.setChannel("SVRCONN.CHL");
factory.setConnectionNameList("hostName1(port),hostName2(port)");
factory.setClientReconnectOptions( WMQConstants.WMQ_CLIENT_RECONNECT );
// Set the amount of time you will attempt to reconnect in seconds
factory.setClientReconnectTimeout( 43200 ); //12 hours
//default is 1800 seconds
//factory.setClientReconnectTimeout(WMQConstants.WMQ_CLIENT_RECONNECT_TIMEOUT_DEFAULT);
Note that clients will not always attempt to reconnect, see the following from the endmqm
man page on Linux:
If you issue endmqm to stop a queue manager, reconnectable clients do not try to reconnect. To override this behavior, specify either the -r or -s option to enable clients to start trying to reconnect.
Note: If a queue manager or a channel ends unexpectedly, reconnectable clients start trying to reconnect.
Upvotes: 1