Without knowing anything more something like this may work (rough code sketch):
Code:
public class MessageProcessor implements MessageListener {
/**
* Keeps a mapping of open file handles so we don't have to re-open it
* every time.
*/
private Map files = new HashMap();
/**
* The directory where files will be written to.
*/
private String parentDir;
/**
* Message processing method uses the JMS message to write data
* to a file.
*/
private void onMessage(Message m) {
/* IOException will have to be taken care of in this method */
String filename = null;
/* use Message to determine filename */
FileWriter fw = (FileWriter)files.get(filename);
/* If we don't already have this file open, open it and save it in the map */
if(fw == null) {
fw = new FileWriter(new File(parentDir, filename));
files.put(filename, fw);
}
/* use FileWriter and Message to write to file */
}
/**
* Release all file handles.
*/
public void destroy() {
/* do something with IOException below */
for(Map.Entry ent : files.entrySet()) {
FileWriter fw = (FileWriter)ent.getValue();
fw.close();
}
}
/**
* Set the parent directory for files.
*/
public void setParentDir(String parentDir) {
this.parentDir = parentDir;
}
}
And then when you set it up you can do something like provide the directory where the files will go:
Code:
<bean id="processor" class="MessageProcessor" destroy-method="destroy">
<!-- Specify which directory to write JMS files here -->
<property name="parentDir" value="/tmp/jmsFiles"/>
</bean>
<bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<!-- Your message processor -->
<property name="messageListener" ref="messageListener" />
<!-- Standard JMS configuration -->
<property name="concurrentConsumers" value="5"/>
<property name="connectionFactory" ref="connectionFactory" />
<property name="destination" ref="destination" />
</bean>
Hope this helps and makes sense in the context of what you want.
Jess