Quantcast

karaf/osgi start dependencies

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

karaf/osgi start dependencies

Jason
Hi all,

I have an application that uses Apache ActiveMQ in Karaf.  I have a
broker project and multiple other projects that should depend on the
broker service to be started.  How do I specify in the maven pom
(maven-bundle-plugin) that the child projects should wait until the
broker is started?

Thanks,
Jason
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: karaf/osgi start dependencies

jbonofre
Hi Jason,

Using a feature, you can define the start-level of the bundles in the
feature.

Regards
JB

On 04/25/2012 05:12 PM, Jason wrote:

> Hi all,
>
> I have an application that uses Apache ActiveMQ in Karaf. I have a
> broker project and multiple other projects that should depend on the
> broker service to be started. How do I specify in the maven pom
> (maven-bundle-plugin) that the child projects should wait until the
> broker is started?
>
> Thanks,
> Jason

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: karaf/osgi start dependencies

Achim Nierbeck
Never the less you shouldn't rely on the startlevels,
I suggest that your application waits on services provided by the
ActiveMQ broker.
This is far more safe and more OSGi like ;)

regards, Achim

2012/4/25 Jean-Baptiste Onofré <[hidden email]>:

> Hi Jason,
>
> Using a feature, you can define the start-level of the bundles in the
> feature.
>
> Regards
> JB
>
>
> On 04/25/2012 05:12 PM, Jason wrote:
>>
>> Hi all,
>>
>> I have an application that uses Apache ActiveMQ in Karaf. I have a
>> broker project and multiple other projects that should depend on the
>> broker service to be started. How do I specify in the maven pom
>> (maven-bundle-plugin) that the child projects should wait until the
>> broker is started?
>>
>> Thanks,
>> Jason
>
>
> --
> Jean-Baptiste Onofré
> [hidden email]
> http://blog.nanthrax.net
> Talend - http://www.talend.com



--

Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/>
Committer & Project Lead
blog <http://notizblog.nierbeck.de/>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: karaf/osgi start dependencies

jbonofre
Agree Achim, however, I'm not sure that ActiveMQ register a service per
queue or topic for instance (only for the broker).

Regards
JB

On 04/25/2012 05:18 PM, Achim Nierbeck wrote:

> Never the less you shouldn't rely on the startlevels,
> I suggest that your application waits on services provided by the
> ActiveMQ broker.
> This is far more safe and more OSGi like ;)
>
> regards, Achim
>
> 2012/4/25 Jean-Baptiste Onofré<[hidden email]>:
>> Hi Jason,
>>
>> Using a feature, you can define the start-level of the bundles in the
>> feature.
>>
>> Regards
>> JB
>>
>>
>> On 04/25/2012 05:12 PM, Jason wrote:
>>>
>>> Hi all,
>>>
>>> I have an application that uses Apache ActiveMQ in Karaf. I have a
>>> broker project and multiple other projects that should depend on the
>>> broker service to be started. How do I specify in the maven pom
>>> (maven-bundle-plugin) that the child projects should wait until the
>>> broker is started?
>>>
>>> Thanks,
>>> Jason
>>
>>
>> --
>> Jean-Baptiste Onofré
>> [hidden email]
>> http://blog.nanthrax.net
>> Talend - http://www.talend.com
>
>
>

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: karaf/osgi start dependencies

Guillaume Nodet
No, but depending on the configuration it may expose a JMSCOnnectionFactory which can be obtained from the OSGi registry.

On Wed, Apr 25, 2012 at 17:30, Jean-Baptiste Onofré <[hidden email]> wrote:
Agree Achim, however, I'm not sure that ActiveMQ register a service per queue or topic for instance (only for the broker).

Regards
JB


On 04/25/2012 05:18 PM, Achim Nierbeck wrote:
Never the less you shouldn't rely on the startlevels,
I suggest that your application waits on services provided by the
ActiveMQ broker.
This is far more safe and more OSGi like ;)

regards, Achim

