I am just starting with DOSGi in Karaff using Zookeeper. I have the service offered in an instance of Karaf and the consumer in another. 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. 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:
<?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; (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)]
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?
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.