Reactive Programming

For The JVM

Deven Phillips

Senior Software Engineer

Sungard Availability Services

July 2015

Java Users Group of Greater Louisville

What Is Reactive?

1. Responsive

2. Resilient

3. Elastic

4. Message Driven

http://www.reactivemanifesto.org/

Responsive

1. Fast Failure

2. Reliable Timeouts

3. Builds Confidence

Resilient

1. Replication

2. Containment

3. Isolation

4. Recovery

5. Testing

Elastic

1. Sharding

2. Replication

3. Scaling

4. Monitoring

Message Driven

1. Location Transparency

2. Loose Coupling

3. Fault Isolation

4. Error Delegation

So, what is reactive?

"Reactive programming is programming with asynchronous data streams..." - André Staltz

https://gist.github.com/staltz/868e7e9bc2a7b8c1f754

Reactive Tools

For The JVM

  • RxJava
  • Quasar
  • Akka/Play
  • Vert.X

RxJava

/*
 * Fetch a list of Wikipedia articles asynchronously, with error handling.
 */
def fetchWikipediaArticleAsynchronouslyWithErrorHandling(String... wikipediaArticleNames) {
    return Observable.create({ subscriber ->
        Thread.start {
            try {
                for (articleName in wikipediaArticleNames) {
                    if (true == subscriber.isUnsubscribed()) {
                        return;
                    }
                    subscriber.onNext(new URL("http://en.wikipedia.org/wiki/"+articleName).getText());
                }
                if (false == subscriber.isUnsubscribed()) {
                    subscriber.onCompleted();
                }
            } catch(Throwable t) {
                if (false == subscriber.isUnsubscribed()) {
                    subscriber.onError(t);
                }
            }
            return (subscriber);
        }
    });
}

Quasar

  • Fibers
  • Actors
  • Behaviors
  • Supervisors
  • Channels

Vert.X

  • Verticles
  • Event Bus
  • Buffers
  • Supervisor
  • Polyglot

Akka/Play Framework

  • Actors
  • Message Bus
  • Supervisors
  • Activator

Which Is The Best?

That's up to you to decide...

 

The answer varies depending on the application and the team and the company you are working for!

Let's Look At Some Code!

Reactive Programming For The JVM

By Deven Phillips

Reactive Programming For The JVM

A basic introduction to reactive programming concepts and tools for the Java Virtual Machine

  • 1,427