如何有选择地从其他路线开始骆驼路线? [英] How to start Camel route optionally from other route?
问题描述
有选择地从另一条路线开始骆驼路线的最佳方法是什么?我的用例是我要根据数据库中的表发送自动报告.如果表已过时,则应开始获取新数据的路径.
What is the best way to start a camel route optionally from another route? My use case is i'm sending out automated reports based on a table in a database. If the table is stale, the route to fetch fresh data should be started.
我有用于生成和发送报告的路由,也有从远程服务器获取文件,在本地保存文件,将其读入数据库并更新数据库日志的路由(这可以告诉报告路由是否有数据是新鲜的.)
I have routes for generating and sending out the reports and i have a route for fetching a file from a remote server, saving it locally, reading it into a database and updating the database log (this tells the reporting routes if the data is fresh).
但是如何将它们绑在一起?
But how to tie them together?
// write to database
from(routeFrom)
.routeId(routeId)
.to(String.format(BEAN_INIT_DB_TABLE, routeId))
.to(String.format(BEAN_VALIDATE_TABLE_COLUMNS, routeId))
.to(String.format(BEAN_LOAD_CSV_FILE_TO_DB, routeId));
// fetch from database
from(reportFrom)
.routeId(reportRouteId)
.to(String.format(BEAN_CHECK_FILEINDB, reportRouteId)
.to(String.format(BEAN_LOAD_DB_TABLE_TO_XLSX_FILE, reportRouteId)
.to(BEAN_START_MAIL, reportRouteId);
在上述 routeFrom , routeId , reportFrom 和 reportRouteId 中,在(yml)属性文件中进行了设置,以及其他路线属性.实际的繁重工作是使用Java Bean完成的.
In the above routeFrom, routeId, reportFrom and reportRouteId are set in a (yml) properties file, as wel as other route properties. The actual heavy work is done with java beans.
如果数据库中没有当前数据可用, BEAN_CHECK_FILEINDB 现在将引发异常.这可以用在骆驼谓词中,然后我可以用骆驼的 choice .但是我该如何从一个选择开始一条骆驼路线呢?
The BEAN_CHECK_FILEINDB will now throw an exception if no current data is available in the database. This could be used in a camel Predicate, then i could use camel's choice. But how can i start a camel route from a choice?
推荐答案
我没有尝试过,但是使用@ claus-ibsen在评论中提到的controlbus功能,应该是这样的:
I have not tried it, but using the controlbus feature mentioned by @claus-ibsen in the comments, it should be something like this:
.choice()
.when(<your no-data-available predicate>)
.to("controlbus:route?routeId=<yourRouteId>&action=suspend")
.otherwise()
.to(<continue to process db-contents>);
有stop
,start
,suspend
和resume
可用作操作.如果您想多次停止/启动路线,suspend
和resume
听起来更合适,但我不知道确切的区别.
There are stop
, start
, suspend
and resume
available as actions. If you want to stop/start the route multiple times, suspend
and resume
sounds more suitable, but I don't know the exact difference.
请注意,.to(...)
仅采用静态端点地址.如果要插入表达式作为路由ID,则必须使用.toD(...)
Notice that .to(...)
only takes static endpoint addresses. If you want to insert an expression as route ID, you have to use .toD(...)
这篇关于如何有选择地从其他路线开始骆驼路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!