【发布时间】:2018-09-29 06:21:26
【问题描述】:
我正在尝试通过编写使用各种 EIP 的简单路由来学习如何使用 Apache Camel。我的导师建议 Apache ServiceMix 作为测试简单路由的好服务器,所以我使用的是 Apache ServiceMix 5.1.0。目前,我正在尝试创建一个从文件中读取请求的路由,将请求的内容替换为来自第二个文件的响应,然后将该响应写入第三个文件。
理想情况下,第二个文件不会被删除;我最终想在其他自学路线中使用这种模式,第二个文件将模仿 web 服务的响应。但是,我现在只是想让它工作,所以我不会使用noop 之类的选项使事情复杂化。
如果我正确地阅读了the Apache Camel Wiki page for the Content Enricher,从enrich EIP 中省略聚合策略将使Camel 丢弃消息的内容并将其替换为从资源中获取的正文。所以,我认为这条骆驼路线会做我想做的事:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:camel="http://camel.apache.org/schema/blueprint" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="file:camel/inMessage/?fileName=replaceMe.txt" />
<enrich uri="file:camel/storedResponse/?fileName=withThis.txt" />
<to uri="file:camel/outMessage/?fileName=output.txt" />
</route>
</camelContext>
</blueprint>
实际发生的是camel/storedResponse/withThis.txt 的内容被camel/inMessage/replaceMe.txt 的内容替换。文件camel/outmessage/output.txt 已创建,但它包含replaceMe.txt 的内容,而不是withThis.txt。
由于我还是 Camel 的新手,我认为问题只是我误读了文档中的某些内容,或者忽略了一个明显的配置问题。
不管怎样,这里是开始路线之前的文件内容。
replaceMe.txt
This is the message sent. It should not appear in the response.
withThis.txt
This is the file stored in the server. The response should contain this text.
output.txt does not yet exist.
这是路由完成后的文件内容。
replaceMe.txt has been deleted.
withThis.txt
This is the message sent. It should not appear in the response.
output.txt
This is the message sent. It should not appear in the response.
感谢您的宝贵时间。
【问题讨论】:
标签: apache-camel apache-servicemix blueprint-osgi