简体   繁体   English

一旦目录中的所有文件都已处理完毕,Camel Spring DSL就在bean上调用方法

[英]Camel Spring DSL Call a method on bean once all all files in a directory have been processed

I am trying to achieve the following in Camel Spring DSL (Version 2.12.1). 我试图在Camel Spring DSL(2.12.1版)中实现以下目标。

  • Read all files from a directory 从目录读取所有文件
  • Process each file with an indexer bean 使用indexer bean处理每个文件
  • Call a finalizeRepository method on the indexer bean once all files have been processed 处理完所有文件后,在索引器bean上调用finalizeRepository方法

(Based on the answer supplied by Claus I have updated the code sample below with a working solution.) (基于克劳斯提供的答案,我已使用有效的解决方案更新了以下代码示例。)

<route>
    <from uri="file:./dataToIndex" />
    <bean ref="indexer" method="addDocument(${body}, ${headers.CamelFileNameOnly})" />
    <when>
        <simple>${headers.CamelBatchComplete} == true</simple>
    <bean ref="indexer" method="finalizeRepository" />
    </when>
</route>

If the header CamelBatchComplete holds the value true the method finalizeRepository on the indexer bean will be called. 如果标头CamelBatchComplete的值为true ,则将调用indexer bean上的finalizeRepository方法。 The header is set to true once all documents in the dataToIndex directory have been processed. 一旦处理了dataToIndex目录中的所有文档,标头就设置为true

The only thing I am not quite certain about is the definition of batch . 我唯一不确定的是batch的定义。 Is a batch determined based on what is found during a single polling event (eg if 1k files are found in a directory then this constitutes the batch), or a pattern of polling event (ie a series of successfull polls with items followed by a poll without any items is considered a batch ). 是一个batch的基础上确定什么是单轮询事件过程中发现的(例如,如果1K文件在目录中找到那么这构成批次),或轮询事件的模式(即项目,随后以投票一系列全成投票没有任何项目的项目视为batch )。

The file component adds a header when its processing the last file in the batch. 文件组件在处理批处理中的最后一个文件时会添加标头。 You can use that to know when its the last and call the bean. 您可以使用它来知道何时最后一次调用bean。

This is done by other components which supports "batch" as you can find details here 这是由其他支持“批处理”的组件完成的,您可以在此处找到详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将Spring bean注入Camel DSL - Injecting Spring bean into Camel DSL Apache Camel-Spring DSL-将String参数传递给bean方法 - Apache Camel - Spring DSL - Pass String argument to bean method 将所有文件移动到 unix 后写入触发器文件 - Write trigger file once all files have been moved to unix 骆驼文件:处理完所有文件后停止路由 - Camel File: Stop route when all files are processed Apache Camel Spring XML - 来自文件名表达式的 Bean 方法调用 - Apache Camel Spring XML - Bean method call from filename expression 是否可以确保在所有servlet过滤器都处理完毕之前将重定向延迟? - Is a redirect guaranteed to be delayed until all servlet filters have been processed? Spring DSL 的 Apache Camel bean 参数绑定问题 - Apache Camel bean parameter binding issue with Spring DSL Apache Camel Java DSL将类参数传递给bean方法 - Apache Camel Java DSL pass class parameter to bean method 骆驼java dsl传递bean方法返回值到标头 - camel java dsl pass bean method return value to header Is it possible to call the header value as a parameter for the method applied to the same object in simple interpreter, Spring DSL for Apache Camel? - Is it possible to call the header value as a parameter for the method applied to the same object in simple interpreter, Spring DSL for Apache Camel?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM