Apache Camel with Spring DSL
I'm trying to run a simple application in Apache Camel using spring DSL. Here is my 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>
And here is my Java class for testing:
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();
}
}
}
I can see Hello and hello2 in my console, but my file is not being moved. I think I'm doing something wrong while creating the camel context. Could you please help? Do I need to add routes explicitly to camelContext?
Got the solution. I should have written Thread.sleep() after the context starts. Camel context was stopping even before the file was picked up.
For testing your routes you should rather use http://camel.apache.org/testing.html . This way you won't fall into similar problems. Besides that camel-test provides many helpers like assertions, mocks, test camel context.
The camel-test api may be cumbersome for some developers, that's why I've started developing a small library which hopefully can address some of the boilerplate http://github.com/gmaslowski/camel-test-support
链接地址: http://www.djcxy.com/p/55010.html上一篇: Apache Camel消息格式
下一篇: 与春天DSL的Apache骆驼