首页 文章

Apache Camel的Enrich EIP如何处理文件 endpoints ?

提问于
浏览
1

我试图通过编写使用各种EIP的简单路由来学习如何使用Apache Camel . 我的导师建议Apache ServiceMix作为测试简单路由的好服务器,所以我使用的是Apache ServiceMix 5.1.0 . 目前,我正在尝试创建一个从文件读取请求的路由,用来自第二个文件的响应替换请求的内容,并将该响应写入第三个文件 .

理想情况下,第二个文件只是试图让它现在正常工作,所以我并没有使用像 noop 这样的选项使事情复杂化 .

如果我已正确读取the Apache Camel Wiki page for the Content Enricher,则从 enrich EIP中省略聚合策略将使Camel丢弃消息的内容并将其替换为从资源获取的正文 . 所以,我认为这个Camel Route会做我想要的:

<?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的新手,我认为问题只是我误读了文档中的内容,或忽略了明显的配置问题 .

对于它的 Value ,这里是开始路线之前文件的内容 .

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.

感谢您的时间 .

2 回答

  • 1

    来自Camel doc

    enrich使用Producer获取额外数据 . 它通常用于请求回复消息传递,例如用于调用外部Web服务 . 另一方面,pollEnrich使用轮询消费者来获取附加数据 . 它通常用于事件消息消息传递,例如读取文件或下载FTP文件 .

    如果使用 enrich ,则 withThis.txt 的内容将替换为 replaceMe.txt 的内容,这不是您想要的 . 请改用 pollEnrich

    <pollEnrich uri="file:camel/storedResponse/?fileName=withThis.txt" />
    
  • -1

    丰富的工作就像一个你的路线实际上是 writing 身体从replaceMe.txt收到withThis.txt而不改变身体的任何东西 . 因此,最终结果pollEnrich需要用于来自withThis.txt的 read

相关问题