2012/4/25 Jean-Baptiste Onofré<[hidden email]>:
Hi Jason,

Using a feature, you can define the start-level of the bundles in the
feature.

Regards
JB


On 04/25/2012 05:12 PM, Jason wrote:

Hi all,

I have an application that uses Apache ActiveMQ in Karaf. I have a
broker project and multiple other projects that should depend on the
broker service to be started. How do I specify in the maven pom
(maven-bundle-plugin) that the child projects should wait until the
broker is started?

Thanks,
Jason


--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com




--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com



--
------------------------
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
FuseSource, Integration everywhere
http://fusesource.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: karaf/osgi start dependencies

cschneider
Yes.

Referencing the connection factory that ActiveMQ publishes as an OSGi service is the best way to setup jms in Karaf anyway.

Christian

Am 25.04.2012 17:35, schrieb Guillaume Nodet:
No, but depending on the configuration it may expose a JMSCOnnectionFactory which can be obtained from the OSGi registry.

On Wed, Apr 25, 2012 at 17:30, Jean-Baptiste Onofré <[hidden email]> wrote:
Agree Achim, however, I'm not sure that ActiveMQ register a service per queue or topic for instance (only for the broker).

Regards
JB


On 04/25/2012 05:18 PM, Achim Nierbeck wrote:
Never the less you shouldn't rely on the startlevels,
I suggest that your application waits on services provided by the
ActiveMQ broker.
This is far more safe and more OSGi like ;)

regards, Achim

2012/4/25 Jean-Baptiste Onofré<[hidden email]>:
Hi Jason,

Using a feature, you can define the start-level of the bundles in the
feature.

Regards
JB


On 04/25/2012 05:12 PM, Jason wrote:

Hi all,

I have an application that uses Apache ActiveMQ in Karaf. I have a
broker project and multiple other projects that should depend on the
broker service to be started. How do I specify in the maven pom
(maven-bundle-plugin) that the child projects should wait until the
broker is started?

Thanks,
Jason


--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com




--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com



--
------------------------
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
FuseSource, Integration everywhere
http://fusesource.com


-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
Talend Application Integration Division http://www.talend.com 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: karaf/osgi start dependencies

jbonofre
Agree, but the connection factory can be exposed independently (for
instance,  the connection factory is deployed in a blueprint descriptor
using Aries, some not in the broker XML) from the broker, and the same
connection factory can be used for different topic/queue.

So even it's a perfect solution, it works ;)

Regards
JB

On 04/25/2012 05:44 PM, Christian Schneider wrote:

> Yes.
>
> Referencing the connection factory that ActiveMQ publishes as an OSGi
> service is the best way to setup jms in Karaf anyway.
>
> Christian
>
> Am 25.04.2012 17:35, schrieb Guillaume Nodet:
>> No, but depending on the configuration it may expose a
>> JMSCOnnectionFactory which can be obtained from the OSGi registry.
>>
>> On Wed, Apr 25, 2012 at 17:30, Jean-Baptiste Onofré <[hidden email]
>> <mailto:[hidden email]>> wrote:
>>
>>     Agree Achim, however, I'm not sure that ActiveMQ register a
>>     service per queue or topic for instance (only for the broker).
>>
>>     Regards
>>     JB
>>
>>
>>     On 04/25/2012 05:18 PM, Achim Nierbeck wrote:
>>
>>         Never the less you shouldn't rely on the startlevels,
>>         I suggest that your application waits on services provided by the
>>         ActiveMQ broker.
>>         This is far more safe and more OSGi like ;)
>>
>>         regards, Achim
>>
>>         2012/4/25 Jean-Baptiste Onofré<[hidden email]
>>         <mailto:[hidden email]>>:
>>
>>             Hi Jason,
>>
>>             Using a feature, you can define the start-level of the
>>             bundles in the
>>             feature.
>>
>>             Regards
>>             JB
>>
>>
>>             On 04/25/2012 05:12 PM, Jason wrote:
>>
>>
>>                 Hi all,
>>
>>                 I have an application that uses Apache ActiveMQ in
>>                 Karaf. I have a
>>                 broker project and multiple other projects that should
>>                 depend on the
>>                 broker service to be started. How do I specify in the
>>                 maven pom
>>                 (maven-bundle-plugin) that the child projects should
>>                 wait until the
>>                 broker is started?
>>
>>                 Thanks,
>>                 Jason
>>
>>
>>
>>             --
>>             Jean-Baptiste Onofré
>>             [hidden email] <mailto:[hidden email]>
>>             http://blog.nanthrax.net
>>             Talend - http://www.talend.com
>>
>>
>>
>>
>>
>>     --
>>     Jean-Baptiste Onofré
>>     [hidden email] <mailto:[hidden email]>
>>     http://blog.nanthrax.net
>>     Talend - http://www.talend.com
>>
>>
>>
>>
>> --
>> ------------------------
>> Guillaume Nodet
>> ------------------------
>> Blog: http://gnodet.blogspot.com/
>> ------------------------
>> FuseSource, Integration everywhere
>> http://fusesource.com
>
>
> --
> Christian Schneider
> http://www.liquid-reality.de
>
> Open Source Architect
> Talend Application Integration Divisionhttp://www.talend.com
>

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: karaf/osgi start dependencies

