Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Lean Microservices with OSGi - Christian Schneider


Published on

OSGi Community Event 2016 Presentation by Christian Schneider (Talend)

Microservices and their frameworks like spring boot allow to start fast but can easily produce ugly monoliths or tangled webs of fine grained dependencies. OSGi on the other hand provides great modularity but is regarded as more complex than spring boot and alike. This Talk shows how to create lean and modular microservices using OSGi, maven, bndtools and Apache Karaf. The build result is a runnable jar or docker image and nicely fits microservice deployments. See how OSGi allows the flexibility to deploy each microservice on its own and let them communicate over (REST) remote calls or deploy them together and talk using OSGi services locally using the same business code bundles.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Lean Microservices with OSGi - Christian Schneider

  1. 1. Lean microservices on OSGi By Christian Schneider Open Source Architect at Talend @schneider_chris
  2. 2. Participate in Demo Connect to irc network freenode Channel #osgichat
  3. 3. Microservices ...way of designing software applications as suites of independently deployable services.... organization around business capability, automated deployment, intelligence in the endpoints, and decentralized control of languages and data. - Martin Fowler ● Create application out of independently deployable services ● Verticals around business capabilities ● Decentralized data ● Automated deployment ● 1 service per process ● Lightweight communications between services (typically REST)
  4. 4. Spring boot ● Framework for micro service development based on spring ● Easy to start. Paste snippets of “starter” dependencies into pom ● Convention over configuration ● Good docker and cloud support
  5. 5. The Dark side of microservices
  6. 6. No, no, no. Quicker, easier, more seductive... Are microservices stronger than OSGi?
  7. 7. Dependencies between microservices
  8. 8. Operations Container vessel - Application Server
  9. 9. Microservices operation - Theory
  10. 10. Microservices operation - Practice
  11. 11. Microservices can not cure bad design
  12. 12. Microservices with spring-boot… What is wrong with it? ● Lots of dependencies already at design time ● Microservices always must communicate remotely ● Proprietary Annotations / API ● No flexibility in packaging 1 Microservice = 1 Deployment Unit = 1 Process
  13. 13. A small spring boot project ● Pollutes the classpath ● Difficult to establish rules which APIs to use 90 dependencies 20 MB jar file
  14. 14. Why is OSGi different? ● Coding against APIs and specs ● Self describing modules (bundles) ● OSGi services to communicate between bundles ● Semantic versioning ● Remote Service Admin for Remote calls and REST ● Flexible packaging
  15. 15. Semantic Versioning ● MAJOR version - incompatible API changes, ● MINOR version - added functionality in a backwards-compatible manner ● BUGFIX version - backwards-compatible bug fixes Mind the difference between API and SPI.
  16. 16. Remote Service Admin ● Exports and imports OSGi services ● Service Properties to mark for export and configure transports, … ● Highly customizable (Policies, Transports, Serialization, Discovery)
  17. 17. Rest services with RSA ● Just JAX-RS annotations on interface REST Endpoint User bundle HTTP OSGi service CXF Transport for Aries RSA Creates Topology Manager Detects Selects transport
  18. 18. Lets see it in practice Small chat application ● Modules talk to each other using an OSGi ChatListener interface described in API bundle ● IRC connector using camel ● Shell integration using gogo ● Tinkerforge Display and Motion detector ● Optional Remoting using Aries RSA
  19. 19. Chat API Chat shell integration Tinkerforge LCD display IRC Connector IRC All in one ● 1 Process ● 6MB runnable jar ● No remote calls inside application ● Still modular as bundles only coupled through API and OSGi service
  20. 20. Container vessel - OSGi deployment in one process
  21. 21. Chat API IRC Connector Aries RSA IRC Microservice Deployment Chat API Tinkerforge LCD and motion detect Aries RSA Chat API Chat shell integration Aries RSA Zookeeper
  22. 22. Microservice Deployment ● Same bundles as before ● As many deployment units as needed ● Each deployment unit can scale ● Runnable jars or docker containers ● Cloud native if needed ● Aries RSA overhead 300 KB + 800 KB zookeeper lib ● Remote calls or local calls as needed ● Many options for remotings (tcp, fastbin, SOAP, REST, JMS)
  23. 23. But beware of the same management issues as any other micro services
  24. 24. Demo time
  25. 25. OSGi can scale from very small to very large But no simple cure for the operational problems of microservices
  26. 26. Unsure if you actually need a microservice architecture? ● Develop your application using modular bundles ● Stay on single process as long as possible ● Decide about the packaging and deployment as late as possible ● Deploy only as fine granular as needed
  27. 27. Further Reading ● Achim Nierbeck - Microservices on OSGi ● Milen Dyankow - Microservices and Modularity ● OSGi Chat example code ● Example for REST export using Aries RSA and CXF