java - 使用 java DSL 创建的路由不会给出路由是否正确执行的任何线索。也使用 apache AHC compoenet 作为组件之一

标签 java routes apache-camel dsl

我已经配置了我的路线,如下所示。我没有收到异常,但同时没有输出。

public static void main(String[] args) {    
CamelContext camelContext = new DefaultCamelContext();
    try {
        camelContext.addRoutes(new RouteBuilder() {
           public void configure() {
                from("direct:foo")               
                .to("ahc:http://services.odata.org/V2/Northwind/Northwind.svc/")
                .to("file:c:/workpro/outbox?fileName=ahc.xml");
           }
        });
        camelContext.start();
    }catch (Exception e1) {
    }           
    }

执行后,我应该在 C 盘中创建一个名为 workpro 的文件夹。您认为我定义路线的方式有任何问题吗?

非常感谢, 拉克什

最佳答案

在 from 中使用计时器,如果您只想调用一次,请将其设置为 repeatCount=1

以及非阻塞的启动方法 - 我刚刚添加了 sleep 30 秒。但请参阅此常见问题解答以获得更好的方法:http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html

public static void main(String[] args) {    
CamelContext camelContext = new DefaultCamelContext();
    try {
        camelContext.addRoutes(new RouteBuilder() {
           public void configure() {
                from("timer:foo?repeatCount=1")               
                .to("ahc:http://services.odata.org/V2/Northwind/Northwind.svc/")
                .to("file:c:/workpro/outbox?fileName=ahc.xml");
           }
        });
        camelContext.start();
        Thread.sleep(30000);
        camelContext.stop();
    }catch (Exception e1) {
    }           
    }

或者您可以使用 direct 来代替计时器,但是您需要向 direct 端点发送一条消息来触发您的路由运行。这一切都记录在 Apache Camel 入门中,例如 http://camel.apache.org/walk-through-an-example.html 。建议新使用 Camel 的用户阅读:http://java.dzone.com/articles/open-source-integration-apache

关于java - 使用 java DSL 创建的路由不会给出路由是否正确执行的任何线索。也使用 apache AHC compoenet 作为组件之一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29124549/

相关文章:

java - Spring Security CSRF 训练模式

java - 未经检查的方法调用作为原始类型的成员

node.js - 无法提供具有快速路由且没有斜杠的静态文件

动态改变端点 Camel

java - Camel Route 中的错误处理程序重试次数超过配置值

java - hibernate 保存/更新级联

未找到带有 Web 窗体和 SSL 页面的 ASP.Net 路由

javascript - 我的函数和重定向到路线之间的延迟

java - 部署 Apache Camel 应用程序时出现警告

java - 使用 Eclipse 为 java 6 编译 java 7