如何将消息运行到MQ服务器并获取输出消息

时间:2018-01-22 19:46:11

标签: java jms message-queue ibm-mq

我想向MQ服务器发送消息并接收输出消息。例如,消息是“pwd”,我收到的消息应该是目录路径,例如“/ usr / home”。但是,我的receiveMessage返回与我发送的“pwd”完全相同的消息。有没有办法让我的receiveMessage可以返回目录补丁?

connectionFactory.setCCDTURL(ccdt.tab);
connectionFactory_.setQueueManager(QUEUE_MANAGER_NAME);
MQQueueConnection connection = (MQQueueConnection)connectionFactory.createQueueConnection();
connection.start();
MQQueue mqQueue= new MQQueue();
MQQueueSender sender =  (MQQueueSender) session.createSender(mqQueue);
JMSTextMessage message = (JMSTextMessage)session.createTextMessage("pwd");
message.setJMSCorrelationID(correlationId);
sender.send(message);
MQQueueSession session =(MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
String selector = "JMSCorrelationID = '" + correlationId + "'";
MQQueueReceiver receiver = (MQQueueReceiver) session.createReceiver(mqQueue, selector);
TextMessage receiveMessage = (TextMessage) receiver.receive(500);
receiver.close();
System.out.println("Received Message: " + receiveMessage );

由于

1 个答案:

答案 0 :(得分:2)

您提供的示例只是将带有文本pwd的消息放入队列,然后从队列中获取相同的消息。您看到的结果是预期的结果。

如果您希望能够将消息发送到将执行该消息内容的队列并且该命令的输出返回给您,则需要编写程序来执行该功能。