以下の JMS コードで処理するために WebSphere MQ 理由コード 2009 をシミュレートしようとしていますが、取得できません。代わりに、2059 を取得しています。接続呼び出し中に SVRCONN チャネルを切断するだけです。サンプル コードで 2009 を取得するにはどうすればよいですか。再度接続してトランザクション セッションを使用する前に、スリープ時間を追加しました。理由コード 2009 を適切に処理して、頻繁に失敗する接続試行によって最終的にキュー マネージャーがスラッシングされないようにするには、他に何ができるでしょうか。コードを見つけてください。
private static void connectToQmgr(MQQueueConnectionFactory cf) {
// TODO Auto-generated method stub
MQQueueConnection connection = null;
MQQueueSession session = null;
MQQueue queue = null;
MQQueueSender sender = null;
//While Statement to make sure multiple connection tries are made until connection establishes
while (connection == null){
try {
connection = (MQQueueConnection) cf.createConnection();
session = (MQQueueSession) connection.createQueueSession(true, Session.CLIENT_ACKNOWLEDGE);
queue = (MQQueue) session.createQueue("queue:///LQ");
sender = (MQQueueSender) session.createSender(queue);
//MQQueueReceiver receiver = (MQQueueReceiver) session.createReceiver(queue);
long uniqueNumber = System.currentTimeMillis() % 1000;
TextMessage message = session.createTextMessage("MQJMSTest "+ uniqueNumber);
// Start the connection
connection.start();
sender.send(message);
session.commit();
System.out.println("Sent message:\\n" + message);
// JMSMessage receivedMessage = (JMSMessage) receiver.receive(10000);
// System.out.println("\\nReceived message:\\n" + receivedMessage);
session.commit();
sender.close();
// receiver.close();
session.close();
connection.stop();
connection.close();
System.out.println("\\nSUCCESS\\n");
} catch (JMSException je) {
System.err.println("Caught JMSException");
// Check for linked exceptions in JMSException to catch MQException and Reason Codes
Throwable t = je;
while (t != null) {
// Write out the message that is applicable to all exceptions
System.err.println("Exception Msg: " + t.getMessage());
// Write out the exception stack trace
t.printStackTrace(System.err);
// Add on specific information depending on the type of exception
if (t instanceof JMSException) {
JMSException je1 = (JMSException) t;
System.err.println("JMS Error code: " + je1.getErrorCode());
if (t instanceof JmsExceptionDetail){
JmsExceptionDetail jed = (JmsExceptionDetail)je1;
System.err.println("JMS Explanation: " + jed.getExplanation());
System.err.println("JMS Explanation: " + jed.getUserAction());
}
} else if (t instanceof MQException) {
MQException mqe = (MQException) t;
System.err.println("WMQ Completion code: " + mqe.getCompCode());
System.err.println("WMQ Reason code: " + mqe.getReason());
//###################################################################################
//MQ Reason Code Error Handle here
//Currently Handling MQ Reason Code 2059 since unable to simulate 2009
//If connection handle exists make sure you close everything and add a wait interval and try a new connection again
if (mqe.getReason()== 2059){
System.out.println("Inside MQ Reson Code Handle");
if( connection != null){
try {
sender.close();
// receiver.close();
session.close();
connection.stop();
connection.close();
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// Add Wait Interval for 5 sec
try {
Thread.sleep(5000);
System.out.println("Inside Thread Sleep for 5 sec");
//Try New connecting Again
connectToQmgr(cf);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//##################################################################################
} else if (t instanceof JmqiException){
JmqiException jmqie = (JmqiException)t;
System.err.println("WMQ Log Message: " + jmqie.getWmqLogMessage());
System.err.println("WMQ Explanation: " + jmqie.getWmqMsgExplanation());
System.err.println("WMQ Msg Summary: " + jmqie.getWmqMsgSummary());
System.err.println("WMQ Msg User Response: "
+ jmqie.getWmqMsgUserResponse());
System.err.println("WMQ Msg Severity: " + jmqie.getWmqMsgSeverity());
}
// Get the next cause
t = t.getCause();
}
}
}
}