Hi Michael,
I am kinda lost with my code.I am trying to get msgs off a queue like I mentioned in my last post but I need to write these msgs into a text file as they come as there can be a lot of msgs on the queue for which I do a MqQ.Get() till all the messages are taken off the queue.This code gets fired again when msgs come onto the queue.Now I am attaching part of my code.Please help me with how to append to the text file after every MQ read and where do I put that code in.
Thanks,
Ann
********************************************************
public class MQGet
{
public static void main(
String[] args)
{
MQQueueManager MQQueueManager;
boolean forever = true;
try
{
MQQueueManager qMgr = new MQQueueManager(mqManager);
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
MQQueue mqQ = qMgr.accessQueue(mqQname, openOptions);
MQMessage retrievedMessage = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_FAIL_IF_QUIESCING
| MQC.MQGMO_NO_SYNCPOINT | MQC.MQGMO_ACCEPT_TRUNCATED_MSG;
gmo.waitInterval = 10000;
while (forever)
{
String outString = "";
int msgLen = 0;
retrievedMessage.messageId = MQC.MQMI_NONE;
retrievedMessage.correlationId = MQC.MQCI_NONE;
mqQ.get(retrievedMessage, gmo);
msgLen = retrievedMessage.getMessageLength();
outString = retrievedMessage.readString(msgLen);
System.out.println(msgLen);
if (retrievedMessage.getMessageLength() != 0)
{
String f0 = outString.substring(0,8);
String f1 = outString.substring(8,14);
String f14 = outString.substring(67,(msgLen+1));
System.out.println(f14);
}
else
{
System.out.println(" No Messages available on Queue ");
}
class OpenSundayTextFile
{
FileWriter fw;
public OpenSundayTextFile() throws IOException
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
Calendar cal = Calendar.getInstance();
if(cal.get(Calendar.DAY_OF_WEEK) == 1)cal.add(Calendar.DATE,-7);
cal.add(Calendar.DATE,-cal.get(Calendar.DAY_OF_WEEK)+2);
String fileName = sdf.format(cal.getTime()) + ".txt";
fw = new FileWriter(fileName,true);
doSomething();
goodBye();
}
public void doSomething() throws IOException
{
fw.write("hello world\r\n");
}
public void goodBye() throws IOException
{
fw.close();
System.exit(0);
}
//This line gives me an error : syntax error on new//
new OpenSundayTextFile();
}
}
mqQ.close();
qMgr.disconnect();
}