Solved

Checking for duplicate jms Textmessages in a folder

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

759 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

21 Experts available now in Live!

Get 1:1 Help Now