Spring Bean init vs Camel Context Running status

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Spring Bean init vs Camel Context Running status

fabryprog
I have a problem with spring bean init and camel context (spring) running
status.

My software has a declared bean:

<bean id="beanA" class="com.mycompany.fabryprog.BeanA" init-method="init" />

Inside the bean i write follow code:

public class BeanA  {
    @EndpointInject(uri="seda://sendNotify")
    private ProducerTemplate notifier;
    ..........
           public void init() {
                     notifier.requestBody("I love Apache camel");
           }
    }
}

When i start my application context i have an error because apache camel
route *seda://sendNotify* isn't still deployed jet

Can i have a method to known when spring camel context is running out?

I suppose to use another spring bean and insert it into depends-on bean
attribute. Is it correct way to solve my problem?

Kings Regard

Fabrizio Spataro
Reply | Threaded
Open this post in threaded view
|

Re: Spring Bean init vs Camel Context Running status

lburgazzoli
Hi,

you can define an EventNotifier bean to be informed about various
events that happens in camel among which the startup of the context.


---
Luca Burgazzoli

On Fri, Sep 28, 2018 at 11:13 AM FabryProg <[hidden email]> wrote:

>
> I have a problem with spring bean init and camel context (spring) running
> status.
>
> My software has a declared bean:
>
> <bean id="beanA" class="com.mycompany.fabryprog.BeanA" init-method="init" />
>
> Inside the bean i write follow code:
>
> public class BeanA  {
>     @EndpointInject(uri="seda://sendNotify")
>     private ProducerTemplate notifier;
>     ..........
>            public void init() {
>                      notifier.requestBody("I love Apache camel");
>            }
>     }
> }
>
> When i start my application context i have an error because apache camel
> route *seda://sendNotify* isn't still deployed jet
>
> Can i have a method to known when spring camel context is running out?
>
> I suppose to use another spring bean and insert it into depends-on bean
> attribute. Is it correct way to solve my problem?
>
> Kings Regard
>
> Fabrizio Spataro
Reply | Threaded
Open this post in threaded view
|

Re: Spring Bean init vs Camel Context Running status

fabryprog
So i must remove init method, define an event (using spring) and handle it
from a route defined into camel context.

is it correct?

Il giorno ven 28 set 2018 alle ore 11:19 Luca Burgazzoli <
[hidden email]> ha scritto:

> Hi,
>
> you can define an EventNotifier bean to be informed about various
> events that happens in camel among which the startup of the context.
>
>
> ---
> Luca Burgazzoli
>
> On Fri, Sep 28, 2018 at 11:13 AM FabryProg <[hidden email]> wrote:
> >
> > I have a problem with spring bean init and camel context (spring) running
> > status.
> >
> > My software has a declared bean:
> >
> > <bean id="beanA" class="com.mycompany.fabryprog.BeanA"
> init-method="init" />
> >
> > Inside the bean i write follow code:
> >
> > public class BeanA  {
> >     @EndpointInject(uri="seda://sendNotify")
> >     private ProducerTemplate notifier;
> >     ..........
> >            public void init() {
> >                      notifier.requestBody("I love Apache camel");
> >            }
> >     }
> > }
> >
> > When i start my application context i have an error because apache camel
> > route *seda://sendNotify* isn't still deployed jet
> >
> > Can i have a method to known when spring camel context is running out?
> >
> > I suppose to use another spring bean and insert it into depends-on bean
> > attribute. Is it correct way to solve my problem?
> >
> > Kings Regard
> >
> > Fabrizio Spataro
>
Reply | Threaded
Open this post in threaded view
|

Re: Spring Bean init vs Camel Context Running status

Claus Ibsen-2
In reply to this post by fabryprog
You can also try with setting depends-in="camelIdName" on your <bean>
to have this bean depend on camel context.

Then you need to set the id of "camelContext> to match that name.

But as Luca says the event notifier is the listeners in camel where
you can get events for startup/stopping and so on.

On Fri, Sep 28, 2018 at 11:13 AM FabryProg <[hidden email]> wrote:

>
> I have a problem with spring bean init and camel context (spring) running
> status.
>
> My software has a declared bean:
>
> <bean id="beanA" class="com.mycompany.fabryprog.BeanA" init-method="init" />
>
> Inside the bean i write follow code:
>
> public class BeanA  {
>     @EndpointInject(uri="seda://sendNotify")
>     private ProducerTemplate notifier;
>     ..........
>            public void init() {
>                      notifier.requestBody("I love Apache camel");
>            }
>     }
> }
>
> When i start my application context i have an error because apache camel
> route *seda://sendNotify* isn't still deployed jet
>
> Can i have a method to known when spring camel context is running out?
>
> I suppose to use another spring bean and insert it into depends-on bean
> attribute. Is it correct way to solve my problem?
>
> Kings Regard
>
> Fabrizio Spataro



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2