IBMMQ:Message 以二进制形式发布,但以字符串形式发送

IBMMQ:Message is published as Binary but sending as String

当我检查 ibm 控制台上的队列时,我正在尝试使用 java.The 消息发送 successful.But 向 ibmmq 发布一条简单消息。消息显示为

但我期待的是简单的字符串。

这是我的 code.when 我正在尝试转换 我收到以下消息 jms_bytes 类型的消息不能将其正文分配给 java.lang.String

import com.ibm.mq.*;
import com.ibm.mq.constants.MQConstants;
import com.ibm.mq.jms.MQQueueConnectionFactory;
import com.ibm.msg.client.jms.JmsFactoryFactory;
import com.ibm.msg.client.wmq.WMQConstants;

import javax.jms.*;
import java.io.IOException;
import java.util.Hashtable;

public class PublisherTest
{
    static private String CHANNEL = "anychannel";
    static private int    PORT = 1414;
    static private String HOST = localhost;
    static private String QMANAGER = "QM1";
    static private String QUEUE = "queue.test";
    static private String USER = USER;
    static private Hashtable<String, Object> props =
            new Hashtable<String, Object>();
    static MQQueueManager qMgr = null;

    static private void putMsgOnQueue(String message) {
        // Disabling IBM cipher suite mapping due to
        // using Oracle Java and not IBM Java
        System.setProperty("com.ibm.mq.cfg.useIBMCipherMappings", "false");
        // Enabling SSL debug to view the communication
        System.setProperty("javax.net.debug", "ssl:handshake");

        props.put(MQConstants.CHANNEL_PROPERTY, CHANNEL);
        props.put(MQConstants.PORT_PROPERTY, PORT);
        props.put(MQConstants.HOST_NAME_PROPERTY, HOST);
        props.put(MQConstants.USER_ID_PROPERTY, USER);
        props.put(MQConstants.PASSWORD_PROPERTY, PASSWORD);
        props.put(MQConstants.SSL_CIPHER_SUITE_PROPERTY, "TLS_RSA_WITH_AES_256_CBC_SHA256");


        try {

            qMgr = new MQQueueManager(QMANAGER, props);


            // MQOO_OUTPUT = Open the queue to put messages
            // MQOO_INPUT_AS_Q_DEF = Using queue-defined defaults
            int openOptions = MQConstants.MQOO_OUTPUT;


            // creating destination
            MQQueue queue = qMgr.accessQueue(QUEUE, openOptions);

            // specify the message options...
            MQPutMessageOptions pmo = new MQPutMessageOptions(); // Default


            // MQPMO_ASYNC_RESPONSE = MQPUT operation is completed without the
            // application waiting for the queue manager to complete the call
            // Using this option can improve messaging performance,
            // particularly for applications using client bindings.
            pmo.options = MQConstants.MQPMO_ASYNC_RESPONSE;

            // create message
            MQMessage mqMessage = new MQMessage();


            System.out.println("Writing message to queue: " + QUEUE);
            mqMessage.writeString(message.toString());

            // Put message on queue
            queue.put(mqMessage, pmo);

            // Close queue
            queue.close();

            // Get status
            MQAsyncStatus asyncStatus = qMgr.getAsyncStatus();

            // Print status code (0 = successful)
            System.out.println(asyncStatus.reasonCode);

        } catch (MQException e) {
            System.out.println("The connection to MQ could not be established." + e.getMessage());

        } catch (IOException e) {
            System.out.println("Error while writing message." +
                    e.getMessage());
        } finally {
            try {
                qMgr.disconnect();
            } catch (MQException e) {
                System.out.println("The connection could not be closed." +
                        e.getMessage());
            }
        }
    }


    public static void main(String[] args) {

         putMsgOnQueue("WELCOME");
    }
}

如有任何帮助,我们将不胜感激。

默认消息格式为MQFMT_NONE。这意味着消息体由字节组成。您的代码未设置消息格式。所以我的想法是 MQ 控制台将此类消息指示为二进制。

建议您将消息格式设置为字符串,运行。这会将消息格式设置为字符串。

        MQMessage mqMessage = new MQMessage();
        mqMessage.format = MQConstants.MQFMT_STRING;