在 Apache Camel 中动态加载路由的最佳方式 [英] Best way to load dynamically routes in Apache Camel
问题描述
我们已经开发了基于 Karaf 和 Apache Camel 的应用程序.虽然我们的应用程序完全基于包 (OSGI),但我们也在启动时加载 Camel 上下文(及其路由上下文"),这意味着我们已经定义了一些静态路由.
we have developped application based on Karaf and Apache Camel. While our application is entirely based on bundles ( OSGI ) we are also loading the Camel context ( and its' Route Contexts ) on startup, whcih would mean that we have defined some static routes.
我的问题是.有没有一种方法可以在应用程序运行时动态加载路由,而无需重新读取 Camel 上下文,因为这将重置/重新启动已经存在的路由.这同样适用于已经创建的路由,例如,如果我们想要编辑一个已经存在的路由.
My question is. Is there a way to dynamically LOAD routes while the application is running without the need to reread the Camel Context as this will reset/restart the already existing routes. The same would apply to already created routes, for example if we want to edit a route whcih already exist.
整个想法是我们计划将路线放入数据库中,因此,数据库将通过 GUI 进行编辑.
The whole idea is that we are planning to put the routes in a database and as such, the database will be edited by a GUI.
那么最好的方法是什么?我不相信这真的是在添加、编辑路由等情况下重新加载 OSGI 包/包的最佳方法......
So what's the best approach to do this? I do not beleive that it is really the best approach to reload OSGI bundle/bundles in case of a route being added, editted etc...
在应用程序运行过程中,或多或少,不同的端点及其相关路由将被添加、编辑、删除.
More or less during operation of the application, Different endpoints + their related routes will be added, edited, removed.
请指教.
谢谢,蒂霍
推荐答案
我认为一个好的方法是将你的路由分组到小的上下文中,每个上下文只有几个(甚至可能是单个)路由.然后你重新加载那个小上下文,而不会导致其他路由中断.
I think a good approach is to group your routes into small contexts with just a few (or maybe even single) routes per context. Then you reload that small context without causing interruption in other routes.
但是,由于您不相信这种方法,因此您可以使用 CamelContext 上的方法轻松添加和删除路由.创建一个路由构建器,从您的数据库构建路由并使用 addRoutes 和 removeRoute.
However, as you don't believe in that approach, you can easily add and remove routes with methods on the CamelContext. Create a route builder that constructs routes from your database and use addRoutes and removeRoute.
这篇关于在 Apache Camel 中动态加载路由的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!