Hi, I am trying to write a program in Java using native MQ API’s and the program is supposed to get messages off a queue and format the message we get.I have been trying to find on the net how to do that,as I want to format the strings as I receive them from the queue.
Like the first 8 characters I get from the MQ Queue,I want to put certain delimiters around them and then around the next 6 chars,different delimiters and so on for about 61 chars from the queue.I tried doing retrivedMessage.readString(8) but that is only for the first 8,how do I get to the next 6 and so on also I tried retrivedMessage.readUTF() but that retrieves the whole message from the queue.whereas I want to format the message into different sets with delimiters to differentiate each of them.my sample code is below:
mqQ.get ( retrievedMessage,gmo);
msgText = retrievedMessage.readUTF( );
if ( retrievedMessage.getMessageLength() != 0){
String fl1 = retrievedMessage.readString(8);
fl1 = “DT” + fl1 + “DT”;
//Substring doesn’t work in MQ,this next line throws an error.
String fl2 = retrievedMessage.substring(8,16);
fl2 = “NT” + fl2 + “NT”;
}
else
System.out.println(" No data Available ");
Also I have another issue,I want to get these delimited messages like the fl1,fl2 etc and put them into a text file and have the messages appended to the text file everyday without opening a new text file.I need to open a new text file/week only.IS that possible? Any suggestions…
Thanks in advance.
Ann
Subject: String Handling in MQ-Java
What is the data type for the retrievedMessage. If you are getting error at substring, then it probably doesnt have the method. It would be helpful if you post your entire code.
however, I would also try:
retrievedMessage.readString(16).substring(8,16);
Subject: RE: String Handling in MQ-Java
the retrievedMessage is the message we get off the Queue.MQMessage retrievedMessage = new MQMessage ( );
while ( forever ) {
mqQ.get ( retrievedMessage,gmo);
msgText = retrievedMessage.readUTF( );
if ( retrievedMessage.getMessageLength() != 0){
String fl1 = retrievedMessage.readString(8);
fl1 = “DT” + fl1 + “DT”;
String fl2 = retrievedMessage.readString(8);
}
else
System.out.println(" No data Available ");
So if I do
retrievedMessage.readString(61).substring(8,61);
This will read all the messages and then take first 8,what about the next 8 and the next 4 and so on…?
Thanks for your suggestion
Subject: RE: String Handling in MQ-Java
I am thinking this is just String handling.
I dont know MQS and I couldnt find the API for it. What you want to do is extract the entire String from the retrievedMessage and do substring to get the values you want. So in the above example you could do:
String fl1 = retrievedMessage.readString(61);
fl1.substring(0,7); // should give you first 8
f11.substring(8,4); // should give you need 4
fl1.substring(12,8); // next 8
so on and so forth. look at the string api to work with strings.
Thanks
Subject: RE: String Handling in MQ-Java
Besides MQ does’nt like the substring command.It balks at that command…