Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ITT 2017 - Maciek Próchniak - OSGi, Java 9? do we still need modularity in the world of microservices

ITT 2017 - Maciek Próchniak - OSGi, Java 9? do we still need modularity in the world of microservices

Maciek Próchniak talks about Microservices. Microservices architecture is one of the most trendy topics in IT these days. Everyone looks at Netflix, LinkedIn or Zalando and tries to be like them.
It’s all very good. But at heart of this revolution lie some well known ideas on modularity and decoupling.
And guess what? Idea of modular Java applications is also not new. Even term “microservice” has been in use on JVM since many, many years. However, the main technology for modular Java - OSGi - was always struggling to gain proper attention and we’re still waiting for modules in JDK itself.
In this talk, Maciek Próchniak explains why you shouldn’t too easily dismiss both OSGi and Java 9 - in many use cases, with little effort they can give you important benefits, without having to spin hundreds of VMs or containers.

990b89ca5f918a94ef6523d399eda9a4?s=128

Istanbul Tech Talks

April 03, 2017
Tweet

Transcript

  1. Java 9/OSGi? Microservices?

  2. Maciek Próchniak

  3. Timeline

  4. Meanwhile...

  5. FFW 2017

  6. Bootiful future?

  7. Bootiful future?

  8. But...

  9. How tall are you?

  10. Case 1 - startup

  11. Case 2 - frameworks?

  12. Case 3 - Enterprise

  13. Case 3 - Enterprise

  14. What are microservices for?

  15. Decoupling

  16. Decoupling

  17. Coupling • • • •

  18. Code level

  19. Deployment level

  20. Runtime coupling?

  21. Stop in between?

  22. Stop in between?

  23. Stop in between?

  24. JVM?

  25. Java modules • ◦ ◦ ◦ • ◦ ◦

  26. None
  27. None
  28. Jigsaw...

  29. None
  30. None
  31. None
  32. Leave prejudice … for next 30min

  33. None
  34. Module

  35. Module

  36. Export/Import module mproch.services.order { requires mproch.services.user; exports pl.mproch.services.order.api; } Export-Package:

    pl.mproch.services.order.api; uses:="javax.ws.rs,javax.ws.rs.core";version="1.0.0" Import-Package: javax.ws.rs;version="[2.0,3)"
  37. What should be module? • • • • •

  38. API vs Library vs Service

  39. API vs Library vs Service

  40. API vs Library vs Service

  41. Deployment?

  42. Deployment?

  43. Versioning?

  44. Semantic versioning

  45. None
  46. OSGi? Error executing command: Error restarting bundles: Unable to start

    bundle 278: Uses constraint violation. Unable to resolve resource demo-persistence-jpa [demo-persistence-jpa [278](R 278.0)] because it is exposed to package 'javax.persistence' from resources javax.persistence [javax.persistence [248](R 248.0)] and org.apache.geronimo.specs.geronimo-jpa_2.0_spec [org.apache.geronimo.specs.geronimo-jpa_2.0_spec [266](R 266.0)] via two dependency chains. Chain 1: demo-persistence-jpa [demo-persistence-jpa [278](R 278.0)] import: (&(osgi.wiring.package=javax.persistence)(version>=2.1.0)) | export: osgi.wiring.package: javax.persistence javax.persistence [javax.persistence [248](R 248.0)] Chain 2: demo-persistence-jpa [demo-persistence-jpa [278](R 278.0)] import: (osgi.wiring.package=org.hibernate.proxy) | export: osgi.wiring.package=org.hibernate.proxy; uses:=javax.persistence com.springsource.org.hibernate [com.springsource.org.hibernate [230](R 230.0)] import: (&(osgi.wiring.package=javax.persistence)(version>=1.0.0)(!(version>=2.0.0))) | export: osgi.wiring.package: javax.persistence org.apache.geronimo.specs.geronimo-jpa_2.0_spec [org.apache.geronimo.specs.geronimo-jpa_2.0_spec [266](R 266.0)] Unresolved requirements: [[demo-persistence-jpa [278](R 278.0)] osgi.wiring.package; (osgi.wiring.package=org.hibernate.proxy)]
  47. Java 9?

  48. Versioning is HARD...

  49. Modules over microservices • • • •

  50. Service is not only code

  51. Service = Code + Behaviour

  52. Behaviour • • •

  53. Spring/CDI? @Singleton public class UserService { @Value(“#{user.maxAge}”) private int maxAge;

    @PostConstruct public void init() { } }
  54. Java 9? module UserModule { provides pl.mp.user.api.UserService with pl.mp.user.impl.DbUserService; }

    module OrderModule { requires UserModule; uses pl.mp.user.api.UserService; } ServiceLoader<UserService> services = ServiceLoader.load(UserService.class); services.iterator()
  55. None
  56. DI - Service Registry (name=”userService”) name=”userService”

  57. Context separation @Singleton @OsgiServiceProvider public class UserService { } public

    class OrderService { @OsgiService @Inject UserService userService }
  58. Context separation

  59. DOSGi

  60. Lifecycle? @Singleton public class UserService { @PostConstruct public void init()

    { } } @Component public class UserService { @Activated @Updated public void init() { } }
  61. Dynamic updates?

  62. Thread::kill

  63. Services over microservices • • • •

  64. But does it have Spring Boot??

  65. But does it have Spring Boot??

  66. ‘Enterprise’ features • • • • • • •

  67. None
  68. Declarative profiles

  69. Profiles deployment

  70. DEMO

  71. But does it have Spring Boot??

  72. OSGi + Karaf platform • • • •

  73. None
  74. Does it work in production?

  75. Our case • • • •

  76. Our case

  77. Do we still need modularity?

  78. What do you need?

  79. What do you need?

  80. What do you need?

  81. None
  82. Thanks