I have a requirement to write a message to the MQ and if it fails due to any reason, I have to write that message into the text file. I have to keep on adding the messages to this text file until the messages starts flowing to MQ again. Once the messages starts flowing, I have to check the text file and load all the pending messages from it and delete them from the text file.
try{
sender.send(mqMessage); where mqMessage is of JMSBytesMessage
}
now if the sending of message failed, I have to write this into a text file
catch(JMSException mqe)
{
mqe.printStackTrace();
try{
String msgString= mqMessage.toString();
FileWriter fstream = new FileWriter(filePath);
BufferedWriter out = new BufferedWriter(fstream);
out.append(msgString);
out.close();
}
catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
Once the messages starts flowing I have to read the textfile and load all these message
inside the 1st try block after sender.send(mqMessage)
I am reading the complete file content and after splitting the messages and storing them to a string how can I typecast that string into the JMSBytesMessage
type in order to put them on MQ.
I have mentioned the complete scenario here because I wanted to tell that though I wanted to convert JMSBytesMessage
to string and then again String to JMSBytesMessage
but I dont want to change the actual content while doing both the type-castings.
Thanks