Reputation: 726
With the java JMS API, I got from a DB an array of bytes and then I'm sending it to an ActiveMQ as a javax.jms.BytesMessage. After that with camel I want to put the file on a location,
I have this route in camel:
<route>
<from uri="activemq:queue.fileOuput"/>
<convertBodyTo type="java.nio.ByteBuffer"/>
<to uri="file://C:/output/"/>
</route>
But my problem is that my file in c:\output\
directory, I got the file with the message id as the file name, like
queue-preVerificacion-fileoutput-ID-jmachine-57401-1347652410053-0-1-1-1-1
but I want to put the name I have in the database, like MyFile.xml
.
I have tried to set a message property like fileName and file:name, and also I saw in the apache document that I need to put a header "org.apache.camel.file.name", but with jms I don't know how to do it.
So my question is how can I put a customized name in the camel route?
Thanks to all.
Upvotes: 0
Views: 7122
Reputation: 520
I think "org.apache.camel.file.name" is for camel 1.x , in the 2.x version CamelFileName worked fine. But I wanted a more dynamic file name, name based on the content. This example using a processor worked well ( camel 2.18 )
<route>
<from uri="MQ:MY_Q_NAME" />
<process ref="MyMessageProcessor"/>
<to uri="file://E:\OUTPUT" />
</route>
Inside the Processor :
exchange.getIn().setHeader(Exchange.FILE_NAME, myFileName);
Upvotes: 0
Reputation: 21005
you just need to set the "CamelFileName" header value (based on a message header, etc)
<route>
<from uri="activemq:queue.fileOuput"/>
<convertBodyTo type="java.nio.ByteBuffer"/>
<setHeader headerName="CamelFileName">
<constant>${header.fileName}</constant>
</setHeader>
<to uri="file://C:/output/"/>
</route>
Upvotes: 3
Reputation: 22279
Just place the file name in the jms message (as a string property).
// Something like this if you send the message using plain java/jms:
msg.setStringProperty("filename","MyFile.xml");
..//Send msg
Then you can do something like this in camel
<to uri="file://C:/output/?fileName=${header.filename}"/>
Upvotes: 4