Jason
In reply to this post by cschneider
Hi all,

Thanks for the quick feedback. 

FWIW, the broker is registered as a service (javax.jms.ConnectionFactory). 

My child projects get the ConnectionFactory from the BundleContext within the BundleActivator.start(BundleContext) method of my Activator and attach a MessageListener to a queue.  I am using "features"  and I set the child project's start-levels to 100.  The start level of the broker is 80.  The first time I start Karaf, everything starts up perfect....no exceptions.  Then I shutdown the container, and start it up again.  Upon startup for the second time, I get the following exceptions per child project:

(org.osgi.framework.BundleException: Activator start error in bundle xxxx [258].)
javax.jms.JMSException: Could not connect to broker URL: tcp://0.0.0.0:61616. Reason: java.net.ConnectException: Connection refused

When I get the prompt and type "start 258", it starts cleanly.

This suggests to me Achim's claim to not rely on start levels seems to have merit. 

So, what is the best way to ensure that a parent service is started?  Ought I check for the connectionexception and just loop until the broker starts up and I can get a valid connection?

Thanks,
Jason

On 04/25/2012 11:44 AM, Christian Schneider wrote:
Yes.

Referencing the connection factory that ActiveMQ publishes as an OSGi service is the best way to setup jms in Karaf anyway.

Christian

Am 25.04.2012 17:35, schrieb Guillaume Nodet:
No, but depending on the configuration it may expose a JMSCOnnectionFactory which can be obtained from the OSGi registry.

On Wed, Apr 25, 2012 at 17:30, Jean-Baptiste Onofré <[hidden email]> wrote:
Agree Achim, however, I'm not sure that ActiveMQ register a service per queue or topic for instance (only for the broker).

Regards
JB


On 04/25/2012 05:18 PM, Achim Nierbeck wrote:
Never the less you shouldn't rely on the startlevels,
I suggest that your application waits on services provided by the
ActiveMQ broker.
This is far more safe and more OSGi like ;)

regards, Achim

2012/4/25 Jean-Baptiste Onofré<[hidden email]>:
Hi Jason,

Using a feature, you can define the start-level of the bundles in the
feature.

Regards
JB


On 04/25/2012 05:12 PM, Jason wrote:

Hi all,

I have an application that uses Apache ActiveMQ in Karaf. I have a
broker project and multiple other projects that should depend on the
broker service to be started. How do I specify in the maven pom
(maven-bundle-plugin) that the child projects should wait until the
broker is started?

Thanks,
Jason


--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com




--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com



--
------------------------
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
FuseSource, Integration everywhere
http://fusesource.com


