OSGi enRoute for R7 – getting started the easy way! - Tim Ward (Paremus)1. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
Tim Ward
tim.ward@paremus.com
OSGi enRoute Quickstart -
A Beginners Guide to OSGi
2. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
Who is Tim Ward?
Chief Technology Officer at Paremus
10 years developing OSGi specifications
Co-chair of the OSGi IoT Expert Group
Interested in Asynchronous Distributed Systems
Author of Manning’s Enterprise OSGi in Action
http://www.manning.com/cummins
@TimothyWard
3. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
OSGi Modularity in 60 seconds
4. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
OSGi Modules
OSGi is a modularity framework for Java
The Modules are JAR files known as “Bundles”
Bundles have private internal code
Shared packages must be exported
Exported packages must be imported to be accessible
org.a.api org.a.api
org.b.impl
5. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
OSGi Modules (2)
The metadata for a bundle lives in the Manifest
The manifest headers define:
A name for the bundle
A version for the bundle
The imported/exported packages for the bundle
Other requirements/capabilities
Getting the Manifest correct is vitally important
6. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
OSGi Services
OSGi Bundles communicate using the Service Registry
This allows for dynamic, loosely coupled interaction
Consumer
Provider B
Provider A
7. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
OSGi Services
OSGi Services are dynamic
They can come and go at any time
OSGi services may depend on other services
You must unregister if your dependency unregisters
One change can cascade across lots of modules
Failing to use services properly gives poor quality bundles
8. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
Developing for OSGi
9. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
Developing bundles
Ok, so that took more than 60 seconds…
Developing bundles involves writing Java code as normal
Then you have to get the Manifest correct
Do you really know all the packages you use in your code?
If you’re using services then you must listen for them
Failure to do so leads to start up ordering concerns
10. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
That sounds like a nightmare!
11. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
The reason for OSGi enRoute
When people start to use OSGi for the first time…
They look at the core specification (not a bad idea)
They get as far as “Bundle-Activator” and then stop 😞
The compendium specification contains many vital things
They look for examples on the internet
Some examples are very old, or just not very good!
Hand writing a manifest file is never a good idea
12. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
The reason for OSGi enRoute (2)
There are lots of good tools for writing OSGi bundles
They are often not well documented, and set up is rarely trivial
The latest OSGi specs are much more user friendly
Annotation driven services, requirements, capabilities
We need a go-to place which demonstrates
OSGi best practices
A familiar toolchain
Worked examples using the OSGi compendium
13. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
So what is OSGi enRoute?
14. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
The anatomy of OSGi enRoute
OSGi enRoute is a GitHub project using Maven
OSGi enRoute provides four things for users
1. Example Projects
2. Maven Project Templates (Archetypes)
3. Usefully curated OSGi Indexes/Maven dependencies
4. A Website describing how to use all of these things!
15. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
Why is OSGi enRoute using Maven
Because it’s the right choice!
Some people love Maven, and some people hate it
But pretty much everyone knows how to use it!
OSGi enRoute isn’t a build tool tutorial
Deliberately use the most common tool
Fit in with established layouts and patterns
Allow users to continue using all of their other tools/plugins
Importantly, there are plugins from bnd to do all the hard work!
16. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
The OSGi enRoute examples
OSGi enRoute provides examples using the Compendium
JAX-RS whiteboard microservices
Transaction Control based Data Access
Using JPA or JDBC!
Using and Customising the OSGi Converter
Each example is provided with a guide to the key points
All bundle metadata and services automatically managed
17. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
The OSGi enRoute archetypes
Archetypes are a fancy Maven name for project templates
They can be published to repositories, and used via Maven tools
There are lots of different enRoute archetypes
Setting up a new build
Creating an API bundle
Creating a JAX-RS microservice bundle
Integration testing
Wrapping up a runnable application
…
18. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
The OSGi enRoute indexes
In some ways these seem less important
They’re actually the basis for everything else!
A key problem when starting OSGi is finding stuff
And what you do find can be of questionable quality
The indexes wrap up groups of useful dependencies
They include reference implementations of OSGi specifications
All of the contents are vetted for “good OSGi packaging”
19. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
The OSGi enRoute website
Available at https://enroute.osgi.org
Contributions can be made on GitHub (osgi/osgi.enroute.site)
The primary goal of the website is to explain the examples
Several examples have step-by-step tutorials
All of the tutorials can be run from the command line
Optional instructions show how to use the Eclipse IDE
The website also provides basic background and FAQs
20. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
Using OSGi enRoute
21. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
How to use OSGi enRoute
It’s been 15 slides since the last picture…
You’ve all done very well 😊
The purpose of enRoute is to be quick and easy
So the best way to explain it is to use it!
22. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
Switch to Eclipse
23. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
Evaluate the Sessions
-1 0 +1
Sign in and vote at eclipsecon.org
24. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
Questions?
25. Copyright © 2018 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi enRoute Quickstart - A Beginners Guide to OSGi October 2018
www.paremus.com @Paremus info@paremus.com