Solved

Checking for duplicate jms Textmessages in a folder

Posted on 2013-11-06
3
130 Views
Last Modified: 2013-11-07
Hi guys
I have a scenario where I have a folder c:\messages.
I am listening a queue for text messages (jms.Textmessage)
I have two requirments
To save the Textmessage in the messages folder. The Textmessage file name should be the messageid.( messageid is unique for each Textmessage).

If the Textmessage file already exists in the messages folder then it should not be saved.

Any idea how I can go about doing this? Any help with code is greatly appreciated.
Thanks.
0
Comment
Question by:royjayd
  • 2
3 Comments
 
LVL 35

Expert Comment

by:mccarl
ID: 39629315
Have you already got some code that we can start from?
0
 

Author Comment

by:royjayd
ID: 39629344
Yeah,


// my listener which is listening for Textmessages on the Queue.
Public class Mylistener{

Public void onMessage(Jaxax.jms.Message message){
if (message instanceOf Jaxax.jms.TextMessage){
String messageId = message.getJmsMessageId();

// here I want to check if a Textmessage file with filename as messageId already exists in the
// C:\messages folder. If it doesn't exist then add the Textmessage to the messages folder.
}
}
}

Thx.
0
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 39629375
Ok, so the code that you would need to insert is simply something like this...
String filename = "C:\\messages\\" + messageId;             // Customize this further if you want all the files to have a file extension, etc  (eg. you could add        + ".txt"      to the end of that to make them all text files)
File file = new File(fileName);
if (!file.exists()) {
    FileOutputStream os = new FileOutputStream(file);
    os.write(((TextMessage) message).getText().getBytes());
    os.close();
}

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Arrays.asList  VS  ArrayList 4 71
xampp tool 12 56
CSV file parsing thru Java 13 34
Is Applet the way to go for my drag and drop system? 8 25
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question