osgi-bundlejbossfusefusefabric

Publishing and Accessing OSGI Service with JBoss Fuse Fabric


I have an OSGi service that I exposed and deployed on jboss fuse fabric. now I need to access this service from another bundle deployed on another container in jboss fuse fabric. but the service is not accessible in client container. jboss fuse V6.3

when I deploy OSGi-service bundle and client bundle in the same container in fuse fabric, it works, but when I deploy the in different containers in does not work and show an error: Unable to start blueprint container for bundle com.osgi.app.bean-camel-client10/1.0.0 due to unresolved dependencies [(objectClass=org.fusesource.example.service.HelloWorldSvc)]

In client:

POM.xml :

<dependency>
    <groupId>com.osgi.app</groupId>
    <artifactId>bean-app-service1</artifactId>
    <version>1.0</version>
</dependency>

config.xml:

<reference id="helloWorld"
    interface="org.fusesource.example.service.HelloWorldSvc"/>
<camelContext xmlns="http://camel.apache.org/schema/blueprint" >
<route>
  <from uri="timer:foo?period=5000"/>
  <to uri="bean:org.fusesource.example.service.HelloWorldSvc?method=sayHello"/>

  <log message="The message contains: ${body}"/>
 </route>

in service-provider:

pom.xml:

<groupId>com.osgi.app</groupId>
<artifactId>bean-app-service2</artifactId>
<version>1.0</version>
<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <version>${version.maven-bundle-plugin}</version>
    <extensions>true</extensions>
    <configuration>
      <instructions>
        <Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle-SymbolicName>
        <Export-Package>org.fusesource.example.service</Export-Package>
      </instructions>
    </configuration>
  </plugin>

config.xml:

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
         http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
         http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<bean id="hello" class="org.fusesource.example.service.impl.HelloWorldSvcImpl"/>

 <service ref="hello" interface="org.fusesource.example.service.HelloWorldSvc"/>
 </blueprint>

How can I access the service which is deployed in another container in fuse fabric, through a camel context?


Solution

  • <service ref="hello" interface="org.fusesource.example.service.HelloWorldSvc"/>
    

    means exactly this: call BundleContext.registerService("org.fusesource.example.service.HelloWorldSvc", object, properties).

    After registration you have a service registered in local OSGi registry which is scoped by single instance of JVM - that never meant exposing the service to be accessible in different JVM.

    If you want a service to be available in different JVM (== in different OSGi registry), you need some kind of remoting - try using CXF endpoint or one of remoting camel components (camel-cxf, camel-rest, ...).