© 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission.
Reactor: A Foundation for Reactive
FastDa...
The Spring IO Directory
Reactor – Housekeeping
● Tweet questions during the presentation
– @ProjectReactor
– @j_brisbin
– @smaldini
● Stop us anyw...
Reactor – What is it?
● Reactor is a foundational library
– Plays in grey area between user-level and lower-level
abstract...
Reactor – What is it?
● Reactor is a distillation of other libraries and best-practices
– Elements of other patterns and l...
Reactor – What can I build with it?
● Reactor applications are reactive
– Reactive Extensions in .NET
– Netflix RxJava
– O...
Reactor – Landscape
Reactor – What does it look like?
Environment env = new Environment();
Reactor reactor = Reactors.reactor()
.env(env)
.dis...
Reactor – Selectors
● Selectors are the left-hand side of an equality comparison
– A Selector can be created from any obje...
Reactor – Selectors
● A RegexSelector will match a String by executing the regex
over it
– R(“some.(.*)”)
– Selectors.rege...
Reactor – Selectors
● A UriTemplateSelector will match a String by extracting bits
from a URI
– U(“/some/{path}”)
– Select...
Reactor – Consumer, Function, Supplier, Predicate
public interface Consumer<T> {
void accept(T t);
}
public interface Supp...
Reactor – Stream
● Streams allow for composition of functions on data
– Callback++
– Netflix RxJava Observable, JDK 8 Stre...
Reactor – Promise
● Promises allow for composition of functions on data
– Share common functions with Stream
Promise<Strin...
Reactor – Processor
● Thin wrapper around Disruptor RingBuffer
– Converts Disruptor API to Reactor API
– Uber fast perform...
Reactor – Spring
● Helpers to integrate Reactor into ApplicationContext
– @EnableReactor for easy configuration
– Wiring a...
Reactor – Spring
@Configuration
@EnableReactor
public class ReactorConfiguration {
@Bean
public Reactor input(Environment ...
Reactor – Spring
@Component
public class SimpleHandler {
@Autowired
private Reactor reactor;
@Selector(“test.topic”)
publi...
Reactor – Spring
● DispatcherTaskExecutor
– Not really a high-scale TaskExecutor
– Used to get Spring components running i...
Reactor – Groovy
● First class citizen language implementation
– @CompileStatic ready
– Prominent use of Closure as Consum...
Reactor – Groovy : Notification and Consumer
@CompileStatic
def welcome(){
reactor.on('greetings') { String s ->
reply “he...
Reactor – Groovy : Promises and Streams
def promise = Promises.task { longStuff(); 1 } get()
def transformation = c | { it...
Reactor – Groovy : Environment
GroovyEnvironment.create {
environment {
defaultDispatcher = "test"
dispatcher('test') {
ty...
Reactor – Groovy : Environment
GroovyEnvironment.create {
reactor('test1') {
stream('test') {
consume{ ev->
log.info ev.da...
Reactor – Extensive awesomeness
● TCP Client/Server, with a Netty 4 implementation
● Buffer tools
● Sequencer support, for...
Reactor – Roadmap
● 1.0 feature complete
– 1.0 M3 on its way
– 1.0 RC1 – within a week
– 1.0 GA – within a month
Reactor – Roadmap
● 1.1 Discussions
– StateBox: A safe tool for concurrent writes
– Better Timer management
– Spring XD, S...
Reactor – Uber Community contributions
● Meltdown: A Clojure binding by @michaelklishin & @ifesdjeen
– https://github.com/...
Reactor – Uber Community contributions
● High Performance Couchbase ingestion by @daschl
– http://nitschinger.at/Using-the...
Learn More. Stay Connected.
● Github organization : http://github.com/reactor
● Follow-up:
– Spring XD
– Spring 4 WebSocke...
Upcoming SlideShare
Loading in...5
×

Reactor spring one2gx_2013_0902-final

1,856

Published on

Reactor talk at SpringOne 2gx by @j_brisbin and @smaldini

Published in: Technology

Reactor spring one2gx_2013_0902-final

  1. 1. © 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission. Reactor: A Foundation for Reactive FastData Applications on the JVM Jon Brisbin – @j_brisbin Stephane Maldini – @smaldini
  2. 2. The Spring IO Directory
  3. 3. Reactor – Housekeeping ● Tweet questions during the presentation – @ProjectReactor – @j_brisbin – @smaldini ● Stop us anywhere if you have a question – There are no stupid questions, only stupid answers!
  4. 4. Reactor – What is it? ● Reactor is a foundational library – Plays in grey area between user-level and lower-level abstractions – Components and application cores can be built on Reactor – Drivers, servers, data integration libraries, domain integration libraries, Evented architectures
  5. 5. Reactor – What is it? ● Reactor is a distillation of other libraries and best-practices – Elements of other patterns and libraries surface throughout Reactor's abstractions http://stackoverflow.com/questions/16595393/akka-or-reactor
  6. 6. Reactor – What can I build with it? ● Reactor applications are reactive – Reactive Extensions in .NET – Netflix RxJava – Observer pattern ● Reactor applications route events based on a Selector – Like a routing topic, but can be any object – Regex, URI template, Class.isAssingableFrom, custom logic
  7. 7. Reactor – Landscape
  8. 8. Reactor – What does it look like? Environment env = new Environment(); Reactor reactor = Reactors.reactor() .env(env) .dispatcher(RING_BUFFER) .get(); reactor.on($(“topic”), (Event<String> ev) → { System.out.println(“Hello “ + ev.getData()); }); reactor.notify(“topic”, Event.wrap(“John Doe”));
  9. 9. Reactor – Selectors ● Selectors are the left-hand side of an equality comparison – A Selector can be created from any object using $(obj) (or the long form: Selectors.object(obj)) – A Selector can extract data from the matched key – Predicate<T> Selectors can be created to match on domain-specific criteria like header values
  10. 10. Reactor – Selectors ● A RegexSelector will match a String by executing the regex over it – R(“some.(.*)”) – Selectors.regex(“some.(.*)”) reactor.on(R(“some.(.+)”), (Event<String> ev) → { // s will be 'topic' String s = ev.getHeaders().get(“group1”); }); reactor.notify(“some.topic”, Event.wrap(“John Doe”));
  11. 11. Reactor – Selectors ● A UriTemplateSelector will match a String by extracting bits from a URI – U(“/some/{path}”) – Selectors.uri(“/some/{path}”) reactor.on(U(“/some/{topic}”), (Event<String> ev) → { // s will be 'topic' String s = ev.getHeaders().get(“topic”); }); reactor.notify(“/some/topic”, Event.wrap(“John Doe”));
  12. 12. Reactor – Consumer, Function, Supplier, Predicate public interface Consumer<T> { void accept(T t); } public interface Supplier<T> { T get(); } public interface Function<T, V> { V apply(T t); } public abstract class Predicate<T> { boolean test(T t); }
  13. 13. Reactor – Stream ● Streams allow for composition of functions on data – Callback++ – Netflix RxJava Observable, JDK 8 Stream Stream<String> str; str.map(String::toUpperCase) .filter(new Predicate() { public boolean test(String s) { … } }) .consume(s → log.info(“consumed string {}”, s));
  14. 14. Reactor – Promise ● Promises allow for composition of functions on data – Share common functions with Stream Promise<String> p; String s = p .onSuccess(s → log.info(“consumed string {}”, s)) .onFailure(t → log.error(t.getMessage(), t)) .onComplete(log.info(“complete”)) .await(5, SECONDS); p.map(String::toUpperCase).consume(s → log.info(“UC: {}”, s));
  15. 15. Reactor – Processor ● Thin wrapper around Disruptor RingBuffer – Converts Disruptor API to Reactor API – Uber fast performance for #UberFastData Processor<Buffer> proc; Operation<Buffer> op = proc.prepare(); op.get().append(data).flip(); op.commit(); proc.batch(512, buff → buff.append(data).flip());
  16. 16. Reactor – Spring ● Helpers to integrate Reactor into ApplicationContext – @EnableReactor for easy configuration – Wiring annotated handlers
  17. 17. Reactor – Spring @Configuration @EnableReactor public class ReactorConfiguration { @Bean public Reactor input(Environment env) { return Reactors.reactor().env(env) .dispatcher(RING_BUFFER).get(); } @Bean public Reactor output(Environment env) { return Reactors.reactor().env(env) .dispatcher(RING_BUFFER).get();
  18. 18. Reactor – Spring @Component public class SimpleHandler { @Autowired private Reactor reactor; @Selector(“test.topic”) public void onTestTopic(String s) { // Handle data } }
  19. 19. Reactor – Spring ● DispatcherTaskExecutor – Not really a high-scale TaskExecutor – Used to get Spring components running in same thread as Reactor Consumers ● ConversionService integration ● PromiseHandlerMethodReturnValueHandler (!) ● ReactorSubscribableChannel
  20. 20. Reactor – Groovy ● First class citizen language implementation – @CompileStatic ready – Prominent use of Closure as Consumers, Functions and more – Operator overloading for elegant programming – Full Reactor system Builder
  21. 21. Reactor – Groovy : Notification and Consumer @CompileStatic def welcome(){ reactor.on('greetings') { String s -> reply “hello $s” reply “how are you?” } reactor.notify 'greetings', 'Jon' reactor.send('greetings', 'Stephane'){ println it cancel() } }
  22. 22. Reactor – Groovy : Promises and Streams def promise = Promises.task { longStuff(); 1 } get() def transformation = c | { it + 1 } transformation.await() == 2 def deferredStream = Streams.defer().get() (deferredStream & { it > 2 }) << { send(it) } deferredStream << 1 << 2 << 3 << 4
  23. 23. Reactor – Groovy : Environment GroovyEnvironment.create { environment { defaultDispatcher = "test" dispatcher('test') { type = DispatcherType.SYNCHRONOUS } } }
  24. 24. Reactor – Groovy : Environment GroovyEnvironment.create { reactor('test1') { stream('test') { consume{ ev-> log.info ev.data } } on('test') { reply it } } }
  25. 25. Reactor – Extensive awesomeness ● TCP Client/Server, with a Netty 4 implementation ● Buffer tools ● Sequencer support, for event ordering ● Work Queue support, with OoB Java Chronicle implementation ● Log Appender
  26. 26. Reactor – Roadmap ● 1.0 feature complete – 1.0 M3 on its way – 1.0 RC1 – within a week – 1.0 GA – within a month
  27. 27. Reactor – Roadmap ● 1.1 Discussions – StateBox: A safe tool for concurrent writes – Better Timer management – Spring XD, Spring 4 – Exploring Distributed Reactors ● Voice your interest and your use-case here
  28. 28. Reactor – Uber Community contributions ● Meltdown: A Clojure binding by @michaelklishin & @ifesdjeen – https://github.com/clojurewerkz/meltdown
  29. 29. Reactor – Uber Community contributions ● High Performance Couchbase ingestion by @daschl – http://nitschinger.at/Using-the-Reactor-Processor-for-High-Performance-TCP ● Benefits of using Reactor Processor, TCP and Batching facilities
  30. 30. Learn More. Stay Connected. ● Github organization : http://github.com/reactor ● Follow-up: – Spring XD – Spring 4 WebSocket – Grails and the realtime web Talk to us on Twitter: @ProjectReactor Find Session replays on YouTube: spring.io/video
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×