使用XMS将XML格式的文本发送和接收到IBM WebSphere MQ [英] Send and Receive XML formatted text to IBM WebSphere MQ using XMS

查看:403
本文介绍了使用XMS将XML格式的文本发送和接收到IBM WebSphere MQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有IBM WebSphere MQ 7.5.我们已经设置了队列管理器和队列.我们想要使用XMS for .net客户端应用程序从队列中读取和写入XML格式的文本.我尝试使用下面的代码,但我不知道如何读取该数据.

We have IBM WebSphere MQ 7.5. We have setup Queue Manager and Queues. We want to read and write XML formatted text from the queues using XMS for .net client application. I tried below code but I don't know how to read that data.

代码:

try
         {
                var factoryfactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
                var connectionfactory = factoryfactory.CreateConnectionFactory();
                connectionfactory.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, queueManager);
                connectionfactory.SetStringProperty(XMSC.WMQ_HOST_NAME, hostIP);
                connectionfactory.SetIntProperty(XMSC.WMQ_PORT, port);
                connectionfactory.SetStringProperty(XMSC.WMQ_CHANNEL, channel);
                connectionfactory.SetIntProperty(XMSC.WMQ_BROKER_VERSION, XMSC.WMQ_BROKER_V2);
                connectionfactory.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT_UNMANAGED);
                using (IConnection conn = connectionfactory.CreateConnection())
                {
                    using (ISession session = conn.CreateSession(false, AcknowledgeMode.AutoAcknowledge))
                    {
                        using (IDestination dest = session.CreateQueue(string.Format("queue://{0}", queueName))) // Create a queue
                        {
                            using (IMessageConsumer consumer = session.CreateConsumer(dest))
                            {
                                conn.Start();
                                IMessage recvMsg = null;
                                recvMsg = consumer.Receive();
                                if (recvMsg != null)
                                    return recvMsg;

                            }
                        }
                    }
                }
            }
            catch(XMSException ex)
            {

            }

recvMsg正在JMS中返回数据.是否有任何有效的代码可以读取字符串/XML数据?

recvMsg is returning data in JMS. Any working code to read data for string/XML?

响应如下:

JMSMessage class: jms_bytes
  JMSType:          
  JMSDeliveryMode:  NonPersistent
  JMSExpiration:    0
  JMSPriority:      0
  JMSMessageID:     ID:414d512043524d44514d312020202020118cff552000dd10
  JMSTimestamp:     1442899405610
  JMSCorrelationID: 
  JMSDestination:   
  JMSReplyTo:       
  JMSRedelivered:   False
    JMS_IBM_Character_Set: 850
    JMS_IBM_Encoding: 546
    JMS_IBM_Format:         
    JMS_IBM_MsgType: 8
    JMS_IBM_PutApplType: 11
    JMS_IBM_PutDate: 20150922
    JMS_IBM_PutTime: 05232561
    JMSXAppID: staller\MQ\Tools\rfhutil.exe
    JMSXDeliveryCount: 1
    JMSXUserID:       
3c3f786d6c2076657273696f6e3d22312e302220656e636f64696e673d225554462d38223f3e0d0a
3c212d2d53616d706c6520584d4c2066696c652067656e65726174656420627920584d4c53707920
76323031322028687474703a2f2f7777772e616c746f76612e636f6d292d2d3e0d0a3c6d74613a4d
5441546f45534254726176656c486973746f7279526571756573744d657373616765207873693a73
6368656d614c6f636174696f6e3d22687474703a2f2f6d74612e626f726465722e676f762e61752f
6d74612f76312e30204d5441546f4553424d657373616765732e7873642220786d6c6e733a636f6d
6d6f6e3d22687474703a2f2f6573622e626f726465722e676f762e61752f636f6d6d6f6e2f76312e
302220786d6c6e733a74683d22687474703a2f2f6d74612e626f726465722e676f762e61752f6d74
612f74726176656c686973746f72792f76312e302220786d6c6e733a6d74613d22687474703a2f2f
6d74612e626f726465722e676f762e61752f6d74612f76312e302220786d6c6e733a7873693d2268
...

推荐答案

您的应用程序收到的消息为jms_bytes类型的消息.由于XML基本上是文本,因此您可以使用ITextMessage消息类型来发送和接收XML有效负载.更改您的生产者应用程序以发送ITextMessage类型的消息,并更改您的应用程序以接收相同的消息类型.示例代码段在这里.

Your application is getting the message as jms_bytes type message. As XML is basically text you can use ITextMessage message type for sending and receiving XML payload. Change your producer application to send messages of type ITextMessage and change your application to receive the same message type. Sample snippet is here.

制作人:

   IMessageProducer producer;
   ITextMessage textMessage;

   // create session, producer
   ....

   textMessage = sessionWMQ.CreateTextMessage();
   textMessage.Text = XmlPayload;
   producer.Send(textMessage);

消费者:

IMessageConsumer consumer;
ITextMessage textMessage;

// create session and consumer

....
// Receive text message
textMessage = (ITextMessage)consumer.Receive(3000); // Wait for 3 seconds to receive message
String XmlPayload = textMessage.Text;

这篇关于使用XMS将XML格式的文本发送和接收到IBM WebSphere MQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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