Apache camel 如何在处理完所有文件后调用bean?
我编写了下面的路径,并希望bean'streamerservice'应该只在处理所有文件结束时调用一次,但是。。。在处理每个文件后调用:Apache camel 如何在处理完所有文件后调用bean?,apache-camel,Apache Camel,我编写了下面的路径,并希望bean'streamerservice'应该只在处理所有文件结束时调用一次,但是。。。在处理每个文件后调用: <route id="teaserInterface"> <from uri="file://{{teaser.dropInDir}}?readLock=changed&delete=true&delay=60000" /> <
<route id="teaserInterface">
<from
uri="file://{{teaser.dropInDir}}?readLock=changed&delete=true&delay=60000" />
<choice>
<when>
<simple>${file:ext} == 'properties'</simple>
<to uri="file://{{teaser.config.directory}}" />
</when>
<when>
<simple>${file:ext} == 'jpg' || ${file:ext} == 'JPG'</simple>
<to uri="sftp://{{apache.ftp.user}}@{{apache.ftp.host}}/{{apache.teaser.ftp.targetDir}}?password={{apache.ftp.password}}&binary=true&separator=UNIX" />
</when>
<otherwise>
<transform>
<simple>Dear user,\n\n the Teaser interface only accept *.jpg and *.properties files, but we found the file ${file.name}.\n\n Have a nice day,\nYour lovely Teaser interface</simple>
</transform>
<to
uri="smtp://smtp.blabla.com?contentType=text/plain&from=blabla@blabla.com&to=chica@chicas.com&subject=A problem occured while setting up new teaser!" />
</otherwise>
</choice>
<bean ref="teaserService" method="updateTeaser" />
</route>
${file:ext}=='properties'
${file:ext}=='jpg'| |${file:ext}=='jpg'
尊敬的用户,\n\n摘要界面仅接受*.jpg和*.properties文件,但我们找到了文件${file.name}。\n\n祝您愉快,\n您可爱的摘要界面
如何实现这样的行为
谢谢驼峰文件组件是一个组件,它向exchange添加了有关正在处理的批的属性。您可以测试属性
CamelBatchComplete
,如果该属性设置为true,则调用bean。如果您只想在读取所有文件后继续,则必须以某种方式对其进行采样。这可以使用以下模式实现:
真的
请注意,我设置了completionFromBatchConsumer=“true”
。从Camel文档中:
如果交换来自批量消费者,则此选项可用。然后,启用时,Aggregator2将使用批处理使用者在消息头CamelBatchSize
中确定的批处理大小。[…]这可用于聚合给定轮询中从文件终结点使用的所有文件
谢谢你,拉尔夫!你有没有一个例子?@zzKozak在我的回答中看到了一个示例,其中显示了一个聚合器,该聚合器具有
completionFromBatchConsumer
选项,如果交换来自批量消费者,则可以使用该选项。
<route>
<from uri="file://src/data/aggregate-and-process?readLock=changed&delete=true&delay=60000" />
<aggregate strategyRef="aggregationStrategy" completionFromBatchConsumer="true">
<correlationExpression>
<constant>true</constant>
</correlationExpression>
<to uri="direct:sub" />
</aggregate>
</route>
<route>
<from uri="direct:sub" />
<!-- processing aggregated body -->
</route>