我们可以将平面文件发送到 IBM MQ 还是必须创建平面文件的字符串表示形式,以便它可以作为消息发送

can we send a flat file to IBM MQ or we have to create a string representation of the flat file so that it can be send as a message

我没有可以直接转换为字符串的平面文件。相反,我有一个 Java 对象,我需要将其作为平面文件发送到 MQ。

您可以在对象上使用 ToString 方法,或转换为 XML 或 JSON,这将序列化。

因此,例如,如果您使用 JSON,您的接收应用程序可以将扁平化的字符串反序列化为 JSON,然后是适当的 Java 对象

发送应用程序 -

import org.json.simple.parser.JSONParser;
import org.json.simple.JSONObject;


JSONObject obj = new JSONObject();
obj.put("xxx", yourJavaObject.somepropertyormethod);
obj.put("yyy", yourJavaObject.someotherpropertyormethod);

String msgAsAString = obj.toString();

您可以使用IBM MQ with JMS

有以下选项,您可以使用这些选项将您的 java class 数据发送到 MQ 队列中。

TextMessage - can send any kind of text data, i.e. you can serialize your java object to XML using JAXB (or JAX-WS in case of SOAP), or JSON using something like GSON, Jackson、JSONP(在 REST 等情况下为 Resteasy、Jersey)甚至 CSV

ObjectMessage - can send java serializable objects, please note - this is risky

BytesMessage - can send any kind of data (including any kind of text format). I.e. you can serialize your java objects into some binary format like Google Protocol Buffers 或一些 ASN.1 等