Reputation: 33
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();
}
}```
Upvotes: 1
Views: 787
Reputation: 33
I hope this helps someone one day, but the issue was caused by a format error, I ended up using the RFHUtil and changed the message format to to MQSTR and I got my messages back as desired.
Upvotes: 2