Solved

Checking for duplicate jms Textmessages in a folder

Posted on 2013-11-06
3
128 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java - Why doesn't this JFrame work 3 58
map related example 6 47
Java exception bubble up 2 17
Convert from a json string array to a Java object 3 28
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

815 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now