【问题标题】:Send and Receive XML formatted text to IBM WebSphere MQ using XMS使用 XMS 向 IBM WebSphere MQ 发送和接收 XML 格式的文本
【发布时间】:2015-12-19 00:41:28
【问题描述】:

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

代码:

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 的数据?

响应如下:

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
...

【问题讨论】:

    标签: .net xml ibm-mq xms


    【解决方案1】:

    您的应用程序正在以jms_bytes 类型的消息形式获取消息。由于 XML 基本上是文本,您可以使用 ITextMessage 消息类型来发送和接收 XML 有效负载。更改您的生产者应用程序以发送ITextMessage 类型的消息,并更改您的应用程序以接收相同的消息类型。示例 sn-p 在这里。

    制作人:

       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;
    

    【讨论】:

    • 嗨,Shashi,我不确定你是否见过this question,但由于你是唯一一个拥有真实信息的人,所以我希望你能看到这个问题。
    猜你喜欢
    • 2018-09-12
    • 2011-11-04
    • 2016-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-25
    • 1970-01-01
    相关资源
    最近更新 更多