Apache Camel与Spring DSL(Apache Camel with Spring DSL)

我正在尝试使用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?

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?

最满意答案

得到了解决方案。 我应该在上下文启动后写入Thread.sleep()。 即使在文件被拾取之前,Camel上下文也停止了。

Got the solution. I should have written Thread.sleep() after the context starts. Camel context was stopping even before the file was picked up.

更多推荐

camelContext,camel,class,Hello,电脑培训,计算机培训,IT培训"/> <meta name=&quo