git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Is it possible to use request scoped beans with Camel CDI ?


Hello,

First, thanks for the great framework.

Second, I am kind of new to Apache Camel and I have a question regarding
bean integration.

Is it possible to use request scoped beans with Camel CDI ?

I am using Camel CDI with Weld (Java DSL without Spring).

The pattern I am trying to implement is synchronous request response using
parallel split-join to enrich my message before replying:

from("jetty:http://localhost:8280/metrics";)
.to("http://localhost:10542/api/public/simulations?bridgeEndpoint=true";)
.split().jsonpath("$").parallelProcessing()
.setBody().jsonpath("$.id")
// My call to third service would be there
.bean(MyBean.class, "addItem")
.end()
.bean(MyBean.class, "items")
.end();

Without CDI scope annotation on MyBean class:
- a first instance is created and shared for every parallel calls
(MyBean.addItem method binding)
- a second instance is created at the end of the main route (MyBean.items
method binding)

Of course I want to retrieve items added by every parallel calls.

With singleton scope qualifier, it is working but shared by every calls to
the main route (see Jetty /metrics endpoint).

I need a way to share a "request" instance of my bean between the main
route and the parallel (sub)routes but a new instance must be created for
each call to the main route. @RequestScoped annotation
throws ContextNotActiveException.

Is it possible ?

I tried using exchange properties but they are not shared between the main
route and the parallel (sub)routes.

Also, I had a look to camel examples but couldn't figure it out.

Thanks.

Best regards,

Julien


( ! ) Warning: include(msgfooter.php): failed to open stream: No such file or directory in /var/www/git/apache-camel-users/msg03388.html on line 120
Call Stack
#TimeMemoryFunctionLocation
10.0335364600{main}( ).../msg03388.html:0

( ! ) Warning: include(): Failed opening 'msgfooter.php' for inclusion (include_path='.:/var/www/git') in /var/www/git/apache-camel-users/msg03388.html on line 120
Call Stack
#TimeMemoryFunctionLocation
10.0335364600{main}( ).../msg03388.html:0