加入骆驼航线在Java运行时 [英] Add camel route at runtime in Java

查看:115
本文介绍了加入骆驼航线在Java运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何添加在Java运行时骆驼路线?我已经找到了Grails的例子,但我有在Java中实现它。

How can I add a camel route at run-time in Java? I have found a Grails example but I have implement it in Java.

我的applicationContext.xml中已经有一些predefined静态路由,我想一些动态路由在运行时添加到它。
可能吗?
由于包括动态路由的唯一方法是编写route.xml然后路由定义加载上下文。它是如何工作的现有静态路由?
路线在运行时

My applicationContext.xml already has some predefined static routes and I want to add some dynamic routes to it at run time. Is it possible? Because the only way to include dynamic route is to write the route.xml and then load the route definition to context. How will it work on existing static routes? Route at runtime

推荐答案

您可以简单地呼吁CamelContext几个不同的API来添加路由......像这样

you can simply call a few different APIs on the CamelContext to add routes...something like this

context.addRoutes(new MyDynamcRouteBuilder(context, "direct:foo", "mock:foo"));
....
private static final class MyDynamcRouteBuilder extends RouteBuilder {
    private final String from;
    private final String to;

    private MyDynamcRouteBuilder(CamelContext context, String from, String to) {
        super(context);
        this.from = from;
        this.to = to;
    }

    @Override
    public void configure() throws Exception {
        from(from).to(to);
    }
}

看到这个单元测试的完整的例子...

see this unit test for the complete example...

<一个href=\"https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/AddRoutesAtRuntimeTest.java\">https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/AddRoutesAtRuntimeTest.java

这篇关于加入骆驼航线在Java运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