Solved

Checking for duplicate jms Textmessages in a folder

Posted on 2013-11-06
3
131 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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
spring jars download 1 52
printf performancy 11 84
Tomcat 9 + java 8 error while trying to deploy a war file 2 689
Html split(text) 2 26
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

735 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