5 November 2017

Dynamic Vaadin on OSGi

Vaadin 8 - Java 8 - Karaf 4 - OSGi 6 : The easy way to real µservice web apps.



There have been numerous articles on describing how to avoid or split up a monolithic architecture into a micro-services setup. A YouTube presentation of Christian Schneider springs to mind (audio gets better after about a minute). I especially like this slide that says it all:


OSGi has done a great job enabling µservice architectures and enforcing clean modular design on the middleware and backend layers but i have not had the chance of putting it into action on the frontend. Finding a modular web UI technology was no great deal, thanks to the people at Vaadin and the basic OSGi integration they have mastered on there latest major version. Getting the two frameworks to play nice is still no trivial task, and resources on the net for Vaadin 8 on OSGi are rare. So, time to get my hands dirty.

My requirements for a modular UI are:
  • Split the UI in vertical modules based on separation of business concerns
  • Runtime addition, removal and updating UI modules and configuration
  • Communicate between these modules using events and/or messaging
  • Discover remote UI modules using DOSGi
  • And maybe we can reach the ultimate goal of SCS, but this could be too much ivory

I cooked up a small setup that demonstrates a possible way of dynamic updating the UI using OSGi declarative services. To get it up and running do the following:

First check out and maven install ops4j-pax-web version 6.0.7.1 from my github account as this contains several corrections to make Vaadin-push work on Karaf. Details can be found here.

Download Karaf 4.1.2 extract and execute.  On the Karaf console add the pax web feature:
feature:repo-add mvn:org.ops4j.pax.web/pax-web-features/6.0.7.1/xml/features
and install the pax-http-whitboad extender:
feature:install pax-http-whiteboard/6.0.7.1
Maven install this project producing a Karaf Archive file (osgi-karaf-vaadin-kar-2.0.0.kar)

Drop this file into the deploy folder found under the Karaf main folder to install all needed bundles at once.

Open up a web browser and open http://localhost:8181/service to display the Vaadin SPA.

Start the dynamic bundle on the Karaf console to see the dynamic parts working.

Any new Ideas regarding this project are always welcome!

Background information:

Christian Posta: Prefer verticals not layers and The Hardest Part About Microservices: Your Data
innoQ: Self contained systems
Arun Gupta: Monolithic to Microservices Refactoring for Java EE Applications