Reputation: 505
I have a simple code to put 2 messages into a queue.
1) I set the connectionNameList with two servers.
2) Those two servers are independent, but have the same Queue Manager and Queue defined with same name, such as "QMgr" and "TEST.IN"
3) I set the setClientReconnectOptions(WMQConstants.WMQ_CLIENT_RECONNECT);
I hope when the first server is down, it should send the messages to 2nd one.
The test I did:
a) I send first message, sender.send(message); It worked.
b) sleep 30 seconds.
During this time, I shutdown the first server
c) then sleep done, try to send 2nd message, but it failed to send immediately
Further more, I tried more, I did try{} catch{} for 2nd message, and in the catch{}, I try to sender.send(message), it still fails.
Any idea why it is different than what I expected. I will really appreciate your reply.
public static void main(String[] args) throws Exception
{
MQQueueConnectionFactory cf = new MQQueueConnectionFactory();
cf.setConnectionNameList("10.230.34.191(1418),10.230.34.169(1418)");
cf.setQueueManager("QMgr");
cf.setTransportType(WMQConstants.WMQ_CM_CLIENT);
cf.setClientReconnectOptions(WMQConstants.WMQ_CLIENT_RECONNECT);
cf.setClientReconnectTimeout(600);
System.out.println("connect list " + cf.getConnectionNameList());
MQQueueConnection connection = (MQQueueConnection) cf
.createQueueConnection("mqm", "passwd");
MQQueueSession session = (MQQueueSession) connection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
MQQueue queue = (MQQueue) session.createQueue("queue:///TEST.IN");
MQQueueSender sender = (MQQueueSender) session.createSender(queue);
long uniqueNumber = System.currentTimeMillis() % 1000;
JMSTextMessage message = (JMSTextMessage) session.createTextMessage("SimplePTP "
+ uniqueNumber);
// Start the connection
connection.start();
sender.send(message);
System.out.println("Sent message:\\n" + message);
System.out.println("sleep 30 seconds");
Thread.sleep(30000);
uniqueNumber = System.currentTimeMillis() % 1000;
message = (JMSTextMessage) session.createTextMessage("SimplePTP " + uniqueNumber);
sender.send(message);
sender.close();
session.close();
connection.close();
System.out.println("\\nSUCCESS\\n");
}
Upvotes: 3
Views: 4400
Reputation: 15273
Well this is the simplest test case and should have worked. How did you bring down the first queue manager? Did you down it with a -r
option. Remember, without the -r
option the clients will not reconnect when queue manager is ended with endmqm
command.
endmqm -r <qm name>
Assuming you used -r
option and it still did not work, then my suggestion would be to try the following:
Set an exception listener to know what is going on with reconnection. Exception listener would be invoked when the connection is broken and reconnection attempt starts till either reconnection is successful or fails. Exception listener sample code would be something like this:
conn.setExceptionListener(new ExceptionListener() {
public void onException(JMSException e) {
System.out.print(e);
}
});
Upvotes: 3