如何使用TextMessage将XML文件发送到JMS队列? [英] How can I use TextMessage to send an XML file to the JMS Queue?

查看:358
本文介绍了如何使用TextMessage将XML文件发送到JMS队列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Oracle Docs说 -

The Oracle Docs say -


TextMessage对象用于发送包含java.lang.String的消息。它从Message接口继承>并添加一个文本消息体。
此消息类型可用于传输基于文本的消息,包括那些包含XML> content的消息。

A TextMessage object is used to send a message containing a java.lang.String. It inherits >from the Message interface and adds a text message body. This message type can be used to transport text-based messages, including those with XML >content.

这是怎么回事可能? XML的内容是否只能发送(通过将其转换为Object然后发送)? XML文件是否可以以任何方式真正放在队列中,然后在接收方读取?

How is this possible? Are the contents of the XML only send-able(by converting it into an Object and then sending it)? Can the XML File be really put on the Queue in any way and then be read on the receiver side?

推荐答案

请使用此您发送的对象必须是可序列化的

Please use this and object you send must be Serializable

class Master implements serializable
 {
   List<File> f=new ArrayList<File>();
  //getter and setter
 }

添加--xml文件尽可能多如你所愿

Add --xml files as many as you want

     Master eMaster = new Master();
    eMaster.setF();
    //add Files here 

    QueueSender queueSender = queueSession.createSender(queue1);
    ObjectMessage objMessage = queueSession.createObjectMessage();
    objMessage.setObject(eMaster);
    queueSender.send(objMessage);

接收方结束: -

        Master em =null;
        Message message = queueReceiver.receive(1);
        if (message instanceof ObjectMessage
                && ((ObjectMessage) message).getObject() instanceof Master) {
            em = (Master) ((ObjectMessage) message).getObject();
            //use this and get list of xml file and iterate and process xml file by 
            //below link
        }

此处的1 xml解析链接

2 xml解析链接到这里

这篇关于如何使用TextMessage将XML文件发送到JMS队列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