在运行时修改骆驼路线/上下文

问题描述 投票:0回答:1

我在我的应用程序中使用 Apache camel 作为集成框架。我正在使用 @ImportResource 注释将 CamelContext.xml 文件添加到我的应用程序中。像这样,camel 上下文文件是使用另一个服务从数据库中获取的。

@ImportResource("http://IP:PORT/files/CamelContext.xml")

Camel 上下文看起来像这样

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.springframework.org/schema/beans"
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd 
    ">
<import resource="http://IP:PORT/files/SampleTestFile.xml" />
<camelContext id="ModelIntegration" trace="true"
        messageHistory="true" xmlns="http://camel.apache.org/schema/spring">
        <routeContextRef ref="SampleTestRef" />
</camelContext>

</beans>

由于 camel 上下文是通过 API 从另一个服务获取的,所以我也想在我的应用程序中添加路由管理。所以我计划在路由管理服务中使用 API 来更新路由和上下文文件。但令人困惑的是如何在运行时重新加载/应用对上下文和路由所做的新更改而不重新启动应用程序。 有人请帮忙。

java spring-boot apache-camel spring-camel
1个回答
0
投票

通常在 spring 应用程序中实现此目的的唯一方法是使用

org.springframework.context.ConfigurableApplicationContext.refresh()
刷新应用程序上下文。为了避免重新启动整个应用程序,骆驼的东西应该在它自己的应用程序上下文中,它可能将应用程序的整体上下文作为父级。然后你只是重新启动必要的东西。

请注意,运行时路由管理等已经是 camel-karaf 的一部分。因此,与其重新发明轮子,不如研究将骆驼的东西移动到 karaf 实例。

© www.soinside.com 2019 - 2024. All rights reserved.