如何使用骆驼端点管理文件?

我有一个应用程序,可以读取一个文件夹中的文件,更改其内容并将其写回到另一个文件夹中。我正在尝试使用Citrus添加集成测试,以在第一个文件夹中写入一些内容,并在应用程序对其进行修改后检查第二个文件夹中更改的内容。

我的问题与this one非常相似,在答复中说要使用骆驼路线,但是我对这些概念还很陌生,不知道从哪里真正开始...

我不太了解<camelContext>标签及其工作方式。到目前为止,我已经写了下面的内容,这就是我尝试在文件中写的地方:

<citrus-camel:endpoint id="inputCamelEndpoint" camel-contxt="inputCamelContext" endpoint-uri="file://C:/HL7/source/?fileName=test.hl7"/>

<camelContext id="inputCamelContext" xmlns="http://camel.apache.org/schema/spring">
    <route id="inputRoute">
        <to uri="file://C:/HL7/source/?fileName=test.hl7"/>
    </route>
</camelContext>

<send endpoint="inputCamelEndpoint">
    <message type="plaintext">
        <data>Hello!</data>
    </message>
</send>

我应该为<from uri="">写些什么? 而且,camelContext的xmlns属性是否已损坏?我有this error

我真的希望有人能给我一些有关这一切的细节,我很迷茫。

BDanube 回答:如何使用骆驼端点管理文件?

欢迎来到Stackoverflow! 在遇到这个问题之前,我还没有听说过Citrus框架,但是我对Camel知之甚少,并且会尝试通过个性化的Camel 101帮助您,以助您一臂之力。

第一件事

  • CamelContext就像Apache Camel集成框架的运行时环境。将其视为类似于Spring ApplicationContext之类的东西。您使用Camel创建的所有内容都生活在上下文中。
  • 骆驼Route是一条处理管道。它从某物(httpjmsfile ... almost everything under the sun)中获取输入,对其应用零个或多个处理步骤,并产生某物的输出({ {1}},consoledisk .....您命名。)
    如果我们考虑一条简单的路线,则可能会有两个http。一种 消耗Endpoints的{​​{1}}端点,一个检查或处理入站消息的一个或多个Consumer组件以及一个将Messages最终消息发送到某个地方(例如存储到磁盘,打印在通过Testminal的HTTP发布到服务器上...)

就您而言,据我所知,您需要一个Processor来接收来自Citrus框架的消息并将其存储到磁盘,以便被测系统可以处理此文件。要在Camel的XML DSL中将此用例解释为路由定义。

Producer

Route URI表示同步的 <camelContext id="inputCamelContext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://camel.apache.org/schema/spring" xsi:schemaLocation=" http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <route id="inputRoute"> <from uri="direct:citrusConsumer" /> <to uri="file://C:/HL7/source/?fileName=test.hl7" /> </route> <camelContext/> 端点[Docs on direct component]。此示例路由所执行的操作是,将到达使用者(direct:)的所有输入消息接收,并将其写入目录Consumer中的名称为direct:direct:citrusConsumer的文件中。如果您想在这里花哨的话,请阅读File组件的其他选项。 Citrus-Camel integration docs还显示了名为test.hl7的{​​{1}}组件的用法。一旦C:/HL7/source/上方示例代码中的direct:准备就绪,Citrus即可向direct:news发送消息以与Camel通话。

重新使用示例代码,集成就像下面的代码片段(请注意对endpoint-uri的更改)

Route

我希望这可以帮助您取得成功。

本文链接:https://www.f2er.com/3153585.html

大家都在问