On 07.04.2011 15:33, Arkadi Shishlov wrote:
It is perfectly reasonable and doable, please see comments inline.

On Thu, 07 Apr 2011 13:24:02 +0300, Andrey Popp <8may...@gmail.com> wrote:
I'm wondering of the following setup:

  * Apache Camel running as daemon.

In our project we pack Camel with maven-shade-plugin into uber-jar and launch it under nohup java -jar. I do not have an access to wiki, but I can send you pom.xml and custom Main.java, or publish it here for reference.

* Ability to submit new routes' configuration from command line (as of CAMEL-1004 it seem Apache Camel is able to replace routes at runtime) as plain Java/Scala
    code files.

Dynamic reconfiguration works. We start with from() and gradually build the route(s) based on database setup. If you arrange a system to load Java code on demand, be it Java, Scala, or Groovy (to skip compile step), then: 1. instantiate a class that extends RouteBuilder and performs route construction in configure()
2. call camel.addRoute(builder)
3. done :)
We keep a "started routes" Map of String->List key-ed by database Id and shutdown old instances in front-to-back order [because our routes consists of multiple from() steps] via camel.stopRoute()+removeRoute().

* Apache Camel should try to compile routes and in the case of success -- replace
    current routes with the new ones.

The replace part could be tricky depending on your requirements. If you started a slightly different copy of the route, you may get duplicates or other undesirable behavior. But route definition should be tested before production somewhere else, so you can probably just shutdown old stuff before staring new one.

The last point is no issue, if you use the same route id. So this test works:

    public void testReplacement() throws Exception{

        MockEndpoint a = getMockEndpoint("mock:a");
        a.setExpectedMessageCount(1);

        template.sendBody("direct:a", "foo");

        RouteBuilder builder = new RouteBuilder() {

            @Override
            public void configure() throws Exception {

                from("direct:a")
                .routeId("myRoute")
                .to("mock:b");

            }
        };

        context.addRoutes(builder);

        MockEndpoint b = getMockEndpoint("mock:a");
        b.setExpectedMessageCount(1);

        template.sendBody("direct:a", "foo");

        assertMockEndpointsSatisfied(10, TimeUnit.SECONDS);

    }

    protected RouteBuilder createRouteBuilder(){
        return new RouteBuilder() {

            @Override
            public void configure() throws Exception {

                from("direct:a")
                .routeId("myRoute")
                .to("mock:a");

            }
        };

    }

Reply via email to