How to Thrive on REST/WebSocket-Based Microservices

42

Transcript of How to Thrive on REST/WebSocket-Based Microservices

Page 1: How to Thrive on REST/WebSocket-Based Microservices
Page 2: How to Thrive on REST/WebSocket-Based Microservices
Page 3: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |   3  

Classroom  Training  

Learning  SubscripFon  

Live  Virtual  Class  

Training  On  Demand  

Keep  Learning  with  Oracle  University  

educa7on.oracle.com  

Cloud  

Technology  

ApplicaFons  

Industries  

Page 4: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Session  Surveys  

Help  us  help  you!!  • Oracle  would  like  to  invite  you  to  take  a  moment  to  give  us  your  session  feedback.  Your  feedback  will  help  us  to  improve  your  conference.    

• Please  be  sure  to  add  your  feedback  for  your  aQended  sessions  by  using  the  Mobile  Survey  or  in  Schedule  Builder.  

 

4

Page 5: How to Thrive on REST/WebSocket-Based Microservices

How to Thrive on REST/WebSocket-based Microservices

   Pavel  Bucek  ([email protected])  Michal  Gajdoš  ([email protected])    Oracle/Sapho  October  27,  2015  

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Page 6: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Safe  Harbor  Statement  The  following  is  intended  to  outline  our  general  product  direcFon.  It  is  intended  for  informaFon  purposes  only,  and  may  not  be  incorporated  into  any  contract.  It  is  not  a  commitment  to  deliver  any  material,  code,  or  funcFonality,  and  should  not  be  relied  upon  in  making  purchasing  decisions.  The  development,  release,  and  Fming  of  any  features  or  funcFonality  described  for  Oracle’s  products  remains  at  the  sole  discreFon  of  Oracle.  

6  

Page 7: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

IntroducFon  

7  

Page 8: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Why  are  we  doing  this?  

• Proof  of  concept  – Micro  is  the  new  black  – Very  small  runFme  can  deliver  key  funcFonality  

•  JAX-­‐RS  (Jersey)  +  WebSocket  (Tyrus)  •  Java  SE  8  adopFon  • ReacFve  APIs    

8  

Page 9: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

What’s  already  there?  

• Vert.x  • Dropwizard  

– JeQy,  Jersey,  Jackson,  …  – No  WebSocket  

• Glassfish  /  Payara  – JAX-­‐RS,  WebSocket,  Servlet,  JSF,  BV,  CDI,  …  – ~60MB  

 

9  

Page 10: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

QUESTION  Typical  produc7on  deployment  in  my  company  is:  

Micro-­‐service  (small  containers,  dynamic  up/down  scaling)  

Monolithic  applicaFon  (big  containers,  staFc  resources,  acFve/passive  backup)  

CombinaFon  of  previous  

A  

B  

C  

10  

Page 11: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Sample  applicaFon  

•  Simple  poll  – Jersey  MVC  

• Results  are  updated  based  on  new  votes  – WebSocket  connecFon  (could  be  SSE..)  

•  Simple  filtering  (websocket  based)  – InteracFve  part  of  the  app  – WebSocket  are  more  efficient  to  use  

11  

Page 12: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

DEMO  How  does  the  Survey  app  works?  

12  

Page 13: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

QUESTION  Which  Java  framework  do  you  use  in  produc7on?  

Java  EE  6+  

Spring  

Java  EE  5  (and  older)  +  Java  SE  

Something  else,  text  us  what!  

A  

B  

C  

13  

D  

Page 14: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

DEMO  +CDI  

14  

Page 15: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

QUESTION  Do  you  use  WebSocket  in  produc7on?  

Yes.  

Not  yet,  but  we  plan  to.  

No  (we  don’t  need  bi-­‐direcFonal  communicaFon).  

No  (we  use  something  else).  

A  

B  

C  

15  

D  

Page 16: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Micro-­‐services  

•  Simple,  small,  decoupled  standalone  “applicaFons”  – They  don’t  do  (and  provide)  anything  else  than  they  should  – Easy  to  develop  and  test  

•  Fast  startup  Fme,  Fault  tolerant  – Dynamic  scaling  – CaQle  vs  Pet  

16  

Page 17: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

<<Placeholder>>  

17  

Page 18: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

<<Placeholder>>  

• Grizzly  – HTTP  container  

• HK2  – Dependency  InjecFon  

