You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Amol Amlapure <am...@gunadhyasoft.com> on 2020/06/30 12:36:46 UTC

RoutesBuilder example in camel 3.2

Hello,

We are trying to upgrade to camel from 2.23.2 to 3.2.
We have a code which adds Routes to CamelContex.

CamelContext cxt = _context.getBean(CamelContext.class);
if (cxt.getRoute(routeid) == null) {
RouteDefinition rtDef = new RouteDefinition();
rtDef.setId(routeid);
rtDef.from("activemq:topic:" + from).beanRef(beanref, methodname);
if (to != null)
rtDef.to(to);

cxt.addRouteDefinition(rtDef);
}

We were exploring the option to use RoutesBuilder to create and add routes
to camelContext. but all the examples have implementation like below:
context.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:start").to("mock:result");
            }
        });
and RoutesBuilder class has only one abstract method:
addRoutesToCamelContext
<https://www.javadoc.io/static/org.apache.camel/camel-api/3.2.0/org/apache/camel/RoutesBuilder.html#addRoutesToCamelContext-org.apache.camel.CamelContext->
(CamelContext
<https://www.javadoc.io/static/org.apache.camel/camel-api/3.2.0/org/apache/camel/CamelContext.html>
 context)

Could you please help with this?

Thanks,
Amol

Re: RoutesBuilder example in camel 3.2

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

context.addRoutes(new RouteBuilder() {

Automatic adds the route, so you dont need to do anything else.
This is what 99,9% of users do.

What you did in 2.x is not common with using the xxxDefinition
classes. That is more for Camel internally.
Use the RouteBuilder classes with the DSL in the configure method.

On Wed, Jul 1, 2020 at 12:28 AM Amol Amlapure
<am...@gunadhyasoft.com> wrote:
>
> Hello,
>
> We are trying to upgrade to camel from 2.23.2 to 3.2.
> We have a code which adds Routes to CamelContex.
>
> CamelContext cxt = _context.getBean(CamelContext.class);
> if (cxt.getRoute(routeid) == null) {
> RouteDefinition rtDef = new RouteDefinition();
> rtDef.setId(routeid);
> rtDef.from("activemq:topic:" + from).beanRef(beanref, methodname);
> if (to != null)
> rtDef.to(to);
>
> cxt.addRouteDefinition(rtDef);
> }
>
> We were exploring the option to use RoutesBuilder to create and add routes
> to camelContext. but all the examples have implementation like below:
> context.addRoutes(new RouteBuilder() {
>             @Override
>             public void configure() throws Exception {
>                 from("direct:start").to("mock:result");
>             }
>         });
> and RoutesBuilder class has only one abstract method:
> addRoutesToCamelContext
> <https://www.javadoc.io/static/org.apache.camel/camel-api/3.2.0/org/apache/camel/RoutesBuilder.html#addRoutesToCamelContext-org.apache.camel.CamelContext->
> (CamelContext
> <https://www.javadoc.io/static/org.apache.camel/camel-api/3.2.0/org/apache/camel/CamelContext.html>
>  context)
>
> Could you please help with this?
>
> Thanks,
> Amol



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2