full stack reactive nosql: spring data and couchbase

23
Full Stack Reactive NoSQL Spring Data and Couchbase Matt Ingenthron @ingenthr Subhashni Balakrishnan @subalakr

Upload: spring-by-pivotal

Post on 21-Jan-2018

828 views

Category:

Technology


7 download

TRANSCRIPT

Page 1: Full Stack Reactive NoSQL: Spring Data and Couchbase

Full Stack Reactive NoSQLSpring Data and Couchbase

Matt Ingenthron @ingenthr

Subhashni Balakrishnan @subalakr

Page 2: Full Stack Reactive NoSQL: Spring Data and Couchbase

2

AGENDA01/ Reactive Programming

02/Building a Reactive Repository with Spring

Framework 5

03/ Let's do it Live

04/ Next Steps

Page 3: Full Stack Reactive NoSQL: Spring Data and Couchbase

Reactive Programming

3

1

Page 4: Full Stack Reactive NoSQL: Spring Data and Couchbase

Motivation for Reactive

4

Resilient

• System stays responsive even when failures occur

• Data is replicated, failures are contained within each

component

• Component client abstracted from failures

Message Driven

• System uses asynchronous message passing

• Applies back-pressure to degrade gracefully

• Communication is non-blocking to only consume

resources while active, lowering overhead

Responsive

• System responds quickly

• Allows for more engaging experiences for users

• Has consistent response times for consistent quality of

service

Elastic

• System stays responsive under varying workload

• System allows addition of resources without interruption

of existing workload

© Couchbase 2017. All rights reserved.

Image courtesy

reactivemanifesto.org

Page 5: Full Stack Reactive NoSQL: Spring Data and Couchbase

Async Programming Without Reactive

6© Couchbase 2017. All rights reserved.

client.asyncGet("posts::1").addListener(future -> {if (future.isDone() && !future.isCancelled()) {

String content = (String) future.get();List<String> ids =

comments_ids_from_json(content);

int i = 0;for (String id : ids) {

if (i++ == 5) {break;

}client.asyncGet(id).addListener(future1 -> {

if (future1.isDone() && !future1.isCancelled()) {System.out.println(future1.get());

}});

}}

});

Page 6: Full Stack Reactive NoSQL: Spring Data and Couchbase

Reactive Asynchronous Programming

7© Couchbase 2017. All rights reserved.

bucket.get("posts::1").map(document -> document.content().getArray("comments")).flatMap(comments -> Observable.from(comments.toList())).take(5).filter(o -> o instanceof String).flatMap(o -> bucket.get((String) o)).subscribe(doc -> System.out.println(doc.content()));

Page 7: Full Stack Reactive NoSQL: Spring Data and Couchbase

Modern Reactive Internals

8© Couchbase 2017. All rights reserved.

Flux<Person> findByFirstname(St ring fi rstname);

Java SDK

Spring Data Couchbase

Java SDK (core-io)

Request/ Response Flow

Request

RingBuf erCouchbaseCore

(1)

publishes

Observable

(2) returns

(3a) maybe

fails fast

RequestHandler

(3b)

not ifies

Node

Service

Endpoint

(4)

locates

(5)

selects

(6)

selects

Net tyChannel

s

Net tyChannel

s

Net ty

Channels

Net ty

Channels

Net tyChannel

s

Net tyChannel

s

Net tyChannel

s

(7)

w rit es int o

(8)

sends t o CB

(9)

reads from CB

(10 a)

complet es

(10 b)

fails

Application

Method Calls

Page 8: Full Stack Reactive NoSQL: Spring Data and Couchbase

Couchbase is End to End Reactive

9© Couchbase 2017. All rights reserved.

Couchbase Server

Couchbase IO EngineJava SDK (core-io)

Request/ Response Flow

Request

RingBuf erCouchbaseCore

(1)

publishes

Observable

(2) returns

(3a) maybe

fails fast

RequestHandler

(3b)

not ifies

Node

Service

Endpoint

(4)

locates

(5)

selects

(6)

selects

Net tyChannel

s

Net tyChannel

s

Net tyChannel

s

Net ty

Channels

Net tyChannel

s

Net tyChannel

s

Net tyChannel

s

(7)

w rit es int o

(8)

pipelines

requests

(9)

sends

responses

(10 a)

completes

(10 b)

fails

couchstore

Hashtable

