java - 如何在运行时在 Spring Boot 应用程序下将添加/删除路由更新到 Apache Camel 中?
问题描述
我需要在应用程序Apache Camel
的运行时添加/删除路由。Spring Boot
这意味着应该在应用程序运行时更新路由。这也意味着在应用程序的第一次运行期间我没有所有路由,并且我无法重新启动它以获取它们。
我找到了旧答案,但仍然无法理解如何使用xml
-defined 路由来做到这一点。你能解释一下怎么做吗?
解决方案
将您的 xml 放在 src/main/resources 下并调用以下组件:
@Component
public class CamelRoutesLoader {
@Autowired
private CamelContext camelContext;
@Value("${camel-routes-filename:#{null}}")
private String routesFilename;
@PostConstruct
private void loadRoutes() {
if(routesFilename == null) {
//error no file name
}
try {
InputStream is = this.getClass().getClassLoader().getResource(routesFilename).openStream();
RoutesDefinition routes = ModelHelper.loadRoutesDefinition(camelContext, is);
camelContext.addRouteDefinitions(routes.getRoutes());
} catch(Exception e) {
//Impossible to load routes
}
}
}
我在 Spring 初始化后调用我的组件,但您可以删除 @PostConstruct,将其公开并传递文件名
推荐阅读
- google-chrome-extension - 使用 chrome 扩展在 mail.google.com 上注入脚本
- visual-studio - Visual Studio Installer 项目始终安装 .NET Framework 4.8 必备组件,即使已安装
- javascript - 循环遍历数组(`Object.keys(obj)`)以查找值
- flutter - 如何在appBar中为flutter中的gridview列表实现搜索栏
- python - 在python中查找随机列表的浮点平均值
- python - 如何将for循环内函数的生成结果存储到Python中的DataFrame?
- javascript - 单击汉堡包时侧边栏而不是下拉菜单(引导程序)
- php - 为什么 if elseif 失败了?
- python - 1e-11 的 Python 浮点精度的奇怪行为
- json - 获取几个字段并遍历数组