我正在尝试使用spring DSL在Apache Camel中运行一个简单的应用程序 . 这是我的spring-config.xml
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost" />
</bean>
</property>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file:src/data?noop=true" />
<process ref="downloadLogger" />
<to uri="jms:incomingOrders" />
</route>
</camelContext>
<bean id="downloadLogger" class="com.test.eip.camel.DownloadLogger"></bean>
这是我的Java类测试:
public class CamelSpringTest {
public static void main(String[] args) throws Exception {
ApplicationContext appContext = new ClassPathXmlApplicationContext("spring-config.xml");
CamelContext camelContext = SpringCamelContext.springCamelContext(appContext, false);
try {
System.out.println("Hello");
camelContext.start();
} finally {
System.out.println("Hello2");
camelContext.stop();
}
}
}
我可以在我的控制台中看到Hello和hello2,但我的文件没有被移动 . 我认为在创建驼峰上下文时我做错了什么 . 能否请你帮忙?我是否需要明确地向camelContext添加路由?
2 回答
得到了解决方案 . 我应该在上下文启动后编写Thread.sleep() . 即使在文件被拾取之前,Camel上下文也停止了 .
要测试您的路线,您应该使用http://camel.apache.org/testing.html . 这样你就不会遇到类似的问题 . 除此之外,camel-test提供了许多帮助器,如断言,模拟,测试驼峰上下文 .
对于一些开发人员来说,驼峰测试api可能很麻烦,'s why I'已经开始开发一个小型库,希望可以解决一些样板问题http://github.com/gmaslowski/camel-test-support