我想从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目录中的一个),看看会发生什么。 –