Saturday, 2 July 2016

OSGI (modularity without microservices)

Microservices are a major trend today. Breaking systems down into rest services with defined interfaces provides modularity, allowing the services to be updated and maintained independently provided the interface does not change. However microservices come with the added cost of network complexity as the microservices are hosted apps on networks.

OSGI is another way to achieve similar modularity within the same JVM. In OSGI world a service is a bundle they provide similar benefits of microservices without the networking downside.

Some of the benefits of OSGI bundles include:
  • OSGI Bundles can dynamically be added and removed from a container at runtime without shutting down the OSGI container. 
  • Bundle dependencies can be made private to the bundle meaning 2 bundles with different versions of the same dependency can run without issues in the same JVM
  • Interfaces are in java so no translation needed
To demonstrate building projects with OSGI I have created a toy OSGI project at

The project consists of 3 Bundles. 
  1. Greeter - Defines Dict interface it consumes any bundles with dictionaries from the container
  2. English Dict - Provides implementation of Dict interface to the container
  3. French Dict- Provides implementation of Dict interface to the container

The UML diagram below shows how the Greeter and the dictionaries are related.

When greeter starts up, it looks for implementations of Dict. Once a Dict is available the greeter will greet using the words in that Dict. Once Dict is removed the greeter will stop greeting in the language.

The following commands can be used to manage bundles in the felix gogo shell:
start <bundleid> - can be used to start a bundle
stop <bundleId>  - can be used to stop a bundle

No comments:

Post a Comment