•  Tyrus  – WebSocket  RI  

•  Jersey  – JAX-­‐RS  RI  

18  

Page 19: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

DEMO  <<Placeholder>>  

19  

Page 20: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

QUESTION  Executable  JAR  size  (<<Placeholder>>  +  poll  app)  is:  

~100  MB  

~50  MB  

~20  MB  

~10  MB  

~5  MB  

A  

B  

C  

20  

D  

E  

Page 21: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Summary  

• Glassfish  – Footprint:  >200  M  – Startup  Fme:  ~10  s  

•  JeQy  +  Weld  – Footprint:  ~28  M  – Startup  Fme:  ~5  s  

•  <<Placeholder>>  – Footprint:  ~11  M  – Startup  Fme:  ~1s  

21  

Page 22: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

What  do  we  miss?  

22  

Page 23: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Java  8  +  ReacFve  APIs  

•  Lots  of  new  features  in  Java  8  •  Frameworks  slowly  up-­‐taking  new  APIs  • OpFonal,  Lambdas,  Streams,  …  

• ReacFve  APIs  are  very  handy  when  you  are  accessing  more  services  – You  don’t  need  to  wait  (block)  for  the  answer  – Processing  hooked  to  “response(s)  received”  

23  

Page 24: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

QUESTION  Java  version  in  produc7on:  

Java  5  (and  older)  

Java  6  

Java  7  

Java  8  

Java  9  (for  cuwng-­‐edge  enthusiasts)  

A  

B  

C  

24  

D  

E  

Page 25: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

OpFonal  in  Jersey  

•  Server  – Incoming  enFFes  – Return  values  (Outgoing  enFFes)  – @*Param  values  

• Client  – Outgoing  enFFes  

25  

Page 26: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

OpFonal  in  Jersey  

26  

Page 27: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

OpFonal  in  Jersey  

27  

Page 28: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

ReacFve  Client  API  in  Jersey/JAX-­‐RS  2.1  

• UFlize  the  reacFve  programming  model  when  using  Jersey/JAX-­‐RS  Client  • Already  in  Jersey  

– Java  8  –  CompleFonStage  – RxJava  – Guava  

• Will  be  in  JAX-­‐RS  2.1  

28  

Page 29: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

ReacFve  Client  API  –  Jersey  &  RxJava  

29  

Page 30: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

ReacFve  Client  API  –  JAX-­‐RS  2.1  &  CompleFonStage  

30  

Page 31: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

ProgrammaFc  Resources  in  Jersey  

31  

Page 32: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Lambdas  in  Tyrus  

•  Endpoint  is  just  a  set  of  lambda  funcFons  – @OnOpen,  @OnMessage,  @OnError,  @OnClose  – WebSocket  API  already  has  programmaFc  version  in  the  specificaFon  –  see  javax.websocket.Endpoint  

•  It  can  be  applied  to  server  side  as  well  – AnnotaFon  way  is  o{en  preferred  for  server-­‐side  deployment  – Easier  to  read  +  integrate  with  other  frameworks  (DI,  ..)  

32  

Page 33: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Lambdas  in  Tyrus  

33  

Page 34: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Lambdas  in  Tyrus  

34  

Page 35: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Lambdas  in  Tyrus  

35  

Page 36: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Streams  in  Tyrus  

•  Stream  processing  is  another  bigger  and  more  notable  feature  of  the  Java  8  • MessageHanders  (in  general  -­‐  any  event  handler)  can  be    modeled  as  endless  stream  – there  are  some  issues  with  “terminators”,  but  that  could  be  solved  -­‐  terminator  would  unregister  current  “message  handler”;  push  vs  pull..  

– streams  can  easily:  filter,  map  (encode/decode)  

36  

Page 37: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Contacts  

• Pavel  Bucek  ([email protected])  • Michal  Gajdoš  ([email protected])    Github  repo:  hQps://github.com/pavelbucek/placeholder  

•  Jersey  –  hQp://jersey.java.net  •  Tyrus  –  hQp://tyrus.java.net    

37  

Page 38: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Q  &  A  

38  

Page 39: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

       

39  

Page 40: How to Thrive on REST/WebSocket-Based Microservices

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |   40  

Page 41: How to Thrive on REST/WebSocket-Based Microservices
Page 42: How to Thrive on REST/WebSocket-Based Microservices