You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by horyna <ph...@centrum.cz> on 2013/05/02 15:26:38 UTC

Is possible to wrap a part of route?

We have in lots routes some common part. e.g.:

  .setHeader("h", constant(THIS_IS_VARIOUS_FOR_EVERY_ROUTE))
                .filter(method("serv", "method").isEqualTo(false))
                .to(VARIOUS_URI)
                .beanRef("serv", "method");

is here possibility how to wrap in and call like one part? e.g.:

from("uri").unmashal...callCommonPart(parameters) ...marshal



--
View this message in context: http://camel.465427.n5.nabble.com/Is-possible-to-wrap-a-part-of-route-tp5731917.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Is possible to wrap a part of route?

Posted by Raul Kripalani <ra...@evosent.com>.
Yes, if the route definition varies for each route, you are better off
creating a Helper class with static methods that build up whatever route
nodes you need.

Another way is to create a base abstract RouteBuilder class that takes care
of the common route definitions. The per-route arguments are provided by
calling abstract getters (e.g. getParameterA()), for which the concrete
classes provide an implementation returning the value of the parameter.

Regards,

*Raúl Kripalani*
Enterprise Architect, Open Source Integration specialist, Program
Manager | Apache
Camel Committer
http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
http://blog.raulkr.net | twitter: @raulvk

On Fri, May 3, 2013 at 11:50 AM, mdo <ma...@gmail.com> wrote:

> Hello horyna,
>
>
> horyna wrote
> > But how to get the parameters into the route? I dont want to store
> > everything into header, body ...this will grow up the code again
>
> as far as I understood your requirement it boils down to the fact that you
> have a couple of routes that share parts of their route definitions. Let's
> assume you had some from() endpoints with different values to be set for
> the
> header "h".
>
> from("file:///.../a")
> .setHeader("h", constant("a"));
>
> Extract the commons parts to a parameterized method:
> private RouteDefinition callCommonPart(RouteDefinition from, String value)
> {
>         return from.setHeader("h", constant(value));
> }
>
> And you can apply this in your route building like this:
> RouteDefinition from = from("file:///.../a");
> callCommonPart(from, "a");
>
> When doing this you can specify the parameters at time of the route
> definition, you don't have to loop values through header fields.
>
> Doesn't this suffice your requirements?
>
> Regards, mdo.
>
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Is-possible-to-wrap-a-part-of-route-tp5731917p5731964.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Is possible to wrap a part of route?

Posted by mdo <ma...@gmail.com>.
Hello horyna,


horyna wrote
> But how to get the parameters into the route? I dont want to store
> everything into header, body ...this will grow up the code again

as far as I understood your requirement it boils down to the fact that you
have a couple of routes that share parts of their route definitions. Let's
assume you had some from() endpoints with different values to be set for the
header "h".

from("file:///.../a")
.setHeader("h", constant("a"));

Extract the commons parts to a parameterized method: 
private RouteDefinition callCommonPart(RouteDefinition from, String value) {
	return from.setHeader("h", constant(value));
}

And you can apply this in your route building like this:
RouteDefinition from = from("file:///.../a");
callCommonPart(from, "a");

When doing this you can specify the parameters at time of the route
definition, you don't have to loop values through header fields.

Doesn't this suffice your requirements?

Regards, mdo.





--
View this message in context: http://camel.465427.n5.nabble.com/Is-possible-to-wrap-a-part-of-route-tp5731917p5731964.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Is possible to wrap a part of route?

Posted by horyna <ph...@centrum.cz>.
But how to get the parameters into the route? I dont want to store everything
into header, body ...this will grow up the code again



--
View this message in context: http://camel.465427.n5.nabble.com/Is-possible-to-wrap-a-part-of-route-tp5731917p5731946.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Is possible to wrap a part of route?

Posted by Raul Kripalani <ra...@evosent.com>.
Place the common part in it's own route and make it consume from a
Direct endpoint, e.g. direct:common.

Raúl.

On 2 May 2013, at 14:27, horyna <ph...@centrum.cz> wrote:

> We have in lots routes some common part. e.g.:
>
>  .setHeader("h", constant(THIS_IS_VARIOUS_FOR_EVERY_ROUTE))
>                .filter(method("serv", "method").isEqualTo(false))
>                .to(VARIOUS_URI)
>                .beanRef("serv", "method");
>
> is here possibility how to wrap in and call like one part? e.g.:
>
> from("uri").unmashal...callCommonPart(parameters) ...marshal
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Is-possible-to-wrap-a-part-of-route-tp5731917.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Is possible to wrap a part of route?

Posted by mdo <ma...@gmail.com>.
Hey, 


horyna wrote
> is here possibility how to wrap in and call like one part? e.g.:
> 
> from("uri").unmashal...callCommonPart(parameters) ...marshal

yes, you can do something like that:
final ProcessorDefinition<?> processorDefinition = from(...)...process(...)

After that you can continue on the reference to this ProcessorDefinition.
Just have a look at the return values of the route building statements.

Regards, mdo.





--
View this message in context: http://camel.465427.n5.nabble.com/Is-possible-to-wrap-a-part-of-route-tp5731917p5731918.html
Sent from the Camel - Users mailing list archive at Nabble.com.