0

因此,我向 WebSphere 发送了一条消息,并成功地将其放入队列中。但是,我在将其从另一个队列中取出时遇到了问题。但是当我使用该行向我发送消息时我注意到了这一点:

inputMessage.writeUTF(消息);消息是:

basket/argos/1001?authToken=fgTSdfs&trustToken=gdf43FsfSFefs33&apiKey=ahjd9234imnmdfnwi&sig=abcde&currency=GBP

它存储在一个 xml 文件中,它在消息的前面附加了一个“n”。谁能告诉我为什么?代码如下:

  MQQueueConnectionFactory cf = new MQQueueConnectionFactory();

    // Config
    cf.setHostName(hostname);
    cf.setPort(portNumber);
    cf.setQueueManager(queueManager);
    cf.setChannel(channel);

    //MQQueueConnection connection = (MQQueueConnection) cf.createQueueConnection();
    //MQQueueSession session = (MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    //MQQueue queue = (MQQueue) session.createQueue(inputQueue);
    //MQQueue queue = (MQQueue)session.
    //MQQueueSender sender =  (MQQueueSender) session.createSender(queue);
    //MQQueueReceiver receiver = (MQQueueReceiver) session.createReceiver(queue);    


    MQQueueManager qMgr = new MQQueueManager(queueManager);
    System.out.println("Queue manager created");

    int openOptions = MQC.MQOO_INPUT_AS_Q_DEF |  
    MQC.MQOO_OUTPUT ;  
    System.out.println("MQ Options created");

    MQQueue mqInputQueue =  
        qMgr.accessQueue(inputQueue,  
                openOptions);

    System.out.println("Queue created");

    MQMessage inputMessage = new MQMessage();
    inputMessage.writeUTF(message);
    System.out.println("message created and sent");

    MQPutMessageOptions pmo = new MQPutMessageOptions();  // accept the defaults,  
    // same as  
    // MQPMO_DEFAULT  
    // constant  
    System.out.println("Queue options created");

    // put the message on the queue  
    mqInputQueue.put(inputMessage,pmo);
    System.out.println("Message put on queue");
    mqInputQueue.close();  
4

1 回答 1

0

MQMessage 似乎派生自 DataInput 和 DataOutput。我猜 writeUTF 正在做与DataOutputStream.

您可以参考此答案寻求帮助为什么 DataOutputStream.writeUTF() 在开头添加额外的 2 个字节?

你有几个选择:

inputMessage.write(message.getBytes("UTF-8"));

或者可能

inputMessage.writeString(message);

于 2013-07-24T16:43:46.127 回答