Slide 1

Slide 1 text

1   Going  Reac+ve   High  Performance  JVM  Code  with  Reactor   Michael  Nitschinger    

Slide 2

Slide 2 text

2   Who  is  that  guy?   •  Developer  Advocate  at  Couchbase   ­  Java  SDK  Maintainer   ­  Spring-­‐Data-­‐Couchbase  and  more     •  @daschl   •  Contribu+ng  to  Reactor,  NeGy,...   •  Living  here  in  Vienna  

Slide 3

Slide 3 text

3   Reac+ve?  

Slide 4

Slide 4 text

4   The  Manifesto   •  hGp://www.reac+vemanifesto.org/     h>p://www.reacCvemanifesto.org/images/full-­‐[email protected]  

Slide 5

Slide 5 text

5   The  Manifesto   •  Event-­‐Driven   ­  Loosely  coupled  components   ­  Sharing  resources   ­  Async  execuCon   •  Scalable   •  Resilient   ­  IsolaCng  failure   ­  Build  supervision  hierachies   •  Responsive  

Slide 6

Slide 6 text

6   Yo  dawg,  I  heard  you  like  ships  events!  

Slide 7

Slide 7 text

7   Meet  Reactor.  

Slide 8

Slide 8 text

8   What  is  Reactor?   •  A  founda+onal  library  to  build     reac+ve  applica+ons.     •  Gray  area  between  user-­‐  and  low-­‐level  code.   •  Build  your  applica+on  cores  on  top  of  it.   •  Helps:  drivers,  servers,  libraries,  evented  architectures.   •  Maintained  by,  but  no  dependency  on  Spring.   •  Currently  in  RC  state!                                        (hGps://github.com/reactor/reactor)  

Slide 9

Slide 9 text

9   Landscape  

Slide 10

Slide 10 text

10   A  first  look  

Slide 11

Slide 11 text

11   Dispatchers   •  Created  on  an  Environment-­‐basis.   •  Dispatchers  manage  Task  Execu+on.     ­  ThreadPoolExecutorDispatcher   execuCng  tasks  in  a  thread  pool   ­  BlockingQueueDispatcher   event-­‐loop  style   ­  RingBufferDispatcher   uses  the  LMAX  Disruptor  RingBuffer   ­  SynchronousDispatcher   for  tesCng  

Slide 12

Slide 12 text

12   Selectors   •  LeY-­‐hand  side  of  an  equality  comparison.   •  Can  be  created  from  any  object.   ­  $(object)   ­  Selectors.object(obj)   •  Can  extract  data  from  the  matched  key.  

Slide 13

Slide 13 text

13   Selectors  -­‐  Regex   •  A  RegexSelector  will  match  a  String  by  execu+ng  the   regex.  

Slide 14

Slide 14 text

14   Selectors  -­‐  Templates   •  A  UriTemplateSelector  will  match  a  String  by  extrac+ng   bits  from  a  URI.  

Slide 15

Slide 15 text

15   Func+ons   •  Perform  work  on  T.     public  interface  Consumer  {    void  accept(T  t);   }   •  Supply  the  caller  with  T.     public  interface  Supplier  {    T  get();   }   •  Perform  work  on  T  and  return  V.     public  interface  Function  {    V  apply(T  t);   }   •  Check  if  the  input  matches  the  criteria.     public  interface  Predicate  {    boolean  test(T  t);   }  

Slide 16

Slide 16 text

16   Promises   •  Promises  allow  for  composi+on  of  func+ons   ­  Shares  common  funcCons  with  a  Stream  

Slide 17

Slide 17 text

17   Streams   •  Streams  allow  the  composi+on  of  func+ons   ­  Callback++   ­  NeYlix  RxJava  Observable,  JDK  8  Stream  

Slide 18

Slide 18 text

18   Processor   •  Thin  wrapper  around  the  Disruptor  RingBuffer   ­  Converts  Disruptor  API  to  Reactor  API   ­  Really  fast!  

Slide 19

Slide 19 text

19   Integra+on:  Spring   •  Helpers  to  integrate  Reactor  into  ApplicationContext   ­  @EnableReactor   ­  Wiring  annotated  handlers   •  DispatcherTaskExecutor   ­  Not  intended  for  “high  scale”   ­  Used  to  get  Spring  components  running  in  the  same  thread  as  Reactor   consumers.  

Slide 20

Slide 20 text

20   Integra+on:  Groovy   •  First  class  ci+zen  language  implementa+on     ­  @CompileStaCc  ready   ­  Prominent  use  of  Closure  as  Consumers,  FuncCons  and  more   ­  Operator  overloading   ­  Full  Reactor  system  Builder  

Slide 21

Slide 21 text

21   Integra+on:  Clojure   •  Meltdown:  A  Clojure  binding  by  @michaelklishin  and   @ifesdjeen   ­  h>ps://github.com/clojurewerkz/meltdown    

Slide 22

Slide 22 text

22   What  else?   •  Too  much  to  show  today!     ­  TCP  Client/Server  based  on  Ne>y  4   ­  Buffer  tooling   ­  Sequencing  for  event  ordering   ­  Work  Queue  support  on  top  of  Java  Chronicle   ­  Logback  Appender   ­  Language  Constructs  (Composables,  Tuples,…)  

Slide 23

Slide 23 text

23   Demo  

Slide 24

Slide 24 text

24   Ques+ons?  

Slide 25

Slide 25 text

25