在Beans.xml中定义的CamelContext。我如何以编程方式实例化camelContext路由
问题描述:
我在spring beans.xml中定义了骆驼上下文。在Beans.xml中定义的CamelContext。我如何以编程方式实例化camelContext路由
现在我想以编程方式在骆驼上下文中调用路由。我怎么做。我想以编程方式执行此操作,因为我想让我的多个节点之一运行此下载。我不想让这个骆驼的所有节点都运行下载。我打算将这作为一项工作或使用动物园管理员,但不想改变我们编写骆驼路线的方式。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<!-- Camel context which holds the route definitions -->
<camelContext id="camelpriceroutebean" errorHandlerRef="errorHandler"
xmlns="http://camel.apache.org/schema/spring">
<route id="download-from-ftp" autoStartup="true" startupOrder="1">
现在我已经用下面的代码
ApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/springbean.xml");
CamelContext camel = (CamelContext) context.getBean("camelpriceroutebean");
List<Route> routes = camel.getRoutes();
试过但springbean.xml抛出expcetion。有没有另一种方法来处理这个问题。 ?
答
看到这个常见问题:http://camel.apache.org/running-camel-standalone.html这http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html。您需要启动Spring/Camel并保持JVM运行并允许路由从FTP服务器运行和下载。这是自动发生的,您不需要调用路由,以使其在从FTP端点消耗时运行。
我建议研究骆驼一些更多它是如何工作等更好地理解它。有例如FTP等案例在:https://github.com/apache/camel/tree/master/examples#examples
嗨克劳斯,我想以编程方式做到这一点,因为我想控制下载的和我的多台机器的一个唯一做到这一点的下载时间。所以我正在寻找在我的骆驼环境中调用路线 – ssD