OSGi Bundle Communication Options
OSGi Bundle Communication Options
Join the DZone community and get the full member experience.Join For Free
SnapLogic is the leading self-service enterprise-grade integration platform. Download the 2018 GartnerMagic Quadrant for Enterprise iPaaS or play around on the platform, risk free, for 30 days.
OSGi Service Registry
This is the most common (and well documented) approach from a pure OSGi perspective. Simple XML can be used to both register APIs as services and access other bundle's services. The service registry then provides an abstraction layer and an event framework to support dynamic binding, reacting to service lifecycle changes, etc. The whiteboard pattern can also help better manage this interaction in more complex/demanding scenarios.
This approach is more direct and relies on OSGi bundle manifests to tell the classloader which classes to export (make available to other bundles) or import (find classes in other bundles). This has the effect of making any imported classes look like any other class in a bundle.
However, this tends to tightly couple bundles together and can cause various classloader/versioning issues when bundles get out of sync.
An ActiveMQ broker is provided with Fuse ESB and is easily setup/configured. JMS endpoints can then easily be setup using Camel to wrap access to POJO Java code, etc. This can easily serve as a bridge between bundles or even VMs/machines entirely. This approach povides the standard JMS benefits (guaranteed messaging, loose coupling, high performance, failover/load balancing, etc).
Some initial performance concerns usually arise when considering use of persistent XML messaging. Most performance concerns can be mitigated by varying the JMS QoS or even using serialized object messages instead of XML, etc.
HTTP (SOAP, REST)
Another classic approach is to provide HTTP endpoints to interact with a bundle. This provides a loosely coupled strategy bound to either a SOAP WSDL or REST request/response format. Camel components can be used to setup these endpoints and wrap requests to POJO Java code, etc.
Unfortunately, these endpoints aren't the easiest to configure/test and often impose a significant overhead in terms of marshaling request/response data around.
Though its roots were in JBI/XML based messaging, it has evolved to provide a more generic/configurable approach to bundle communication. It can be configured to be to be synchronous or asynchronous. Also, the camel-nmr component makes it easy to define NMR endpoints to route data between bundles without the need to use JMS brokers or more complex HTTP definitions.
See this post from Adrian Trenaman for more details on the new NMR...
VM uses asynchronous SEDA to send messages between entities in the same virtual machine. This has the benefit of using a seperate thread for a producer and consumer.
More to come on this...I'm still working out the differences between VM and NMR in OSGi.
Distributed OSGi (DOSGi)
This implements the remove services functionality using SOAP web services. Its very new and I'm still coming up to speed on it...(thanks Ashwin for pointing this out)
More to come on this...see these page for now.
This is clearly still a work in progress. There are a lot of options and I'm still trying to get my head around the trade-offs of each approach (hence this page). As time permits, I'll try to expand on these more...
If anyone has had good/bad experiences with these techniques or others, let me know...
Published at DZone with permission of Ben O'Day , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.