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);
Capitalware Inc.
Original Message:
Sent: Thu May 25, 2023 04:39 AM
From: Francois Brandelik
Subject: IBM MQ : Not able read messages using java code which are added from rhfutil app
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
Original Message:
Sent: Wed May 24, 2023 07:36 AM
From: Ranjitha YM
Subject: IBM MQ : Not able read messages using java code which are added from rhfutil app
After adding the message format, we are able to read messages inserted from RFHUtil Thank You
------------------------------
Ranjitha YM
Original Message:
Sent: Wed May 24, 2023 06:41 AM
From: JUKKA VÄHÄTÖRMÄ
Subject: IBM MQ : Not able read messages using java code which are added from rhfutil app
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Ä
Original Message:
Sent: Wed May 24, 2023 02:37 AM
From: JUKKA VÄHÄTÖRMÄ
Subject: IBM MQ : Not able read messages using java code which are added from rhfutil app
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Ä
Original Message:
Sent: Tue May 23, 2023 05:57 AM
From: Ranjitha YM
Subject: IBM MQ : Not able read messages using java code which are added from rhfutil app
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
------------------------------