【问题标题】:Apache Camel with Spring DSL带有 Spring DSL 的 Apache Camel
【发布时间】:2016-05-05 04:55:00
【问题描述】:

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

【问题讨论】:

    标签: apache-camel


    【解决方案1】:

    找到解决方案。我应该在上下文开始后编写 Thread.sleep() 。甚至在文件被拾取之前,骆驼上下文就停止了。

    【讨论】:

      【解决方案2】:

      为了测试您的路线,您应该使用 http://camel.apache.org/testing.html 。这样你就不会陷入类似的问题。除此之外,camel-test 还提供了许多帮助程序,例如断言、模拟、测试骆驼上下文。

      camel-test api 对一些开发人员来说可能很麻烦,这就是为什么我开始开发一个小型库,希望可以解决一些样板文件http://github.com/gmaslowski/camel-test-support

      【讨论】:

        猜你喜欢
        • 2020-08-30
        • 2017-07-25
        • 1970-01-01
        • 2016-04-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多