Ten reasons to use OSGi
for your next cloud app
@pbakker
Slide 2
Slide 2 text
Paul Bakker
@pbakker
Slide 3
Slide 3 text
Reason nr
Developer Productivity
1
Slide 4
Slide 4 text
Code
Maven build full project
Deploy to app server
Re-initialize full app
Typical Java development
workflow…
Slide 5
Slide 5 text
Typical OSGi development
workflow…
“Like working with a
scripting language”
Slide 6
Slide 6 text
No content
Slide 7
Slide 7 text
How does it work?
Class loader per bundle
OSGi supports updating a bundle
On compile, bundle is rebuild and re-installed
Slide 8
Slide 8 text
Reason nr
No more
ClassNotFoundException
2
Slide 9
Slide 9 text
Imports / Exports
OSGi bundles define explicitly what classes they import
Imports must be exported by some bundle
Imports are calculated from your byte code
Slide 10
Slide 10 text
Example code
z
Slide 11
Slide 11 text
Import packages are
generated
Import-‐Package:
org.apache.felix.dm;version=“[4.0,5)",
org.osgi.framework;version="[1.3,2)"
Slide 12
Slide 12 text
The framework tells you
what’s missing
Unable to resolve 1.0: missing requirement [1.0]
osgi.wiring.package;
(&(osgi.wiring.package=org.apache.felix.dm)
(version>=4.0.0)(!(version>=5.0.0)))
Forgot to install Dependency
Manager bundle…
Slide 13
Slide 13 text
API versioning
Deploy multiple versions of an API
Import a specific version range
Semantic Versioning
Slide 14
Slide 14 text
Reason nr
Great for
Cloud Deployment
3
Slide 15
Slide 15 text
Great for (Cloud) deployment
No application server
Executable JAR file
Very small memory footprint
Perfect for building Docker containers
Slide 16
Slide 16 text
Building a binary
gradle build export
java -‐jar MyApp.jar
Great commercial support
RTI
Kubernetes based clusters
Logging and Monitoring for OSGi
Automated Blue/Green deployments
Slide 19
Slide 19 text
Reason nr
Maintainable
architecture
4
Slide 20
Slide 20 text
Maintainable architecture
Implementation hiding
Enforce module boundaries
Modules during development, build and runtime
Slide 21
Slide 21 text
Bundles and services
Only APIs are exported, the bundle’s contract
Services provide functionality
True decoupling
Service
Registry
Bundle registering a
service
Bundle using a
service
Publish
MyInterface
Lookup
MyInterface
Slide 22
Slide 22 text
Data
Business
UI
Big ball of mud
Big ball of mud
Big ball of mud
Slide 23
Slide 23 text
Data
Business
UI
Slide 24
Slide 24 text
Rooms
Resource
AngularJS
Client
Rooms Service
RabbitMQ
Service
STOMP
AMQP
RabbitMQ
Chat Log
Mongose
Jongo
REST
Personalized
Ad Generator
Word Counter
Product
Service
MySQL
Slide 25
Slide 25 text
Rooms
Resource
AngularJS
Client
Rooms Service
RabbitMQ
Service
STOMP
AMQP
RabbitMQ
Chat Log
Mongo
Jongo
REST
Personalized
Ad Generator
Word Counter
Product
Service
MySQL
Each part is a separate OSGi bundle
Slide 26
Slide 26 text
Reason nr
Dependency
Injection
5
@ServiceDependency
Best preparation for
Micro Services
OSGi services are micro services within a VM
Easy to migrate to remote services when needed
Perfect balance between “Monolith First” and Micro
Services from te get go
Slide 30
Slide 30 text
OSGi Remote Services
OSGi spec for remote service discovery and invocation
Pluggable discovery and transport
No code changes required!
Slide 31
Slide 31 text
Client
Server
Slide 32
Slide 32 text
Reason nr
All the libraries
you need
7
Slide 33
Slide 33 text
REST
Scheduling
Mongo
JPA
Web Resources
Blob Stores
Remote Services
Security
Email
Config
Components
No core framework or half a zillion dependencies!
Slide 34
Slide 34 text
Amdatu REST example
Slide 35
Slide 35 text
Amdatu Mongo example
Amdatu
Mongo Service
Setup Object
Mapper
Execute query
Slide 36
Slide 36 text
Reason nr
Plugin systems
8
Plugin
Registry
Plugin Plugin Plugin
Slide 37
Slide 37 text
core.jar
myplugin.jar
Install plugin by installing a bundle
Slide 38
Slide 38 text
Real world examples
Amdatu Bootstrap (even directly from Git repos)
Spring Roo
Eclipse
Glassfish
…
Slide 39
Slide 39 text
Reason nr
Integration testing
9
Slide 40
Slide 40 text
Integration testing
Looks like plain JUnit
Runs in an OSGi framework
Slide 41
Slide 41 text
Reason nr
Great resources
to get you started
10
Slide 42
Slide 42 text
Don’t be afraid to ask!
http://amdatu.org
@pbakker