You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by a746076drdrb <a7...@drdrb.net> on 2016/10/13 07:53:32 UTC

cdi reuse the route

Hello,

I have a few question hot to use CDI routes. With spring xml it was easy to
reuse routes and separate them into context. Is it also possible to use the
same route twice with CDI but with diffrent config and maybe in difftent
contexts? 

Is it possible to disable routes per configuration?

Thanks!



--
View this message in context: http://camel.465427.n5.nabble.com/cdi-reuse-the-route-tp5788716.html
Sent from the Camel Development mailing list archive at Nabble.com.

Re: cdi reuse the route

Posted by Antonin Stefanutti <an...@stefanutti.fr>.
That should be fine with that version of Weld. Though I realise for it to work the qualifier need to be annotated with @Repeatable, which is missing. I’ve just created https://issues.apache.org/jira/browse/CAMEL-10464. I’ll work on it ASAP. In the meantime, you should be able to achieve the same effect using your own repeating qualifiers.

Antonin

> On 10 Nov 2016, at 12:06, a746076drdrb <a7...@drdrb.net> wrote:
> 
> I'm using 
>            <groupId>org.jboss.weld.se</groupId>                                                                       
>            <artifactId>weld-se</artifactId>                                                                           
>            <version>2.4.0.Final</version>                                                                             
> 
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/cdi-reuse-the-route-tp5788716p5789998.html
> Sent from the Camel Development mailing list archive at Nabble.com.


Re: cdi reuse the route

Posted by a746076drdrb <a7...@drdrb.net>.
I'm using 
            <groupId>org.jboss.weld.se</groupId>                                                                       
            <artifactId>weld-se</artifactId>                                                                           
            <version>2.4.0.Final</version>                                                                             




--
View this message in context: http://camel.465427.n5.nabble.com/cdi-reuse-the-route-tp5788716p5789998.html
Sent from the Camel Development mailing list archive at Nabble.com.

Re: cdi reuse the route

Posted by Antonin Stefanutti <an...@stefanutti.fr>.
Hi,

What CDI runtime are you using? It may be that some older runtimes do not support this. It has been discussed and is tracked in https://issues.jboss.org/browse/CDI-471 though some Weld versions already support it.

Antonin

> On 10 Nov 2016, at 09:59, a746076drdrb <a7...@drdrb.net> wrote:
> 
> Hi Antonin,
> 
> thanks a lot for help! I tried to play with it and get: ContextName is not
> repeatable annotation type.
> 
> Are there any working examples using the same cdi route twice?
> 
> Cheerz!
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/cdi-reuse-the-route-tp5788716p5789985.html
> Sent from the Camel Development mailing list archive at Nabble.com.


Re: cdi reuse the route

Posted by a746076drdrb <a7...@drdrb.net>.
Hi Antonin,

thanks a lot for help! I tried to play with it and get: ContextName is not
repeatable annotation type.

Are there any working examples using the same cdi route twice?

Cheerz!



--
View this message in context: http://camel.465427.n5.nabble.com/cdi-reuse-the-route-tp5788716p5789985.html
Sent from the Camel Development mailing list archive at Nabble.com.

Re: cdi reuse the route

Posted by Antonin Stefanutti <an...@stefanutti.fr>.
Hi,

There are multiple ways to achieve sharing routes across contexts in CDI. Maybe the most simple example could be the following one:

@ContextName("foo")
@ContextName("bar")
class MySharedRouteBuilder extends RouteBuilder {

}

@ApplicationScoped
@ContextName("foo")
class FooCamelContext extends DefaultCamelContext {
}


@ApplicationScoped
@ContextName("bar")
class BarCamelContext extends DefaultCamelContext {
}

In that example you’ll get two Camel contexts auto-configured with the same RouteBuilder, which can be configured depending on each context properties configuration sources. There are probably a couple of other ways to achieve reuse though that first example should help you get started.

As you mention Spring XML, starting Camel 2.18.0, Camel CDI can import Camel XML files as documented in [1]. You can find an example in [2]. This may be useful to leverage existing routeContext and routeContextRef elements.

Hope that helps.

[1]: http://camel.apache.org/cdi.html#CDI-CamelXMLconfigurationimport
[2]: https://github.com/apache/camel/tree/master/examples/camel-example-cdi-xml

Antonin

> On 13 Oct 2016, at 09:53, a746076drdrb <a7...@drdrb.net> wrote:
> 
> Hello,
> 
> I have a few question hot to use CDI routes. With spring xml it was easy to
> reuse routes and separate them into context. Is it also possible to use the
> same route twice with CDI but with diffrent config and maybe in difftent
> contexts? 
> 
> Is it possible to disable routes per configuration?
> 
> Thanks!
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/cdi-reuse-the-route-tp5788716.html
> Sent from the Camel Development mailing list archive at Nabble.com.