Reputation: 1
I have two bundle A and B , the bundle A have a service activator containing a method called receive for receiving emails, and bundle B consume emails from bundle A so I would like how to expose a service activator as a service in OSGi.
Upvotes: 0
Views: 907
Reputation: 23413
Create an interface depending on your needs. I will provide you with an example one:
public interface Receiver {
void receive(String smth);
}
Create an implementation class:
public class ReceiverImpl implements Receiver {
@Override
public void receive(String smth) {
}
}
Then expose the Receiver as an OSGi service using Spring like this:
<bean id="receiver" class="com.yourpackage.ReceiverImpl"/>
<osgi:service ref="receiver" interface="com.yourpackage.Receiver"/>
To make this work make sure that your Receiver bundle exports the package in the manifest entries and your Consumer bundle imports that package.
To call the Receiver in other bundle use:
<osgi:reference id="receiver" interface="com.yourpackage.Receiver"/>
You can then set the property of the Receiver to any Spring bean of the bundle which will use it.
Upvotes: 1