2 Replies Latest reply: Jan 5, 2014 10:05 AM by Erhard Siegl RSS

Only one route allowed per Java DSL

Erhard Siegl Newbie

Hi,

 

Coming from Camel, I find the "direct:..." endpoint very convenient to structure my code. A small demo-example in Camel looks like this:

 

    public void configure() {

              Namespaces ns = new Namespaces("o", "http://bergfex.at/order/1.0");
    
              from("activemq:personnel.records")
                  .multicast().to("direct:journal","direct:validator");
                   
              from("direct:validator")
                  .doTry()
                            .to("validator:order.xsd")
                            .to("direct:router")
                  .doCatch(org.apache.camel.ValidationException.class)
                            .to("log:INVALID_MESSAGE?showCaughtException=true")
                            .to("activemq:invalid.records")
                  .end();
    
              from("direct:router")
                 .process(new CheckHeaderProcessor(Exchange.FILE_NAME))
                   .choice()
                       .when(ns.xpath("/o:order/o:person/o:city = 'London'"))
                           .to("activemq:london.records")
                       .otherwise()
                           .to("log:INVALID_CITY")
                           .to("activemq:invalid.records");
    
                 from("direct:journal").removeHeader(Exchange.FILE_NAME).to("file:target/journal");     
    }

 

 

When I try a similar thing in Switchyard I get: "org.switchyard.exception.SwitchYardException: Only one route allowed per Java DSL class ..."

Of cource one could write everything as one route or define external References and several @Route Classes, but both solutions would make the code more difficult to read and harder to maintain.

Are there plans to support more routes within one class or are there other alternatives especially to this use of the "direct" endpoint?

  • 1. Re: Only one route allowed per Java DSL
    Łukasz Dywicki Novice

    Hey Erhard,

    This limitation is introduced to keep clean relation between service interface and mediation behind the scenes, because every implementation.camel must be linked with interface. You are right that references are good practice in this case, instead of direct: you can use switchyard:// in uri. If you would like to have multiple entry points to service you can use different bindings (as you have JMS component).

  • 2. Re: Only one route allowed per Java DSL
    Erhard Siegl Newbie

    The feature was implemented in Switchyard 1.0.0. This works now :

      public void configure() {

           from("switchyard://Greeter")

                .log(LoggingLevel.INFO,

                     "Received message for 'Greeter' : ${body}")

                .to("direct:ep1")

                .to("file:testdir");


           from("direct:ep1")

                .log("Hit direct endpoint")

                .to("switchyard://SaveService");

           }

      }