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.

Istanbul Tech Talks

April 03, 2017
Tweet

More Decks by Istanbul Tech Talks

Other Decks in Programming

Transcript

  1. Java 9/OSGi?
    Microservices?

    View Slide

  2. Maciek Próchniak

    View Slide

  3. Timeline

    View Slide

  4. Meanwhile...

    View Slide

  5. FFW 2017

    View Slide

  6. Bootiful future?

    View Slide

  7. Bootiful future?

    View Slide

  8. But...

    View Slide

  9. How tall are you?

    View Slide

  10. Case 1 - startup

    View Slide

  11. Case 2 - frameworks?

    View Slide

  12. Case 3 - Enterprise

    View Slide

  13. Case 3 - Enterprise

    View Slide

  14. What are microservices
    for?

    View Slide

  15. Decoupling

    View Slide

  16. Decoupling

    View Slide

  17. Coupling




    View Slide

  18. Code level

    View Slide

  19. Deployment level

    View Slide

  20. Runtime coupling?

    View Slide

  21. Stop in between?

    View Slide

  22. Stop in between?

    View Slide

  23. Stop in between?

    View Slide

  24. JVM?

    View Slide

  25. Java modules







    View Slide

  26. View Slide

  27. View Slide

  28. Jigsaw...

    View Slide

  29. View Slide

  30. View Slide

  31. View Slide

  32. Leave prejudice
    … for next 30min

    View Slide

  33. View Slide

  34. Module

    View Slide

  35. Module

    View Slide

  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)"

    View Slide

  37. What should be module?





    View Slide

  38. API vs Library vs Service

    View Slide

  39. API vs Library vs Service

    View Slide

  40. API vs Library vs Service

    View Slide

  41. Deployment?

    View Slide

  42. Deployment?

    View Slide

  43. Versioning?

    View Slide

  44. Semantic versioning

    View Slide

  45. View Slide

  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)]

    View Slide

  47. Java 9?

    View Slide

  48. Versioning is HARD...

    View Slide

  49. Modules over microservices




    View Slide

  50. Service is not only code

    View Slide

  51. Service = Code + Behaviour

    View Slide

  52. Behaviour



    View Slide

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

    View Slide

  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 services = ServiceLoader.load(UserService.class);
    services.iterator()

    View Slide

  55. View Slide

  56. DI - Service Registry
    (name=”userService”)
    name=”userService”

    View Slide

  57. Context separation
    @Singleton
    @OsgiServiceProvider
    public class UserService {
    }
    public class OrderService {
    @OsgiService
    @Inject
    UserService userService
    }

    View Slide

  58. Context separation

    View Slide

  59. DOSGi

    View Slide

  60. Lifecycle?
    @Singleton
    public class UserService {
    @PostConstruct
    public void init() {
    }
    }
    @Component
    public class UserService {
    @Activated
    @Updated
    public void init() {
    }
    }

    View Slide

  61. Dynamic updates?

    View Slide

  62. Thread::kill

    View Slide

  63. Services over microservices




    View Slide

  64. But does it have Spring
    Boot??

    View Slide

  65. But does it have Spring Boot??

    View Slide

  66. ‘Enterprise’ features







    View Slide

  67. View Slide

  68. Declarative profiles

    View Slide

  69. Profiles deployment

    View Slide

  70. DEMO

    View Slide

  71. But does it have Spring Boot??

    View Slide

  72. OSGi + Karaf platform




    View Slide

  73. View Slide

  74. Does it work in
    production?

    View Slide

  75. Our case




    View Slide

  76. Our case

    View Slide

  77. Do we still need modularity?

    View Slide

  78. What do you need?

    View Slide

  79. What do you need?

    View Slide

  80. What do you need?

    View Slide

  81. View Slide

  82. Thanks

    View Slide