[Karaf 4.0.1] - Reference annotation null instance with javax.jms.ConnectionFactory

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

[Karaf 4.0.1] - Reference annotation null instance with javax.jms.ConnectionFactory

fpapon
Hi,

I'm using SCR to get instance of service like LogService, ConfigurationAdmin and it work well.
I tried to do the same with JMS Factory with the activemq-cf feature and my service can't resolve the ConnectionFactory...

  @Reference
  private LogService logService;

 
  @Reference
  private ConfigurationAdmin configAdmin;

 
  @Reference(target="(osgi.jndi.service.name=jms/activemq-moss)")
  private ConnectionFactory jmsConnectionFactory;


In console :

karaf@root()> service:list ConnectionFactory                                                                                                                                                                                15:48:40
[javax.jms.ConnectionFactory]
-----------------------------
 osgi.jndi.service.name = jms/activemq-moss
 service.bundleid = 38
 service.id = 180
 service.scope = singleton
Provided by :
 activemq-cf (38)


karaf@root()> jndi:names            
JNDI Name                      │ Class Name

osgi:service/jms/activemq-moss │ org.apache.activemq.jms.pool.PooledConnectionFactory
osgi:service/mossorder         │ org.postgresql.jdbc2.optional.SimpleDataSource
osgi:service/jndi              │ org.apache.karaf.jndi.internal.JndiServiceImpl



when installing the feature :

resolution:=mandatory [caused by: Unable to resolve myservice/1.0.0.SNAPSHOT: missing requirement [myservice/1.0.0.SNAPSHOT] osgi.service; filter:="(objectClass=javax.jms.ConnectionFactory)"; effective:=active]]



However, if I do this in the activate method of my service :


jmsConnectionFactory =
          bndContext.getService(bndContext.getServiceReferences(ConnectionFactory.class,
              "(osgi.jndi.service.name=jms/activemq-moss)").iterator().next());


It's work !



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

Re: [Karaf 4.0.1] - Reference annotation null instance with javax.jms.ConnectionFactory

jbonofre
Better here ;)

Your SCR component is immediate ?

Regards
JB

On 07/28/2017 01:55 PM, fpapon wrote:

> Hi,
>
> I'm using SCR to get instance of service like LogService, ConfigurationAdmin
> and it work well.
> I tried to do the same with JMS Factory with the activemq-cf feature and my
> service can't resolve the ConnectionFactory...
>
> *  @Reference
>    private LogService logService;*
>    
> *  @Reference
>    private ConfigurationAdmin configAdmin;*
>    
> *  @Reference(target="(osgi.jndi.service.name=jms/activemq-moss)")
>    private ConnectionFactory jmsConnectionFactory;*
>
> In console :
>
> *karaf@root()> service:list ConnectionFactory
> 15:48:40
> [javax.jms.ConnectionFactory]
> -----------------------------
>   osgi.jndi.service.name = jms/activemq-moss
>   service.bundleid = 38
>   service.id = 180
>   service.scope = singleton
> Provided by :
>   activemq-cf (38)
>
> *karaf@root()> jndi:names
> JNDI Name                      │ Class Name
>
> osgi:service/jms/activemq-moss │
> org.apache.activemq.jms.pool.PooledConnectionFactory
> osgi:service/mossorder         │
> org.postgresql.jdbc2.optional.SimpleDataSource
> osgi:service/jndi              │
> org.apache.karaf.jndi.internal.JndiServiceImpl*
>
>
> when installing the feature :
> *
> resolution:=mandatory [caused by: Unable to resolve
> myservice/1.0.0.SNAPSHOT: missing requirement [myservice/1.0.0.SNAPSHOT]
> osgi.service; filter:="(objectClass=javax.jms.ConnectionFactory)";
> effective:=active]]*
>
>
> However, if I do this in the activate method of my service :
>
> *
> jmsConnectionFactory =
>          
> bndContext.getService(bndContext.getServiceReferences(ConnectionFactory.class,
>              
> "(osgi.jndi.service.name=jms/activemq-moss)").iterator().next());*
>
> It's work !
>
>
>
>
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Karaf-4-0-1-Reference-annotation-null-instance-with-javax-jms-ConnectionFactory-tp4051119.html
> Sent from the Karaf - User mailing list archive at Nabble.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

