我在 Windows 上为 WebSphere MQ 7 编写了一个 API EXIT,当我从命令行放入队列或从队列中获取一条简单消息时,例如:“amqsput”或“amqsget”,我会得到一些日志文件,其中包含时间、消息数据、队列名称等信息。
这就是我对用 Java 编写的测试程序的期望,但是当我使用下面的代码时:
MQMessage msg = new MQMessage();
msg.writeUTF("Hello, World!");
MQPutMessageOptions pmo = new MQPutMessageOptions();
queue.put(消息、pmo);
我得到了空白日志文件。然后我使用下面的代码:
MQMessage msg = new MQMessage();
msg.writeString("Hello, World!");
MQPutMessageOptions pmo = new MQPutMessageOptions();
queue.put(消息、pmo);
然后我在日志文件中看到了熟悉的数据。
我打开MQ资源管理器,在“消息浏览器”中看到两条消息:
你好,世界!
%你好,世界!
我完全迷失了,这个“%”是从哪里来的?由于编码问题,我的 api 导出没有记录 put 操作?
如有任何建议,我们将不胜感激! 谢谢!
最佳答案
我很确定我记得在某处读过 writeUTF()
输出长度信息以及字符串。
啊,是的,就是这里:
来自IBM自己的doco在 WriteUTF()
上:
This method takes an ActiveX string and writes it into the message data buffer at the current position in UTF format. The data written consists of a 2-byte length followed by the character data. DataOffset is incremented by the length of the string if the method succeeds.
(我的斜体)。正如您已经发现的,WriteString()
是一种没有长度的方法。
关于ibm-mq - 当我通过基于 Java 的客户端程序发送消息时,为什么我的 WebSphere MQ(在 Windows 上)API Exit 没有记录任何内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3457097/