使用 JBoss Fuse Fabric 发布和访问 OSGI 服务

Publishing and Accessing OSGI Service with JBoss Fuse Fabric

我有一个 OSGi 服务,我公开并部署在 jboss fuse 结构上。 现在我需要从 jboss fuse fabric 中部署在另一个容器上的另一个 bundle 访问这个服务。但该服务无法在客户端容器中访问。 jboss保险丝V6.3

当我在 fuse fabric 中的同一个容器中部署 OSGi 服务包和客户端包时,它可以工作,但是当我在不同的容器中部署它们时,它不起作用并显示错误: 由于未解决的依赖项 [(objectClass=org.fusesource.example.service.HelloWorldSvc)]

,无法启动捆绑包 com.osgi.app.bean-camel-client10/1.0.0 的蓝图容器

在客户端:

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>

在服务提供商中:

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>

如何通过 camel 上下文访问部署在 fuse fabric 中另一个容器中的服务?

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

的意思就是:调用 BundleContext.registerService("org.fusesource.example.service.HelloWorldSvc", object, properties).

注册后,您在 local OSGi registry 中注册了一个服务,该服务的作用域为单个 JVM 实例 - 这绝不意味着将服务公开以供在不同的 JVM 中访问。

如果您希望服务在不同的 JVM(== 在不同的 OSGi 注册表中)可用,您需要某种远程处理 - 尝试使用 CXF 端点或远程处理之一骆驼组件(camel-cxf、camel-rest、...)。