Re: [Karaf 4.0.1] - Reference annotation null instance with javax.jms.ConnectionFactory

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

Re: [Karaf 4.0.1] - Reference annotation null instance with javax.jms.ConnectionFactory

jbonofre
And the @Refernce policy is static (the default), not the dynamic ?

The service is actually there ?

Regards
JB

On 07/28/2017 02:02 PM, fpapon wrote:
> Yes
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Karaf-4-0-1-Reference-annotation-null-instance-with-javax-jms-ConnectionFactory-tp4051119p4051123.html
> Sent from the Karaf - User mailing list archive at Nabble.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

Re: [Karaf 4.0.1] - Reference annotation null instance with javax.jms.ConnectionFactory

fpapon
Yes the policy is static (default).

In my custom distribution, the activemq-cf is in the bootFeatures and started before my service.

I don't understand why this work and not the @Reference :

bndContext.getService(bndContext.getServiceReferences(ConnectionFactory.class,
              "(osgi.jndi.service.name=jms/activemq-moss)").iterator().next());

Here the code of the ConnectionFactoryProvider of the activemq-cf :

@Component //
( //
    name = "org.apache.activemq", //
    immediate = true, //
    configurationPolicy = ConfigurationPolicy.REQUIRE //
)
public class ConnectionFactoryProvider {
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Karaf 4.0.1] - Reference annotation null instance with javax.jms.ConnectionFactory

fpapon
I take a look to the class JmsAppender of Decanter and I do the same code in my service :(

I can't find what i'm doing wrong...
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Karaf 4.0.1] - Reference annotation null instance with javax.jms.ConnectionFactory

jbonofre
Did you check the actual service with ls ?

Regards
JB

On 07/28/2017 02:28 PM, fpapon wrote:

> I take a look to the class JmsAppender of Decanter and I do the same code in
> my service :(
>
> I can't find what i'm doing wrong...
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Karaf-4-0-1-Reference-annotation-null-instance-with-javax-jms-ConnectionFactory-tp4051119p4051126.html
> Sent from the Karaf - User mailing list archive at Nabble.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

Re: [Karaf 4.0.1] - Reference annotation null instance with javax.jms.ConnectionFactory

fpapon
I have this with ls :

[javax.jms.ConnectionFactory]                                                                                                                                                                                                       -----------------------------                                                                                                                                                                                                        osgi.jndi.service.name = jms/activemq-moss                                                                                                                                                                                          service.bundleid = 38                                                                                                                                                                                                               service.id = 180                                                                                                                                                                                                                    service.scope = singleton                                                                                                                                                                                                          Provided by :                                                                                                                                                                                                                        activemq-cf (38)                                                                                                                                                                                                                   Used by:                                                                                                                                                                                                                             Apache Karaf :: JNDI :: Core (126)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Karaf 4.0.1] - Reference annotation null instance with javax.jms.ConnectionFactory

fpapon
sorry I'm newbe in the forum...

[javax.jms.ConnectionFactory]
-----------------------------
osgi.jndi.service.name = jms/activemq-moss
service.bundleid = 38
service.id = 180
service.scope = singleton
Provided by :
activemq-cf (38)
Used by:
Apache Karaf :: JNDI :: Core (126)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Karaf 4.0.1] - Reference annotation null instance with javax.jms.ConnectionFactory

fpapon
I've got it !

I had to add OPTIONAL in the cardinality and it work well :

  @Reference(target = "(osgi.jndi.service.name=jms/activemq-moss)", cardinality = ReferenceCardinality.OPTIONAL)
  private ConnectionFactory jmsConnectionFactory;


Perhaps because the ConnectionFactoryProvider class of the activemq-cf feature is a factory...
Loading...