简体   繁体   中英

Reading xml messages from ibm mq

I am trying to retrieve some XML messages as a readable string straight from IBM MQ, AND render them on a UI.

I used the following code and I get the error. GET Exception: com.IBM.mq.MQException: MQJE001: Completion Code '1', Reason '2110'.

What changes could I possibly make to get the messages back as a string? However, when the messages are of the format MQSTR they are rendered on the UI.

        MQQueueManager _queueManager = null;
        int port = inputPort;
        String hostname = host;
        String channel = chanel;
        String qManager = queuemanager;
        String inputQName = queuename;

        MQEnvironment.hostname = hostname;
        MQEnvironment.channel = channel;
        MQEnvironment.port = port;

        _queueManager = new MQQueueManager(qManager);


        int openOptions = MQC.MQOO_INQUIRE + MQC.MQOO_FAIL_IF_QUIESCING +  MQC.MQOO_BROWSE;


        MQQueue queue = _queueManager.accessQueue( inputQName,
                openOptions,
                null, // default q manager
                null, // no dynamic q name
                null ); // no alternate user id

        System.out.println("MQRead is now connected.\n");
        int depth = queue.getCurrentDepth();
        System.out.println("Current depth: " + depth + "\n");

        if (depth == 0)
        {
            System.out.println("Depth is zero");
        }

        MQGetMessageOptions getOptions = new MQGetMessageOptions();
        getOptions.options = MQC.MQGMO_NO_WAIT + MQC.MQGMO_FAIL_IF_QUIESCING + MQC.MQGMO_CONVERT + MQC.MQGMO_BROWSE_NEXT;

        ArrayList<MessageDTO> myMessages = new ArrayList<>();

        while(true)
        {
            MQMessage message = new MQMessage();


            try
            {
                queue.get(message, getOptions);
                byte[] b = new byte[message.getMessageLength()];
                message.readFully(b);


                System.out.println (new MQHeaderList (message, false));

                String newMessage =  new String(b);
                MessageDTO newMsg = new MessageDTO();
                newMsg.setMessage(newMessage);
                Random rand = new Random();
                newMsg.setMessageNumber(rand.nextInt());


                myMessages.add(newMsg);


                model.addAttribute("myMessages", myMessages);
                System.out.println(myMessages);
                message.clearMessage();
            }
            catch (IOException e)
            {
                System.out.println("IOException during GET: " + e.getMessage());
                break;
            }
            catch (MQException e)
            {
                if (e.completionCode == 2 && e.reasonCode == MQException.MQRC_NO_MSG_AVAILABLE) {
                    if (depth > 0)
                    {
                        System.out.println("All messages read.");
                    }
                }
                else
                {
                    System.out.println("GET Exception: " + e);
                }
                break;
            } catch (MQDataException e) {
                e.printStackTrace();
            }


        }
        queue.close();
        _queueManager.disconnect();
    }

}```

我希望有一天这对某人有所帮助,但问题是由格式错误引起的,我最终使用了 RFHUtil 并将消息格式更改为 MQSTR,然后我根据需要取回了我的消息。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM