You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Jason <jd...@renci.org> on 2012/04/25 17:12:24 UTC

karaf/osgi start dependencies

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

Re: karaf/osgi start dependencies

Posted by Christian Schneider <ch...@die-schneider.net>.
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


Re: karaf/osgi start dependencies

Posted by Christian Schneider <ch...@die-schneider.net>.
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é <jb@nanthrax.net 
>>> <ma...@nanthrax.net>> 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é<jb@nanthrax.net
>>>         <ma...@nanthrax.net>>:
>>>
>>>             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é
>>>             jbonofre@apache.org <ma...@apache.org>
>>>             http://blog.nanthrax.net
>>>             Talend - http://www.talend.com
>>>
>>>
>>>
>>>
>>>
>>>     -- 
>>>     Jean-Baptiste Onofré
>>>     jbonofre@apache.org <ma...@apache.org>
>>>     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  
>


-- 

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

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


Re: karaf/osgi start dependencies

Posted by Jason <jd...@renci.org>.
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é <jb@nanthrax.net 
>> <ma...@nanthrax.net>> 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é<jb@nanthrax.net
>>         <ma...@nanthrax.net>>:
>>
>>             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é
>>             jbonofre@apache.org <ma...@apache.org>
>>             http://blog.nanthrax.net
>>             Talend - http://www.talend.com
>>
>>
>>
>>
>>
>>     -- 
>>     Jean-Baptiste Onofré
>>     jbonofre@apache.org <ma...@apache.org>
>>     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  


Re: karaf/osgi start dependencies

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
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é <jb@nanthrax.net
>> <ma...@nanthrax.net>> 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é<jb@nanthrax.net
>>         <ma...@nanthrax.net>>:
>>
>>             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é
>>             jbonofre@apache.org <ma...@apache.org>
>>             http://blog.nanthrax.net
>>             Talend - http://www.talend.com
>>
>>
>>
>>
>>
>>     --
>>     Jean-Baptiste Onofré
>>     jbonofre@apache.org <ma...@apache.org>
>>     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é
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: karaf/osgi start dependencies

Posted by Christian Schneider <ch...@die-schneider.net>.
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é <jb@nanthrax.net 
> <ma...@nanthrax.net>> 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é<jb@nanthrax.net
>         <ma...@nanthrax.net>>:
>
>             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é
>             jbonofre@apache.org <ma...@apache.org>
>             http://blog.nanthrax.net
>             Talend - http://www.talend.com
>
>
>
>
>
>     -- 
>     Jean-Baptiste Onofré
>     jbonofre@apache.org <ma...@apache.org>
>     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


Re: karaf/osgi start dependencies

Posted by Guillaume Nodet <gn...@gmail.com>.
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é <jb...@nanthrax.net> 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é<jb...@nanthrax.net>:
>>
>>> 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é
>>> jbonofre@apache.org
>>> http://blog.nanthrax.net
>>> Talend - http://www.talend.com
>>>
>>
>>
>>
>>
> --
> Jean-Baptiste Onofré
> jbonofre@apache.org
> http://blog.nanthrax.net
> Talend - http://www.talend.com
>



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

Re: karaf/osgi start dependencies

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
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é<jb...@nanthrax.net>:
>> 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é
>> jbonofre@apache.org
>> http://blog.nanthrax.net
>> Talend - http://www.talend.com
>
>
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: karaf/osgi start dependencies

Posted by Achim Nierbeck <bc...@googlemail.com>.
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é <jb...@nanthrax.net>:
> 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é
> jbonofre@apache.org
> 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/>

Re: karaf/osgi start dependencies

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
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é
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com