Author |
Message
|
invisiblewoman |
Posted: Wed Jan 09, 2008 8:02 pm Post subject: How to write messages to a file when MQ is not available? |
|
|
Newbie
Joined: 09 Jan 2008 Posts: 4
|
Hi,
I writing an application which write messages to the MQ, when the MQ is not available, it throw errors but what I want to do is when MQ is not available buffer up the messages and write it to a file and when MQ become available, get the message s from the file and write it back to MQ. I'm new MQ java so can anyone help me or provide me with sample code on how to do this? |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Jan 10, 2008 4:50 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
I'm confused.
Do you not know how to write to a file from Java?
Do you not know how to write a program that does B only if A doesn't work?
Or do you not know how to tell that MQ is "unavailable"? I'll give you a hint here, this is an exceptional condition that MQ is "unavailable".
Are you sure that your program is actually supposed to continue processing if MQ is "not available"? What do your requirements tell you to do in this case? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
Vitor |
Posted: Thu Jan 10, 2008 4:51 am Post subject: Re: How to write messages to a file when MQ is not available |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
invisiblewoman wrote: |
what I want to do is when MQ is not available buffer up the messages and write it to a file and when MQ become available, get the message s from the file and write it back to MQ. |
How would you handle the same situation with other software, e.g. writing rows to a database when the database is not available? The design solution would be almost identical.
IMHO it's a bad requirement - if a piece of the software stack is unavailable (MQ, database, etc) then the application should highlight the fact by not working in the traditional way! I mean, what would a Java app do if an application server was not working? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
invisiblewoman |
Posted: Thu Jan 10, 2008 3:24 pm Post subject: |
|
|
Newbie
Joined: 09 Jan 2008 Posts: 4
|
I'm writing an API that allow operator access data to be logged. The log facility must records at least the following details: Date/Time of the event, relevant users or process, event description etc... and the data format for this is a set of String characters separated by ~. The access log data then need to write to MQ. With the current design of this API, when MQ is not available throw an error exception but however by doing this way none of the access log data can be logged until MQ become available.
So what I come up with to handle temporary MQ outages is when MQ is not available, buffer up the log messages and write it to a file, when MQ is available, get the log messages from a file and put it to MQ, Delete the log messages from the file. Can anyone be able to help me with this part, I'm quite new to Java, so a sample code would be nice.
Thanks
Thanks |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Jan 10, 2008 4:21 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
So.
The question is - what do you need sample code for?
Writing to MQ?
Writing to a File?
Detecting an Exception when Writing to MQ?
Detecting an Exception when Writing to a File?
Reading from a File? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
invisiblewoman |
Posted: Thu Jan 10, 2008 4:31 pm Post subject: |
|
|
Newbie
Joined: 09 Jan 2008 Posts: 4
|
Hi,
I need the sample code for:
Detecting an Exception when Writing to MQ and when there is an exception buffer up all the log messages that try to write to MQ then Writing to a File, Detecting an Exception when Writing to a File, When MQ become available Reading from a File and Writing back to MQ and finally Deleting messages from a File. |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Jan 10, 2008 4:46 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
So, you really don't want sample code.
You want a solution.
If you break the problem out into the steps that I've asked about, and you do some searches for sample code for those various pieces...
You will a) learn something , b) solve your problem yourself , rather than asking for free help from random strangers on the internet.  _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
invisiblewoman |
Posted: Thu Jan 10, 2008 5:32 pm Post subject: |
|
|
Newbie
Joined: 09 Jan 2008 Posts: 4
|
I'm not asking for the whole solution of the problem, Since I'm new to Java, what I need is a rough design of the solution, e.g what classes do I need, what methods are there for each classes, probably a simple java sudo code of the solution. |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Jan 10, 2008 8:53 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
So check out JMSException, java.io and java.nio.
http://java.sun.com has the API docs and some tutorials about it.
Happy reading  _________________ MQ & Broker admin |
|
Back to top |
|
 |
|