简体   繁体   English

Karaf中的分布式OSGI-消费者服务未启动

[英]Distributed OSGI in Karaf -Consumer service not starting

I am just starting with DOSGi in Karaff using Zookeeper. 我只是使用Zookeeper从Karaff的DOSGi开始。 I have the service offered in an instance of Karaf and the consumer in another. 我在Karaf实例中提供了服务,而在另一个实例中提供了消费者。 The service side works well. 服务端运行良好。 Once published, I can see it using the log:display command in Karaf console where the Zookeeper server is installed and I can access to the wsdl by the browser as well. 发布后,可以在安装了Zookeeper服务器的Karaf控制台中使用log:display命令查看它,并且我也可以通过浏览器访问wsdl。 The problem is in the consumer side. 问题出在消费者方面。 It should write a message (ref code below) when the service is up, but it never happens. 服务启动时,它应该写一条消息(下面的参考代码),但是永远不会发生。 Consumer code: 消费者代码:

package org.osgi.proyecto.dev.internal.consumer;


import org.osgi.proyecto.dev.consumer.IConsumer;   
import org.osgi.proyecto.dev.sensor.ISensor;

public class Consumer implements IConsumer {

public void sensorActivo(ISensor sensor){       
    System.out.println("El sensor esta activo");
}   
}

And the component.xml: 和component.xml:

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"     immediate="true" enabled="true" name="OSGI_Bundle-Consumer">
<implementation class="org.osgi.proyecto.dev.internal.consumer.Consumer"/>
<reference bind="sensorActivo" cardinality="1..1"   interface="org.osgi.proyecto.dev.sensor.ISensor" name="ISensor"  policy="dynamic"/>>
</scr:component>

Manifest: 表现:

  Manifest-Version: 1.0
  Bundle-ManifestVersion: 2
  Bundle-Name: OSGI_Bundle-Consumer
  Bundle-SymbolicName: OSGI_Bundle-Consumer2
  Bundle-Version: 1.0.0.qualifier
  Bundle-RequiredExecutionEnvironment: JavaSE-1.8
  Service-Component: OSGI-INF/component.xml
  Import-Package: org.osgi.framework;version="1.8.0",
   org.osgi.proyecto.dev.sensor

I tried forcing the consumer bundle (start bundle) and it gives me this error: 我尝试强制使用使用者捆绑包(启动捆绑包),它给了我这个错误:

Error starting bundle 137: Unable to resolve OSGI_Bundle-Consumer [137](R 137.1): missing requirement [OSGI_Bundle-Consumer [137](R 137.1)] osgi.wiring.package; 启动包137时出错,无法解析OSGI_Bundle-Consumer [137](R 137.1):缺少要求[OSGI_Bundle-Consumer [137](R 137.1)] osgi.wiring.package; (osgi.wiring.package=org.osgi.proyecto.dev.sensor) Unresolved requirements: [[OSGI_Bundle-Consumer [137](R 137.1)] osgi.wiring.package; (osgi.wiring.package = org.osgi.proyecto.dev.sensor)未解决的要求:[[OSGI_Bundle-Consumer [137](R 137.1)] osgi.wiring.package; (osgi.wiring.package=org.osgi.proyecto.dev.sensor)] (osgi.wiring.package = org.osgi.proyecto.dev.sensor)]

It seems that there is a dependency error. 似乎存在依赖性错误。 This is solved installing the sensor bundle (Installed state) in the consumer instance. 解决了在消费者实例中安装传感器束(已安装状态)的问题。 How can I avoid installing the same sensor bundle in both Karaf instances? 如何避免在两个Karaf实例中安装相同的传感器束?

You should put the service interface in a separate bundle. 您应该将服务接口放在单独的捆绑软件中。 Then you can install the consumer and the interface bundle on the consumer side and the service and the interface bundle on the server side. 然后,您可以在使用者端安装使用者和接口束,并在服务器端安装服务和接口束。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM