我需要构建一个java独立应用程序,它能够向MQSeries发送消息,指定回复队列和回复MQMgr。 我能够使用SimpleP2P示例中的代码发送消息,但无法指定回复队列并回复MQMgr
public static void main(String[] args) {
try {
MQQueueConnectionFactory cf = new MQQueueConnectionFactory();
cf.setHostName("xyz.com");
cf.setPort(141600);
cf.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);
cf.setQueueManager("QMG");
cf.setChannel("CHANNEL");
MQQueueSession session = (MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
MQQueue queue = (MQQueue) session.createQueue("queue:///A.QUEUE");
MQQueueSender sender = (MQQueueSender) session.createSender(queue);
long uniqueNumber = System.currentTimeMillis() % 1000;
String fileText = convertXMLFileToString("test.xml");
System.out.println("fileText " + fileText);
JMSTextMessage message = (JMSTextMessage) session.createTextMessage(fileText);
connection.start();
System.out.println("before Sent message:\\n" + message);
sender.send(message);
System.out.println("Sent message:\\n" + message);
sender.close();
session.close();
connection.close();
System.out.println("\\nSUCCESS\\n");
} catch (JMSException jmsex) {
System.out.println(jmsex);
System.out.println("\\nFAILURE\\n");
} catch (Exception ex) {
System.out.println(ex);
System.out.println("\\nFAILURE\\n");
}
}
答案 0 :(得分:2)
试试这个: -
MQQueue replyToQ = new MQQueue(QMgrName, ReplyQueue);
Destination replyTo = (Destination) replyToQ;
message.setJMSReplyTo(replyTo);
答案 1 :(得分:0)
public void postMessageToDatastage(String msg,String queueName,String batchID){
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.");
//System.out.println("Queue is closing...");
defaultLocalQueue.close();
// for asynchornus communtication...
//MQAsyncStatus asyncStatus = qManager.getAsyncStatus();
qManager.disconnect();
} catch (MQException e) {
e.printStackTrace();
}
}
答案 2 :(得分:-1)
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();
}
}