MQ JMS setClientReconnectOptions not working as expected?

I have a simple code to post 2 messages to a queue.
1) I have set up a connectionNameList with two servers.
2) These two servers are independent but have the same queue manager and a queue with the same name such as "QMgr" and "TEST.IN"
3) I set setClientReconnectOptions (WMQConstants.WMQ_CLIENT_RECONNECT);
  Hopefully when the first server is down it should send messages to the second one.

The test I did:
 a) I am sending the first message, sender.send (message); It worked.
 b) sleep 30 seconds.
  During this time I shutdown the first server
 c) then do a sleep, try to send the 2nd message, but it couldn't send immediately

Moreover, I tried more, I tried {} catch {} for the 2nd post, and in catch {}, I try to pass sender.send (message), it still fails.

Any idea why it is different than expected. I will be very grateful for your answer.

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");
  }

      

+3


source to share


1 answer


Well this is the simplest test case and should work. How did you hit the first queue manager? You used it with an option -r

. Remember, without the option, -r

clients will not reconnect when the queue manager ends up with a command endmqm

.

endmqm -r <qm name>

      

Assuming you used the parameter -r

and it still doesn't work, then my suggestion would be to try this:



Install an exception listener to see what happens with reconnection. An exception listener is called when a connection fails and attempts to reconnect until the reconnection is successful or complete. The exception listener example code would be something like this:

conn.setExceptionListener(new ExceptionListener() {

  public void onException(JMSException e) {
    System.out.print(e);
  }
});

      

+3


source







All Articles