-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
Talend Application Integration Division http://www.talend.com 

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: karaf/osgi start dependencies

cschneider
You have to have an Import-Service statement in the Manifest for the dependency to be recognized by the OSGi framework.
I reference my services using blueprint and use the maven bundle plugin. So a suitable entry gets generated automatically. If you
use an Activator you will have to manually add the Manifest entry.

Christian

Am 25.04.2012 18:08, schrieb Jason:
Hi all,

Thanks for the quick feedback. 

FWIW, the broker is registered as a service (javax.jms.ConnectionFactory). 

My child projects get the ConnectionFactory from the BundleContext within the BundleActivator.start(BundleContext) method of my Activator and attach a MessageListener to a queue.  I am using "features"  and I set the child project's start-levels to 100.  The start level of the broker is 80.  The first time I start Karaf, everything starts up perfect....no exceptions.  Then I shutdown the container, and start it up again.  Upon startup for the second time, I get the following exceptions per child project:

(org.osgi.framework.BundleException: Activator start error in bundle xxxx [258].)
javax.jms.JMSException: Could not connect to broker URL: tcp://0.0.0.0:61616. Reason: java.net.ConnectException: Connection refused

When I get the prompt and type "start 258", it starts cleanly.

This suggests to me Achim's claim to not rely on start levels seems to have merit. 

So, what is the best way to ensure that a parent service is started?  Ought I check for the connectionexception and just loop until the broker starts up and I can get a valid connection?

Thanks,
Jason

On 04/25/2012 11:44 AM, Christian Schneider wrote:
Yes.

Referencing the connection factory that ActiveMQ publishes as an OSGi service is the best way to setup jms in Karaf anyway.

Christian

Am 25.04.2012 17:35, schrieb Guillaume Nodet:
No, but depending on the configuration it may expose a JMSCOnnectionFactory which can be obtained from the OSGi registry.

On Wed, Apr 25, 2012 at 17:30, Jean-Baptiste Onofré <[hidden email]> wrote:
Agree Achim, however, I'm not sure that ActiveMQ register a service per queue or topic for instance (only for the broker).

Regards
JB


On 04/25/2012 05:18 PM, Achim Nierbeck wrote:
Never the less you shouldn't rely on the startlevels,
I suggest that your application waits on services provided by the
ActiveMQ broker.
This is far more safe and more OSGi like ;)

regards, Achim

2012/4/25 Jean-Baptiste Onofré<[hidden email]>:
Hi Jason,

Using a feature, you can define the start-level of the bundles in the
feature.

Regards
JB


On 04/25/2012 05:12 PM, Jason wrote:

Hi all,

I have an application that uses Apache ActiveMQ in Karaf. I have a
broker project and multiple other projects that should depend on the
broker service to be started. How do I specify in the maven pom
(maven-bundle-plugin) that the child projects should wait until the
broker is started?

Thanks,
Jason


--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com




--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com



--
------------------------
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
FuseSource, Integration everywhere
http://fusesource.com


-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
Talend Application Integration Division http://www.talend.com 



-- 
 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
Talend Application Integration Division http://www.talend.com 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: karaf/osgi start dependencies

cschneider
I just talked to Jean-Baptiste about the problem. We agreed that Import-Service may help to pull up the bundle offering the service but it may still
not be ready in time.

So the real solution is to use blueprint service reference (set to mandatory) or a ServiceTracker. The idea with both is that you only really start your code when the service comes up
and that you also shut down when the service goes down. Blueprint is by far the easiest solution as it will do it for you.

Christian

Am 25.04.2012 22:41, schrieb Christian Schneider:
You have to have an Import-Service statement in the Manifest for the dependency to be recognized by the OSGi framework.
I reference my services using blueprint and use the maven bundle plugin. So a suitable entry gets generated automatically. If you
use an Activator you will have to manually add the Manifest entry.

Christian


-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
Talend Application Integration Division http://www.talend.com 
Loading...