REST microservices are a powerful tool for composing large-scale systems, and the standalone nature of a microservice helps to avoid it becoming part of a “big ball of mud” application. Given the power and success of microservices as inter-process modules, why stop there? OSGi has offered in-process microservices for nearly two decades, and uses them to great effect in modular applications.
The new OSGi JAX-RS whiteboard service allows dynamic OSGi services to be automatically exported as JAX-RS Resources, Filters or Applications. These “Microservice modules” can be easily shared or moved between frameworks, allowing you to benefit from a microservice structure that goes all the way down.
Over the last decade there has been a significant shift in the way that many computer programs are written. The focus has changed from building larger, more monolithic applications that provide a single high-level function, to composing these high-level behaviours from groups of smaller, distributed services. This is generally known as a “microservice” architecture, indicating that the services are smaller and lighter weight than typical web services.
The standard for REST microservices in Java is known as JAX-RS. JAX-RS provides a simple annotation-based model in which POJOs can have their methods mapped to RESTful service invocations. There is automatic mapping of HTTP parameters, and of the HTTP response, based on the annotations, and the incoming HTTP Headers. JAX-RS also includes support for grouping these POJOs into a single Application artifact. This allows the POJOs to interact with one another, as well as to share configuration and runtime state. When used in JAX-RS these POJOs are known as JAX-RS resources.
Ideal JAX-RS resources are stateless, and are usually instantiated by the container. JAX-RS resources share many features with OSGi services, in that they provide a way for machines (or processes within a machine) to interact with one another through a defined contract. This synergy between JAX-RS resources and OSGi services is the driver for the OSGi JAX-RS whiteboard service, allowing OSGi services to be transparently exposed using JAX-RS.