未在Websphere MQ临时队列上收到回复

时间:2014-04-28 10:34:09

标签: java jms ibm-mq

我正在使用发送/接收机制到Websphere MQ系统。

我以文本格式发送的xml应该收到回复,但我没有收到回复。

我知道xml正在发送"好的,因为"事情正在发生"在目标系统中 - 只是我没有收到回复。回复对我很重要,因为如果某些内容失败,它可能会包含错误消息。

所以,我没有收到回复的原因 - 我不确定我的代码或Websphere MQ配置是否有问题。

我的代码上的任何指针或我应该要求Websphere MQ管理员查看的内容都非常感谢!!

一个小的自包含示例来演示接收不会发生如下:

public class CustomQueueConnection {
    private MQQueueConnectionFactory connectionFactory;
    private MQQueueConnection connection;

    private void runTest() throws JMSException {
        connect();
        MQQueueSession session = (MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        MQQueue queue = (MQQueue) session.createQueue("queue:///REQ_SNAPSHOT.HT");
        MQQueueSender sender = (MQQueueSender) session.createSender(queue);
        TemporaryQueue temporaryQueue = session.createTemporaryQueue();
        MQQueueReceiver receiver = (MQQueueReceiver) session.createReceiver(temporaryQueue);

        TextMessage message = session.createTextMessage(
                "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
                // my well constructed xml goes here...
        );

        message.setJMSReplyTo(temporaryQueue);
        sender.send(message);
        System.out.println("Sent: " + message);
        JMSMessage receivedMessage = (JMSMessage) receiver.receive(10000);
        System.out.println("Received: " + receivedMessage);
    }

    public boolean connect() {
        boolean connected = false;
        try {
            connectionFactory = new MQQueueConnectionFactory();
            connectionFactory.setCCSID(819);
            connectionFactory.setPort(1417);
            connectionFactory.setHostName("1.2.3.4");
            connectionFactory.setQueueManager("GATE1");
            connectionFactory.setChannel("CLIENTS.CHANNEL");
            connectionFactory.setTemporaryModel("GATEWAY_MODEL_QUEUE");
            connectionFactory.setTempQPrefix("MACHINE.USER_NAME.*");
            connectionFactory.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);

            connection = (MQQueueConnection) connectionFactory.createQueueConnection();
            connected = true;
        } catch (JMSException e) {
            connected = false;
        }
        return connected;
    }

    public static void main(String[] args) throws JMSException {
        new CustomQueueConnection().runTest();
    }

}

这是输出:

Sent:
        JMS Message class: jms_text
        JMSType:         null
        JMSDeliveryMode: 2
        JMSExpiration:   0
        JMSPriority:     4
        JMSMessageID:    ID:414d512050314f47415445312020202053599032201b4d05
        JMSTimestamp:    1398680728618
        JMSCorrelationID:null
        JMSDestination:  queue:///REQ_SNAPSHOT.HT
        JMSReplyTo:      queue://GATE1/MACHINE.USER_NAME.53599032201B4E04?persistence=1
        JMSRedelivered:  false
        JMS_IBM_PutDate:20140428
        JMSXAppID:WebSphere MQ Client for Java
        JMS_IBM_PutApplType:28
        JMSXUserID:aomis
        JMS_IBM_PutTime:10252859
        JMSXDeliveryCount:0
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<esb:esbMessage xmlns:esb="http://ESBServices
        Another 557 character(s) omitted
        Received: null

(注意:收到:null)

编辑:Websphere MQ版本为6.0.25

2 个答案:

答案 0 :(得分:0)

您的代码看起来不错,消息发送成功。我希望你检查一下:

1)是否有运行的应用程序从REQ_SNAPSHOT.HT队列接收消息?

2)假设有一个应用程序在运行和接收消息,该应用程序是否已成功处理传入的XML消息?它抛出任何例外吗?

3)如果传入的消息处理成功,它是否回复了正确的回复队列&#34; MACHINE.USER_NAME.53599032201B4E04&#34;?在回复邮件时检查它是否遇到任何问题。

答案 1 :(得分:0)

解决方案是双重的。

首先,连接需要在创建后立即启动

        connect();
        connection.start();

其次,消息需要与DeliveryMode.NON_PERSISTENT一起发送。

相关问题