MQ

 View Only
  • 1.  IBM MQ : Not able read messages using java code which are added from rhfutil app

    Posted Tue May 23, 2023 05:57 AM

    Team, 

    We are not able to read messages using Java code which is added from rhfutil app.

    In our Queue, we have 5 messages 4 are inserted from rfhutil and one from the java write operation 

    when we run read code, it reads only the message inserted using the java write operation, it's not reading messages inserted using rfhutil

    output of java code 




    Java Code 

    MQQueueManager manager;
    MQQueue queue = null;
    boolean getMore = true;
     
    Hashtable<String, Object> mqht = new Hashtable<>();
     
    mqht.put(CMQC.CHANNEL_PROPERTY,channel);
    mqht.put(CMQC.HOST_NAME_PROPERTY, host);
    mqht.put(CMQC.PORT_PROPERTY, new Integer(port));
    mqht.put(CMQC.USER_ID_PROPERTY, username);
    mqht.put(CMQC.PASSWORD_PROPERTY, password);
     
    manager=new MQQueueManager(queueManager, mqht);
     
    int openOptions = MQConstants.MQOO_BROWSE | MQConstants.MQOO_INPUT_EXCLUSIVE | MQConstants.MQOO_INQUIRE;        
    queue = manager.accessQueue("DEV.QUEUE.1",openOptions);
     
    MQGetMessageOptions gmo = new MQGetMessageOptions();
    gmo.options = MQConstants.MQGMO_WAIT + MQConstants.MQGMO_FAIL_IF_QUIESCING 
    + MQConstants.MQGMO_CONVERT + MQConstants.MQGMO_BROWSE_NEXT ;
     
    try {
     
    while(getMore)
    {
    MQMessage message = new MQMessage();
     
    queue.get(message, gmo);
    byte[] b = new byte[message.getMessageLength()];
    message.readFully(b);
    System.out.println(new String(b));
     
    }
     
    } catch (MQException e) {
    if (e.reasonCode == 2033)
                {
    System.out.println("No message available");
                }
     
    if ( (e.completionCode == CMQC.MQCC_FAILED) &&(e.reasonCode == CMQC.MQRC_NO_MSG_AVAILABLE) ) {
    }
    else
    {
    System.out.println("MQException: " + e.getLocalizedMessage());
    System.out.println("CC=" + e.completionCode + " : RC=" + e.reasonCode);
    getMore = false;
    }
     
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
     
     
    manager.disconnect();
    queue.close();
    }


    can you please help us to understand why we are not able to read rfhutil data ?





    ------------------------------
    Ranjitha YM
    ------------------------------


  • 2.  RE: IBM MQ : Not able read messages using java code which are added from rhfutil app

    Posted Wed May 24, 2023 02:37 AM

    Hi Ranjitha,

    You could try to set MQDM Message Format (on MQMD tab) before writing message to the queue.

    Most likely it should be 'MQSTR' but you could check what is Message Format value in the messages that are processed successfully (those written with java).



    ------------------------------
    JUKKA VÄHÄTÖRMÄ
    ------------------------------



  • 3.  RE: IBM MQ : Not able read messages using java code which are added from rhfutil app

    Posted Wed May 24, 2023 06:42 AM

    There is also JMS Message Type selection on the JMS tab. In your case I think it should be 'bytes'.



    ------------------------------
    JUKKA VÄHÄTÖRMÄ
    ------------------------------



  • 4.  RE: IBM MQ : Not able read messages using java code which are added from rhfutil app

    Posted Wed May 24, 2023 07:37 AM

    After adding the message format, we are able to read messages inserted from RFHUtil Thank You



    ------------------------------
    Ranjitha YM
    ------------------------------



  • 5.  RE: IBM MQ : Not able read messages using java code which are added from rhfutil app

    IBM Champion
    Posted Thu May 25, 2023 04:40 AM
    Edited by Francois Brandelik Thu May 25, 2023 04:43 AM

    Hi Ranjitha,
    You also have an error in your code 

    System.out.println(new String(b));

    This piece of code assumes that the byte array you retrieved is in the code page of the platform (java assumptions)
    This may or may not be so. The right way would be to read the message.ccsid (CodedCharSetID) value and assign it to the corresponding charset modifier so your piece of code should read

    System.out.println(new String(b, charset));


    Hope this helps



    ------------------------------
    Francois Brandelik
    ------------------------------



  • 6.  RE: IBM MQ : Not able read messages using java code which are added from rhfutil app

    IBM Champion
    Posted Thu May 25, 2023 01:50 PM

    Adding to what FB said, IBM added methods to the MQMessage class to handle character conversion. They are readStringOfByteLength and readStringOfCharLength. 

    What I typically do is:

    MQGetMessageOptions gmo = new MQGetMessageOptions();
    gmo.options = CMQC.MQGMO_NO_WAIT + CMQC.MQGMO_FAIL_IF_QUIESCING;
    MQMessage rcvMsg = new MQMessage();
    queue.get(rcvMsg, gmo);

    if (CMQC.MQFMT_STRING.equals(rcvMsg.format))
    {
       String sMsg = rcvMsg.readStringOfByteLength(rcvMsg.getMessageLength());
       System.out.println("Data: " + sMsg);
    }
    else
    {
       byte[] bMsg = new byte[rcvMsg.getMessageLength()];
       rcvMsg.readFully(bMsg);
       System.out.println("Data: " + new String(bMsg));
    }



    ------------------------------
    Roger Lacroix
    CTO
    Capitalware Inc.
    London ON Canada
    https://capitalware.com
    ------------------------------