camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: How to instanciate a bean in camel registry for use with @produce annotation
Date Mon, 06 Jul 2015 11:26:43 GMT
Refer to it by its name, and use beanRef

.beanRef("dtsm", "normalize")

On Mon, Jul 6, 2015 at 12:36 PM, Benjamin Legendre <jeff58@free.fr> wrote:
> Hi,
> I'm using Camel 2.15.2 inside a stand alone java application.
>
> I do not figure how to add a bean in the Camel context in order to inject a ProducerTemplate
using @Produce on a property of my bean.
> I my scenario The producer is not injected.
>
>
> Here is the bean binding:
>
>         SimpleRegistry registry = new SimpleRegistry();
>         registry.put("dtsm", new DigitalTimeSeriesNormalizer());
>         CamelContext context = new DefaultCamelContext(registry);
>
>
> The bean is then called like this is the route:
>
>         .beanRef("dtsm", "normalize")
>
>
> Here is the code inside the bean:
>
> public class DigitalTimeSeriesNormalizer {
>
>     @Produce
>     public ProducerTemplate producerTemplate;
>
>     [...]
>
>     public ArrayList<TimeSerie> normalize(ArrayList<TimeSerie> timeSeries)
{
>
>          this.producerTemplate // is null here
>
>     [...]
> }
>
> It works when i use this syntax:
>
> .bean(DigitalTimeSeriesNormalizer.class, "normalize")
>
> But it is not what i want because a new instance of the bean is created each time it
is called on the route.
> If this is the only way to make it to work, is there a way to make camel instanciate
it only one time and use a reference of the bean the next time ?
>
> Thanks in advance.
> Benjamin



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Mime
View raw message