mc:w orker <N>mc:w orker <N>mc:worker <N>mc:w orker <N>

(1)

request it em

from engine

memory cache

(7)

not ifies complet ion

(4a)

not ifies complet ion

(maybe)

ep:io

ep:nio

(4b)

requests

backfi ll

(5)

async IO request

(6)

IO complet ion

(2)

looks up it em

(3)

returns

metadata

Page 9: Full Stack Reactive NoSQL: Spring Data and Couchbase

Poll

© Couchbase 2017. All rights reserved.

Page 10: Full Stack Reactive NoSQL: Spring Data and Couchbase

Building a Reactive Repository with Spring Framework 5

11

2

Page 11: Full Stack Reactive NoSQL: Spring Data and Couchbase

Reactive Programming Model

12© Couchbase 2017. All rights reserved.

Publisher Subscriber

Page 12: Full Stack Reactive NoSQL: Spring Data and Couchbase

Reactive Composeable API

13

Reactor

Mono [0 | 1]

Flux [N]

RxJava

Observable [N]

© Couchbase 2017. All rights reserved.

Page 13: Full Stack Reactive NoSQL: Spring Data and Couchbase

Reactive Couchbase Client

14© Couchbase 2017. All rights reserved.

Page 14: Full Stack Reactive NoSQL: Spring Data and Couchbase

Reactive Template

15© Couchbase 2017. All rights reserved.

Page 15: Full Stack Reactive NoSQL: Spring Data and Couchbase

Reactive Repository

16© Couchbase 2017. All rights reserved.

Page 16: Full Stack Reactive NoSQL: Spring Data and Couchbase

Full Stack Reactive Web Application - Components

17

• http layer using Spring web flux

• Data access using Spring Data Couchbase

© Couchbase 2017. All rights reserved.

Page 17: Full Stack Reactive NoSQL: Spring Data and Couchbase

Reactive Flow

18© Couchbase 2017. All rights reserved.

Page 18: Full Stack Reactive NoSQL: Spring Data and Couchbase

Let's Do It Live

19

3

Page 19: Full Stack Reactive NoSQL: Spring Data and Couchbase

Activity Tracker Application

20© Couchbase 2017. All rights reserved.

Couchbase Cluster

Couchbase Node

Browser

Spring Boot App

Spring Boot

Spring Framework 5

Spring Data 2.0 (Kay)

Spring Data Couchbase 3.0

act ivityTracker

Bucket

KV

Se

rvic

e

Qu

ery

Se

rvic

e

Oth

er

Se

rvic

es

Couchbase Node

act ivityTracker

Bucket

KV

Se

rvic

e

Qu

ery

Se

rvic

e

Oth

er

Se

rvic

es

Sp

rin

g D

ata

Co

uc

hb

ase

/ leader

/ leaderSt ream

Spring

@GetMapping()

Page 20: Full Stack Reactive NoSQL: Spring Data and Couchbase

Summary, Next Steps

21

4

Page 21: Full Stack Reactive NoSQL: Spring Data and Couchbase

Summary

22

Today's Demo

https://github.com/subalakr/springdatareactive

Spring Data Couchbase

http://projects.spring.io/spring-data-couchbase/

Try Spring Data Kay

http://projects.spring.io/spring-data/#quick-start

(select Kay-M4 from the pulldown)

Spring Data on GitHub

https://github.com/spring-projects/spring-data-

couchbase/

• Awesomeness with reactive programming in

Spring Framework 5 using the Couchbase

reactive core

• Reactive template and repository introduced in

Spring data Couchbase Kay

• End-to-end reactive web application for activity

tracking

• Spring data Couchbase is • Fully Java 8

• Supports other cool features:• DTO projections

• Java 8 time support

• Auto-generation of IDs

• Kotlin support is in the works

© Couchbase 2017. All rights reserved.

Page 22: Full Stack Reactive NoSQL: Spring Data and Couchbase

Now is the

Time for Your

Feedback

Try the Spring Data

Milestone Build with

Spring Data Couchbase

http://projects.spring.io/spring-

data/#quick-start (Select Kay-M4)

Attend Couchbase Connect!

http://connect.couchbase.com

Europe– Paris

26 September 2017

Silicon Valley

Fall 2017

23Couchbase 2017. All rights reserved.

Page 23: Full Stack Reactive NoSQL: Spring Data and Couchbase

Thank you

©2017 Couchbase. All rights reserved. 24