0

使用 java JMS API,我从数据库中得到一个字节数组,然后将它作为 javax.jms.BytesMessage 发送到 ActiveMQ。之后用骆驼我想把文件放在一个位置,

我在骆驼中有这条路线:

    <route>
        <from uri="activemq:queue.fileOuput"/>
        <convertBodyTo type="java.nio.ByteBuffer"/>
        <to uri="file://C:/output/"/>
    </route>

但我的问题是我的文件在c:\output\目录中,我得到了带有消息 id 作为文件名的文件, queue-preVerificacion-fileoutput-ID-jmachine-57401-1347652410053-0-1-1-1-1 但是我想把我的名字放在数据库中,比如MyFile.xml.

我试图设置像fileName和file:name这样的消息属性,并且我在apache文档中看到我需要放置一个标题“org.apache.camel.file.name”,但是我不知道jms怎么做。

所以我的问题是如何在骆驼路线中放置自定义名称?

谢谢大家。

4

3 回答 3

4

只需将文件名放在 jms 消息中(作为字符串属性)。

// Something like this if you send the message using plain java/jms:
msg.setStringProperty("filename","MyFile.xml");
..//Send msg

然后你可以在骆驼中做这样的事情

<to uri="file://C:/output/?fileName=${header.filename}"/>
于 2012-09-14T23:05:28.300 回答
3

您只需要设置“CamelFileName”标头值(基于消息标头等)

<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>
于 2012-09-15T05:19:51.333 回答
0

我认为“org.apache.camel.file.name”适用于骆驼 1.x,在 2.x 版本中 CamelFileName 工作正常。但我想要一个更动态的文件名,根据内容命名。这个使用处理器的例子运行良好(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);
于 2018-07-10T15:07:40.943 回答