You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by kalber <Ka...@swslt.com> on 2016/05/05 12:07:54 UTC

Camel 2.17, @Producer works only for select objects ?

Hi,

i'm trying to create managed beans with @Producer, but only for
PropertiesComponent
works. In the example below method prodceProperties works,  produceConfig
not.

Is there a limitation under camel for @Producer ?


@ApplicationScoped
public class TestProducer {

    @Produces
    @Named("prop")
    public PropertiesComponent produceProperties() {
        System.out.println("Produces Properties");
        return null;
    }

    @Produces
    @Named("not-prop1")
    public MyBean produceConfig() {
        System.out.println("Not Properties");
        return null;
    }

}



-----
kh
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-2-17-Producer-works-only-for-select-objects-tp5782226.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel 2.17, @Producer works only for select objects ?

Posted by kalber <Ka...@swslt.com>.
Thanks,

it's not a camel problem but simply my CDI ignorance.

MyBean is never used or better Injected, consequence producer is not
triggerd.

Now i understand what's lazy loading is in CDI.




-----
kh
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-2-17-Producer-works-only-for-select-objects-tp5782226p5782279.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel 2.17, @Producer works only for select objects ?

Posted by Antonin Stefanutti <an...@stefanutti.fr>.
> On 06 May 2016, at 10:21, kalber <Ka...@swslt.com> wrote:
> 
> -- In your example below, what exactly does not work with the produceConfig
> producer method?
> Simply 'System.out.println("Not Properties")'  not executed.

CDI beans are lazy-produced, that is the producer methods are only executed if instances of those beans are requested.

This works for the PropertiesComponent because the Camel context requests an instance of that bean at start time.

So in your example, where is the @Named("not-prop1") bean actually used? If it is reference in a Camel route, then it’ll be called when the route starts.

> -- Is it normal that the method return null? 
> It's only a test, wanna see if ' 'System.out.println("Not Properties")'
> works.
> 
> So there is a limitation, only referenced object can be produced.

That is the way CDI works. Beans are lazy instantiated, hence @Produces methods are called only if the beans need to be instantiated.

> Wy this limitation, e need to produce auxiliary beans for processing.
> 
> How can i make My Bean reference ?

There are ways to have beans eagerly instantiated, though that’s more a CDI question than a Camel question.

Maybe you could share your Camel CDI example so that we can help further.

Antonin

> -----
> kh
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-2-17-Producer-works-only-for-select-objects-tp5782226p5782265.html
> Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Camel 2.17, @Producer works only for select objects ?

Posted by kalber <Ka...@swslt.com>.
-- In your example below, what exactly does not work with the produceConfig
producer method?
Simply 'System.out.println("Not Properties")'  not executed.
-- Is it normal that the method return null? 
It's only a test, wanna see if ' 'System.out.println("Not Properties")'
works.

So there is a limitation, only referenced object can be produced.

Wy this limitation, e need to produce auxiliary beans for processing.

How can i make My Bean reference ?




-----
kh
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-2-17-Producer-works-only-for-select-objects-tp5782226p5782265.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel 2.17, @Producer works only for select objects ?

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

You can declare any kind of beans with @Produces. Whenever Camel looks up for a named bean via the Camel registry, it will retrieve a reference to the corresponding named bean declared with @Produces.

In your example below, what exactly does not work with the produceConfig producer method? Is it normal that the method return null? Note that the producer method will actually be invoked only if a reference to it is needed, for example if a Camel route refers to it.

Antonin

> On 05 May 2016, at 14:07, kalber <Ka...@swslt.com> wrote:
> 
> Hi,
> 
> i'm trying to create managed beans with @Producer, but only for
> PropertiesComponent
> works. In the example below method prodceProperties works,  produceConfig
> not.
> 
> Is there a limitation under camel for @Producer ?
> 
> 
> @ApplicationScoped
> public class TestProducer {
> 
>    @Produces
>    @Named("prop")
>    public PropertiesComponent produceProperties() {
>        System.out.println("Produces Properties");
>        return null;
>    }
> 
>    @Produces
>    @Named("not-prop1")
>    public MyBean produceConfig() {
>        System.out.println("Not Properties");
>        return null;
>    }
> 
> }
> 
> 
> 
> -----
> kh
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-2-17-Producer-works-only-for-select-objects-tp5782226.html
> Sent from the Camel - Users mailing list archive at Nabble.com.