You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Pascal Schumacher <pa...@gmx.net> on 2017/11/08 19:24:45 UTC

Spring - Create Bean after Camel Context is started

Hello everybody,

using camel 2.20 with spring 5.0.1 and need to start another component (defined as spring bean) after camel context has started. I added 'depends-on="camelContextId"' to the other beans spring xml definition, but this has a no effect as the camel context is starting asynchronously.

Any ideas how to solve this?

Thanks and kind regards,

Pascal


AW: AW: Spring - Create Bean after Camel Context is started

Posted by Michael Lück <mi...@hm-ag.de>.
Could you add some endpoint like direct (failIfNoConsumers=false), vm, seda or activmq beween the routes that want to sent to your component and the route that consumes your component?

Consuming Endpoints                                                                                         Your Component Endpoint
| ----------------------------------------------------------------------------------------------|

=>
Consuming Endpoints                            (direct,vm,seda,activemq)                 Your Component Endpoint
|-------------------------------------------------|---------------------------------------------|
             Static route                                            dynamic route

Then the message may stay in that endpoint until a consumer will register on the endpoint.

Michael

> -----Ursprüngliche Nachricht-----
> Von: Pascal Schumacher [mailto:PascalSchumacher@gmx.net]
> Gesendet: Donnerstag, 9. November 2017 10:37
> An: users@camel.apache.org
> Betreff: Aw: AW: Spring - Create Bean after Camel Context is started
> 
> Hi Michael,
> 
> thanks for the response.
> 
> Sorry for not making myself clear. The other component accesses multiple
> camel routes and throws errors if the routes are not started yet, therefore I
> would like spring to start it after the camel context has been started. The
> simplifed spring configuration:
> 
> <beans>
>     <camelContext id="camelContext" />
>     <bean id="componentDependingOnStartedCamelContext" depends-
> on="camelContext" /> </beans>
> 
> Cheers,
> Pascal
> 
> Gesendet: Donnerstag, 09. November 2017 um 07:48 Uhr
> Von: "Michael Lück" <mi...@hm-ag.de>
> An: users@camel.apache.org
> Betreff: AW: Spring - Create Bean after Camel Context is started Hi Pascal,
> 
> perhaps you can encapsulate the call to the bean into a single route builder
> and add that route dynamically to the Camel Context like here:
> https://stackoverflow.com/questions/10451444/add-camel-route-at-
> runtime-in-java
> 
> But I'm not sure if I understood the use case correctly.
> 
> Michael
> 
> > -----Ursprüngliche Nachricht-----
> > Von: Pascal Schumacher [mailto:pascalschumacher@gmx.net]
> > Gesendet: Mittwoch, 8. November 2017 20:25
> > An: users@camel.apache.org
> > Betreff: Spring - Create Bean after Camel Context is started
> >
> > Hello everybody,
> >
> > using camel 2.20 with spring 5.0.1 and need to start another component
> > (defined as spring bean) after camel context has started. I added
> > 'depends- on="camelContextId"' to the other beans spring xml
> > definition, but this has a no effect as the camel context is starting
> asynchronously.
> >
> > Any ideas how to solve this?
> >
> > Thanks and kind regards,
> >
> > Pascal
> 
> 


Aw: AW: Spring - Create Bean after Camel Context is started

Posted by Pascal Schumacher <Pa...@gmx.net>.
Hi Michael,

thanks for the response.

Sorry for not making myself clear. The other component accesses multiple camel routes and throws errors if the routes are not started yet, therefore I would like spring to start it after the camel context has been started. The simplifed spring configuration:

<beans>
    <camelContext id="camelContext" />
    <bean id="componentDependingOnStartedCamelContext" depends-on="camelContext" />
</beans>
 
Cheers,
Pascal 

Gesendet: Donnerstag, 09. November 2017 um 07:48 Uhr
Von: "Michael Lück" <mi...@hm-ag.de>
An: users@camel.apache.org
Betreff: AW: Spring - Create Bean after Camel Context is started
Hi Pascal,

perhaps you can encapsulate the call to the bean into a single route builder and add that route dynamically to the Camel Context like here:
https://stackoverflow.com/questions/10451444/add-camel-route-at-runtime-in-java

But I'm not sure if I understood the use case correctly.

Michael

> -----Ursprüngliche Nachricht-----
> Von: Pascal Schumacher [mailto:pascalschumacher@gmx.net]
> Gesendet: Mittwoch, 8. November 2017 20:25
> An: users@camel.apache.org
> Betreff: Spring - Create Bean after Camel Context is started
>
> Hello everybody,
>
> using camel 2.20 with spring 5.0.1 and need to start another component
> (defined as spring bean) after camel context has started. I added 'depends-
> on="camelContextId"' to the other beans spring xml definition, but this has a
> no effect as the camel context is starting asynchronously.
>
> Any ideas how to solve this?
>
> Thanks and kind regards,
>
> Pascal

 

AW: Spring - Create Bean after Camel Context is started

Posted by Michael Lück <mi...@hm-ag.de>.
Hi Pascal, 

perhaps you can encapsulate the call to the bean into a single route builder and add that route dynamically to the Camel Context like here:
https://stackoverflow.com/questions/10451444/add-camel-route-at-runtime-in-java

But I'm not sure if I understood the use case correctly.

Michael

> -----Ursprüngliche Nachricht-----
> Von: Pascal Schumacher [mailto:pascalschumacher@gmx.net]
> Gesendet: Mittwoch, 8. November 2017 20:25
> An: users@camel.apache.org
> Betreff: Spring - Create Bean after Camel Context is started
> 
> Hello everybody,
> 
> using camel 2.20 with spring 5.0.1 and need to start another component
> (defined as spring bean) after camel context has started. I added 'depends-
> on="camelContextId"' to the other beans spring xml definition, but this has a
> no effect as the camel context is starting asynchronously.
> 
> Any ideas how to solve this?
> 
> Thanks and kind regards,
> 
> Pascal



Re: Spring - Create Bean after Camel Context is started

Posted by Zoran Regvart <zo...@regvart.com>.
Hi Pascal,
I think you'll find StartupListener[1] helpful, there is a
`addStartupListener` method on the CamelContext,

zoran

[1] https://github.com/apache/camel/blob/master/camel-core/src/main/java/org/apache/camel/StartupListener.java

On Wed, Nov 8, 2017 at 8:24 PM, Pascal Schumacher
<pa...@gmx.net> wrote:
> Hello everybody,
>
> using camel 2.20 with spring 5.0.1 and need to start another component
> (defined as spring bean) after camel context has started. I added
> 'depends-on="camelContextId"' to the other beans spring xml definition, but
> this has a no effect as the camel context is starting asynchronously.
>
> Any ideas how to solve this?
>
> Thanks and kind regards,
>
> Pascal
>



-- 
Zoran Regvart