我想從Java程序中將消息發送到Queue,我遇到了一個問題,它說它無法連接到主機&看起來它不是能夠閱讀頻道。從Java程序寫入消息到隊列時發生Websphere MQ問題
下面是從AMERR01.log誤差
----- amqccita.c : 4113 -------------------------------------------------------
07/25/2016 07:04:29 AM - Process(18280.26) User(mqm) Program(amqrmppa)
Host(ip-10-0-0-238) Installation(Installation1)
VRMF(8.0.0.4) QMgr(CSBTS.QUEUE.MANAGER)
AMQ9209: Connection to host 'ip-10-0-0-238 (10.0.0.238)' for channel 'CHAN2'
closed.
EXPLANATION:
An error occurred receiving data from 'ip-10-0-0-238 (10.0.0.238)' over TCP/IP.
The connection to the remote host has unexpectedly terminated.
The channel name is 'CHAN2'; in some cases it cannot be determined and so is
shown as '????'.
ACTION:
Tell the systems administrator.
這裏是Java代碼,
package com.sample.mq.client.ClientMQ;
import java.io.IOException;
import com.ibm.mq.MQC;
import com.ibm.mq.MQEnvironment;
import com.ibm.mq.MQException;
import com.ibm.mq.MQGetMessageOptions;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQPutMessageOptions;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;
/**
* Java class to connect to MQ. Post and Retreive messages.
*
*/
public class MQClientTest {
String qMngrStr = "CSBTS.QUEUE.MANAGER";
String user = "mqm";
String password = "[email protected]";
String queueName = "CSBTS.DEAL";
String hostName = "10.0.0.238";
int port = 1414;
String channel = "CHAN2";
//message to put on MQ.
String msg = "Hello World, WelCome to MQ.";
//Create a default local queue.
MQQueue defaultLocalQueue;
MQQueueManager qManager;
/**
* Initialize the MQ
*
*/
public void init(){
//Set MQ connection credentials to MQ Envorinment.
MQEnvironment.hostname = hostname;
MQEnvironment.channel = channel;
MQEnvironment.port = port;
MQEnvironment.userID = user;
MQEnvironment.password = password;
//set transport properties.
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT);
try {
//initialize MQ manager.
qManager = new MQQueueManager(qMngrStr);
} catch (MQException e) {
e.printStackTrace();
}
}
/**
* Method to put message to MQ.
*
*/
public void putAndGetMessage(){
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
try {
defaultLocalQueue = qManager.accessQueue(queueName, openOptions);
MQMessage putMessage = new MQMessage();
putMessage.writeUTF(msg);
//specify the message options...
MQPutMessageOptions pmo = new MQPutMessageOptions();
// accept
// put the message on the queue
defaultLocalQueue.put(putMessage, pmo);
System.out.println("Message is put on MQ.");
//get message from MQ.
MQMessage getMessages = new MQMessage();
//assign message id to get message.
getMessages.messageId = putMessage.messageId;
//get message options.
MQGetMessageOptions gmo = new MQGetMessageOptions();
defaultLocalQueue.get(getMessages, gmo);
String retreivedMsg = getMessages.readUTF();
System.out.println("Message got from MQ: "+retreivedMsg);
} catch (MQException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
System.out.println("Processing Main...");
MQClientTest clientTest = new MQClientTest();
//initialize MQ.
clientTest.init();
//put and retreive message from MQ.
clientTest.putAndGetMessage();
System.out.println("Done!");
}
}
我試圖讀取命令行隊列中的消息,
./amqsget CSBTS.DEAL CSBTS.QUEUE.MANAGER
我無法弄清楚是什麼問題,它是與連接或通道。 P.S我的頻道身份驗證已禁用。
什麼是你從Java命令得到的輸出?我假設這不是您發佈的第一組輸出結果? – ipsi
1.請發佈運行程序時得到的異常堆棧跟蹤。我們需要知道MQ原因碼。 2.嘗試獲取您要連接的隊列管理器的AMQERR01.log,爲什麼連接終止的關鍵信息位可能在那裏。如果根本沒有關於連接的信息,那麼也許你使用的是錯誤的端口並且根本不連接到MQ。 3.嘗試使用MQ示例連接到隊列管理器,運行amqsput(samples/bin目錄中的一個),看看會發生什麼。 –