data microservices with spring cloud stream, task, and data flow #jsug #springday

117
‹#› © 2016 Pivotal Software, Inc. All rights reserved. Data Microservices with Spring Cloud Stream, Task, and Data Flow Toshiaki Maki (@making) 2016-11-18 Spring Day 2016 #springday #jsug

Upload: toshiaki-maki

Post on 06-Jan-2017

3.699 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved. ‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Data Microservices with Spring Cloud Stream, Task, and Data Flow

Toshiaki Maki (@making) 2016-11-18 Spring Day 2016 #springday #jsug

Page 2: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Who am I ?• Toshiaki Maki (@making) http://blog.ik.am

•Sr. Solutions Architect @Pivotal

•Spring Framework enthusiast

bit.ly/hajiboot2

Page 3: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Input

Motivation

HTTP

TCP

S3

JDBC

Rabbit

JMS

Twitter

Syslog

Output

HDFS

Cassandra

HAWQ

Greenplum

JDBC

S3

TCP

Gemfire

❓❔❓

• Real Time Analysis • Data Ingestion • ETL Process

Page 4: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring XD (eXtreme Data)

Page 5: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring XD (eXtreme Data)

🤔

Page 6: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring XD Architecture

Container Containergpfdist

Cassandra

jms

http

ZooKeeper

Message Broker

XD Admin

stream1 = http | cassandrastream2 = jms | gpfdist

On Metal/VMs

Page 7: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring XD Architecture

Container Containergpfdist

Cassandra

jms

http

ZooKeeper

Message Broker

XD Admin

stream1 = http | cassandrastream2 = jms | gpfdist

On Metal/VMs

😇

Page 8: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring XD Architecture

Container Containergpfdist

Cassandra

jms

http

ZooKeeper

Message Broker

XD Admin

stream1 = http | cassandrastream2 = jms | gpfdist

On Metal/VMs

Page 9: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Modern Platforms

Cloud Foundry YARN Kubernetes Mesos

Docker Swarm Nomad OpenShift

Page 10: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Cloud Native Redesign

•From multiple modules embedded in a container to standalone executable applications •From our own runtime to delegating to existing modern platforms

Page 11: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Data Microservices

$ cat book.txt | tr ' ' '¥ ' | tr '[:upper:]' '[:lower:]' | tr -d '[:punct:]' | grep -v '[^a-z]‘ | sort | uniq -c | sort -rn | head

Page 12: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Data Microservices

$ cat book.txt | tr ' ' '¥ ' | tr '[:upper:]' '[:lower:]' | tr -d '[:punct:]' | grep -v '[^a-z]‘ | sort | uniq -c | sort -rn | head

Page 13: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Data Microservices

$ cat book.txt | tr ' ' '¥ ' | tr '[:upper:]' '[:lower:]' | tr -d '[:punct:]' | grep -v '[^a-z]‘ | sort | uniq -c | sort -rn | head

Microservice for each data processing

Page 14: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Data Microservices

$ cat book.txt | tr ' ' '¥ ' | tr '[:upper:]' '[:lower:]' | tr -d '[:punct:]' | grep -v '[^a-z]‘ | sort | uniq -c | sort -rn | head

Microservice for each data processing

Page 15: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Data Microservices

$ cat book.txt | tr ' ' '¥ ' | tr '[:upper:]' '[:lower:]' | tr -d '[:punct:]' | grep -v '[^a-z]‘ | sort | uniq -c | sort -rn | head

Microservice for each data processing

bound with Message Brokers

Page 16: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Data Microservices

$ cat book.txt | tr ' ' '¥ ' | tr '[:upper:]' '[:lower:]' | tr -d '[:punct:]' | grep -v '[^a-z]‘ | sort | uniq -c | sort -rn | head

Microservice for each data processing

bound with Message Brokers

Page 17: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Data Microservices

$ cat book.txt | tr ' ' '¥ ' | tr '[:upper:]' '[:lower:]' | tr -d '[:punct:]' | grep -v '[^a-z]‘ | sort | uniq -c | sort -rn | head

Microservice for each data processing

bound with Message Brokers

on the modern platform

Page 18: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Data Microservices

$ cat book.txt | tr ' ' '¥ ' | tr '[:upper:]' '[:lower:]' | tr -d '[:punct:]' | grep -v '[^a-z]‘ | sort | uniq -c | sort -rn | head

Microservice for each data processing

bound with Message Brokers

on the modern platform

Page 19: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Data Microservices

$ cat book.txt | tr ' ' '¥ ' | tr '[:upper:]' '[:lower:]' | tr -d '[:punct:]' | grep -v '[^a-z]‘ | sort | uniq -c | sort -rn | head

Microservice for each data processing

bound with Message Brokers

on the modern platform

Page 20: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring Cloud Data Flow• Microservices-based Distributed Data Pipelines •Long Lived Stream Applications

•Short Lived Task Applications

Page 21: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring Cloud Data Flow• Microservices-based Distributed Data Pipelines •Long Lived Stream Applications

•Short Lived Task ApplicationsSpring Cloud Stream

Page 22: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring Cloud Data Flow• Microservices-based Distributed Data Pipelines •Long Lived Stream Applications

•Short Lived Task ApplicationsSpring Cloud Stream

Spring Cloud Task

Page 23: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring Cloud Data Flow• Microservices-based Distributed Data Pipelines •Long Lived Stream Applications

•Short Lived Task ApplicationsSpring Cloud Stream

Spring Cloud Task

Orchestration Layer

Page 24: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

StructureSpring Cloud Data Flow

Spring Cloud Deployer (SPI)

Spring Cloud Stream Spring Cloud Task

Spring Integration Spring Boot Spring Batch

Page 25: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

StructureSpring Cloud Data Flow

Spring Cloud Deployer (SPI)

Spring Cloud Stream Spring Cloud Task

Spring Integration Spring Boot Spring Batch

• Spring Cloud Deployer Local • Spring Cloud Deployer Cloud Foundry • Spring Cloud Deployer Yarn • Spring Cloud Deployer Kubernetes • Spring Cloud Deployer Mesos

Page 26: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

SCDF Deployment Platform

Spring Cloud Data Flow Server

Deployer SPI

REST API

SCDF Shell SCDF Flo

Page 27: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring Cloud Data Flow Architecture

gpfdist

cassandra

jms

http

stream1 = http | cassandrastream2 = jms | gpfdist

Message Broker

Data Flow Server DB

Platform Runtime

Page 28: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring Cloud Data Flow Architecture

gpfdist

cassandra

jms

http

stream1 = http | cassandrastream2 = jms | gpfdist

Message Broker

Data Flow Server DB

Platform Runtime

Page 29: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring Cloud Stream

Page 30: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring Cloud Stream•Event-driven microservice framework

•Built on battle-tested components (Spring Boot / Spring Integration)

•Opinionated primitives for streaming applications

•Persistent Pub/Sub

•Consumer Groups

•Partitioning Support

•Pluggable messaging middleware bindings

source | processor | sink

Page 31: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

JJUG CCC in 2 weeks

Page 32: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring Cloud Stream Applications

Twitter Stream

Cassandra

java -jar twittersource.jar --server.port=8080 --consumerKey=XYZ --consumerSecret=ABC --spring.cloud.stream.bindings. output.destination=ingest

Source

Sink java -jar cassandrasink.jar --server.port=8081 --spring.cassandra.keyspace=tweet --spring.cloud.stream.bindings. input.destination=ingest

Page 33: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring Cloud Stream Applications

Twitter Stream

Cassandra

java -jar twittersource.jar --server.port=8080 --consumerKey=XYZ --consumerSecret=ABC --spring.cloud.stream.bindings. output.destination=ingest

Source

Sink java -jar cassandrasink.jar --server.port=8081 --spring.cassandra.keyspace=tweet --spring.cloud.stream.bindings. input.destination=ingest

TwitterStream Cassandraingest

Page 34: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Message Binders• @EnableBinding•Binder Implementations

•Production-Ready

•Rabbit MQ

•Apache Kafka

•Experimental

• JMS

•Google PubSub

Page 35: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Programming Model (Sink)@SpringBootApplication @EnableBinding(Sink.class) public class DemoSinkApp { @StreamListener(Sink.INPUT) void receive(Message<String> message) { System.out.println("Received " + message); } public static void main(String[] args) { SpringApplication.run(DemoSinkApp.class, args); } }

Page 36: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Sink

Properties (Sink)

spring.cloud.stream.bindings.input.destination=demo-strm

demo-strm in

put

Page 37: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Programming Model (Source)@SpringBootApplication @RestController@EnableBinding(Source.class) public class DemoSourceApp { @Autowired Source source; @GetMapping void send(@RequestParam String text) { source.output() .send(MessageBuilder.withPayload(text).build()); } public static void main(String[] args) { SpringApplication.run(DemoSourceApp.class, args); } }

Page 38: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Programming Model (Source)@SpringBootApplication @RestController@EnableBinding(Source.class) public class DemoSourceApp { @Bean @InboundChannelAdapter(channel = Source.OUTPUT, poller = @Poller(fixedDelay = "1000", maxMessagesPerPoll = "1")) MessageSource<String> source() { return () -> MessageBuilder.withPayload("Hi").build()); } public static void main(String[] args) { SpringApplication.run(DemoSourceApp.class, args); }}

Page 39: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Properties (Source)

spring.cloud.stream.bindings.output.destination=demo-strm

demo-strm

Source

outp

ut

Page 40: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Binder (RabbitMQ)<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-stream-rabbit</artifactId></dependency>

demo-strm

Page 41: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Binder (Apache Kafka)<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-stream-kafka</artifactId></dependency>

demo-strm

Page 42: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Sink

Pipeline

demo-strm in

put

Source

outp

ut

source | sink

Page 43: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Programming Model (Processor)@SpringBootApplication @EnableBinding(Processor.class) public class DemoProcessorApp { @StreamListener(Processor.INPUT) @SendTo(Processor.OUTPUT) void receive(String text) { return "[[" + text + "]]"; } public static void main(String[] args) { SpringApplication.run(DemoProcessorApp.class, args); } }

Page 44: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Properties (Processor)

spring.cloud.stream.bindings.output.destination=my-source

spring.cloud.stream.bindings.input.destination=my-sourcespring.cloud.stream.bindings.output.destination=my-proc

spring.cloud.stream.bindings.input.destination=my-proc

Source

Processor

Sink

Page 45: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Pipeline

my-source

Source

outp

utsource | processor | sink

Processor

outp

ut

inpu

t

my-proc

Sink

inpu

t

Page 46: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Reactive API Support@SpringBootApplication @EnableBinding(Processor.class) public class DemoProcessorRxApp { @StreamListener @Output(Processor.OUTPUT) public Flux<String> receive(@Input(Processor.INPUT) Flux<String> stream) { return stream.map(text -> "[[" + text + "]]"); } public static void main(String[] args) { SpringApplication.run(DemoProcessorRxApp.class, args); } }

Page 47: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Reactive API Support

@StreamListener @Output(Processor.OUTPUT) public Flux<AverageData> receive(@Input(Processor.INPUT) Flux<SensorData> stream) { return stream.window(Duration.ofSecond(20), Duration.ofSecond(10)) .flatMap(win -> win.groupBy(sensor -> sensor.id)) .flatMap(group -> calcAverage(group));}

Page 48: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring Cloud Stream App StartersSource Processor Sink

file ftp gemfire gemfire-cq http jdbc jms load-generator loggregator mail mongodb rabbit

s3 sftp syslog tcp tcp-client time trigger triggertask twitterstream

bridge filter groovy-filter groovy-transform httpclient pommel scriptable-transform splitter tcp-client transform

aggregate-counter cassandra counter field-value-counter file ftp gemfire gpfdist hfs hdfs-dataset jdbc

log rabbit redis-pubsub router s3 sftp task-launcher-local task-lancher-yarn tcp throughput web socket

http://cloud.spring.io/spring-cloud-stream-app-starters/

Page 49: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Stream Orchestration in SCDFingest = twitterstream | cassandra

dataflow:> stream create --name=ingest --definition="twitterstream | cassandra"dataflow:> stream deploy --name=ingest

|

Page 50: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Import apps

dataflow:> app import --uri http://bit.ly/1-0-4-GA-stream-applications-rabbit-maven

rabbit mavenkafka docker

stream-applications-

http://cloud.spring.io/spring-cloud-stream-app-starters/

Page 51: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Register your own apps

dataflow:> app register --name foo --type source --uri http://example.com/foo-source-1.0.jar

dataflow:> app register --name foo --type source --uri maven://com.example:foo-source:1.0dataflow:> app register --name foo --type source --uri docker:myapps/foo-source:1.0

dataflow:> app register --name foo --type source --uri file:///tmp/foo-source:1.0

Page 52: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Instance Count

dataflow:> stream create --name=s1 --definition="http | work | hdfs"dataflow:> stream deploy --name=s1 --properties="app.http.count=2,app.work.count=3,app.hdfs.count=4"

Page 53: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Instance Count

http

work

hdfs

http

work

work

hdfs

hdfs

hdfs

Load

Bal

ance

r

Page 54: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Resource Management

dataflow:> stream deploy --name=s1 --properties="app.work.spring.cloud.deployer.cloudfoundry.memory=2048"

Page 55: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Resource Management

http

http

work

work

work

hdfs

hdfs

hdfs

hdfs

Page 56: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring Flo http://projects.spring.io/spring-flo/

Page 57: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Stream Core Features•Persistent Pub-Sub •Consumer Group •Partitioning Support

Page 58: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Persistent Pub-Sub

HTTP Average Top Ns1.http s1.ave

Message Broker

Page 59: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Persistent Pub-Sub

HTTP Average

HDFS

Top Ns1.http s1.ave

Message Broker

Page 60: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Persistent Pub-Sub

HTTP Average

HDFS

Top N

FaultDetection

s1.http s1.ave

Message Broker

Page 61: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Persistent Pub-Sub

HTTP Average

HDFS

Top N

FaultDetection

s1.http s1.ave

Message Broker

{"id":1, "temperature":38}

Page 62: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Persistent Pub-Sub

HTTP Average

HDFS

Top N

FaultDetection

s1.http s1.ave

Message Broker

{"id":1, "temperature":38}{"id":1, "temperature":38}

Page 63: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Persistent Pub-Sub

HTTP Average

HDFS

Top N

FaultDetection

s1.http s1.ave

Message Broker

{"id":1, "temperature":38}

{"id":1, "temperature":38}

{"id":1, "temperature":38}

Page 64: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Persistent Pub-Sub

HTTP Average

HDFS

Top N

FaultDetection

s1.http s1.ave

Message Broker

{"id":1, "temperature":38}

{"id":1, "temperature":38} {"id":1, "temperature":38}

Page 65: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

HTTP Average

HDFS

Top N

FaultDetection

s1.http s1.ave

Message Broker

AverageAverage

HDFSHDFS

Page 66: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

HTTP Average

HDFS

Top N

FaultDetection

s1.http s1.ave

Message Broker

{"id":1, "temperature":38}

AverageAverage

HDFSHDFS

Page 67: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

HTTP Average

HDFS

Top N

FaultDetection

s1.http s1.ave

Message Broker

{"id":1, "temperature":38}{"id":1, "temperature":38}

AverageAverage

HDFSHDFS

Page 68: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

HTTP Average

HDFS

Top N

FaultDetection

s1.http s1.ave

Message Broker

{"id":1, "temperature":38}

{"id":1, "temperature":38}

AverageAverage

HDFSHDFS

{"id":1, "temperature":38}

{"id":1, "temperature":38}

{"id":1, "temperature":38}

{"id":1, "temperature":38}

Page 69: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

HTTP Average

HDFS

Top N

FaultDetection

s1.http s1.ave

Message Broker

{"id":1, "temperature":38}

{"id":1, "temperature":38}

AverageAverage

HDFSHDFS

{"id":1, "temperature":38}

{"id":1, "temperature":38}

{"id":1, "temperature":38}

{"id":1, "temperature":38}

😩

Page 70: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

HTTP Average

HDFS

Top N

FaultDetection

s1.http s1.ave

Message Broker

{"id":1, "temperature":38}

{"id":1, "temperature":38}

AverageAverage

HDFSHDFS

{"id":1, "temperature":38}

{"id":1, "temperature":38}

{"id":1, "temperature":38}

{"id":1, "temperature":38}

😩

Consumer Group

Page 71: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

HTTP Average

HDFS

Top N

FaultDetection

s1.http s1.ave

Message Broker

{"id":1, "temperature":38}

{"id":1, "temperature":38}

AverageAverage

HDFSHDFS

{"id":1, "temperature":38}

{"id":1, "temperature":38}

{"id":1, "temperature":38}

{"id":1, "temperature":38}

😩spring.cloud.stream.bindings.<channelName>.group=ave

Spring Cloud Stream

group is configured by default 😁

Spring Cloud Data Flow

Consumer Group

Page 72: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Consumer Group

HTTP Average

HDFS

Top N

FaultDetection

s1.http s1.ave

Message Broker

AverageAverage

HDFSHDFS

group=ave

group=hdfs

Page 73: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Consumer Group

HTTP Average

HDFS

Top N

FaultDetection

s1.http s1.ave

Message Broker

AverageAverage

HDFSHDFS

group=ave

group=hdfs

{"id":1, "temperature":38}

Page 74: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Consumer Group

HTTP Average

HDFS

Top N

FaultDetection

s1.http s1.ave

Message Broker

AverageAverage

HDFSHDFS

group=ave

group=hdfs

{"id":1, "temperature":38}{"id":1, "temperature":38}

Page 75: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Consumer Group

HTTP Average

HDFS

Top N

FaultDetection

s1.http s1.ave

Message Broker

AverageAverage

HDFSHDFS

group=ave

group=hdfs

{"id":1, "temperature":38}

{"id":1, "temperature":38}

Page 76: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Consumer Group

HTTP Average

HDFS

Top N

FaultDetection

s1.http s1.ave

Message Broker

AverageAverage

HDFSHDFS

group=ave

group=hdfs

{"id":1, "temperature":38}

{"id":1, "temperature":38} 🤓

Page 77: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Consumer Group

HTTP Average

HDFS

Top N

FaultDetection

s1.http s1.ave

Message Broker

AverageAverage

HDFSHDFS

group=ave

group=hdfs

{"id":1, "temperature":38}

{"id":1, "temperature":38} 🤓consumer group subscriptions

are durable 😁

Page 78: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

HTTP

Average

s1.http

Average

Page 79: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

HTTP

Average

s1.http

Average

{"id":1, "temperature":38}{"id":2, "temperature":41}

{"id":2, "temperature":42}{"id":1, "temperature":37}

Page 80: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

HTTP

Average

s1.http

Average

{"id":1, "temperature":38}{"id":2, "temperature":41}{"id":2, "temperature":42}

{"id":1, "temperature":37}

Page 81: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

HTTP

Average

s1.http

Average

{"id":1, "temperature":38}

{"id":2, "temperature":41}

{"id":2, "temperature":42}{"id":1, "temperature":37}

Page 82: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

HTTP

Average

s1.http

Average

{"id":1, "temperature":38}

{"id":2, "temperature":41}

{"id":2, "temperature":42}

{"id":1, "temperature":37}

Page 83: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

HTTP

Average

s1.http

Average

{"id":1, "temperature":38}

{"id":2, "temperature":41}

{"id":2, "temperature":42}

{"id":1, "temperature":37}

Page 84: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

HTTP

Average

s1.http

Average

{"id":1, "temperature":38}

{"id":2, "temperature":41}

{"id":2, "temperature":42}

{"id":1, "temperature":37}

😩

Page 85: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

HTTP

Average

s1.http

Average

{"id":1, "temperature":38}

{"id":2, "temperature":41}

{"id":2, "temperature":42}

{"id":1, "temperature":37}

😩

Partitioning Support(Stateful Stream)

Page 86: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

HTTP

Average

s1.http

Average

{"id":1, "temperature":38}

{"id":2, "temperature":41}

{"id":2, "temperature":42}

{"id":1, "temperature":37}

😩stream deploy --name=xxxx --properties="app.http.producer.partitionKeyExpression=payload.id"

spring.cloud.stream.bindings.<channelName>.producer.partitionKeyExpression=payload.id

Spring Cloud Stream

Spring Cloud Data Flow

Partitioning Support(Stateful Stream)

Page 87: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Partitioning Support(Stateful Stream)

HTTP

Average

s1.http

Average

Page 88: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Partitioning Support(Stateful Stream)

HTTP

Average

s1.http

Average

{"id":1, "temperature":38}{"id":2, "temperature":41}

{"id":2, "temperature":42}{"id":1, "temperature":37}

Page 89: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Partitioning Support(Stateful Stream)

HTTP

Average

s1.http

Average

{"id":1, "temperature":38}{"id":2, "temperature":41}{"id":2, "temperature":42}

{"id":1, "temperature":37}

Page 90: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Partitioning Support(Stateful Stream)

HTTP

Average

s1.http

Average

{"id":1, "temperature":38}

{"id":2, "temperature":41}

{"id":2, "temperature":42}{"id":1, "temperature":37}

Page 91: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Partitioning Support(Stateful Stream)

HTTP

Average

s1.http

Average

{"id":1, "temperature":38}

{"id":2, "temperature":41}{"id":2, "temperature":42}

{"id":1, "temperature":37}

Page 92: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Partitioning Support(Stateful Stream)

HTTP

Average

s1.http

Average

{"id":1, "temperature":38}

{"id":2, "temperature":41}{"id":2, "temperature":42}

{"id":1, "temperature":37}

Page 93: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Partitioning Support(Stateful Stream)

HTTP

Average

s1.http

Average

{"id":1, "temperature":38}

{"id":2, "temperature":41}{"id":2, "temperature":42}

{"id":1, "temperature":37}

🤓

Page 94: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Simple Real Time Analyticstweets = twitterstream | hdfs

analytics = :ingest.twitterstream > field-value-counter --fieldName=lang

HTTP

s1.http

HDFS COUNTER

Data Flow ServerREST API

Page 95: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Demo (Twitter Stream!)

Page 96: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Page 97: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring Cloud Task

Page 98: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring Cloud Task•Spring Boot based framework for short lived task

•Spring Boot's CommandLineRunner or Spring Batch

•Result of each process persists in Task Repository

•Well Integrated with Spring Batch (Job Repository)

Page 99: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Programming Model (CLR)@SpringBootApplication @EnableTaskpublic class DemoTaskApp { @Bean CommandLineRunner clr() { return args -> System.out.println("Task!"); } public static void main(String[] args) { SpringApplication.run(DemoTaskApp.class, args); } } spring.application.name=hello

Page 100: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Task Execution ListTask Name ID Start Time End Time Exit Code

hello 3 Tue Nov 15 16:49:08 JST 2016

Tue Nov 15 16:49:08 JST 2016

0

hello 2 Tue Nov 15 16:48:54 JST 2016

Tue Nov 15 16:48:55 JST 2016

0

hello 1 Tue Nov 15 16:48:23 JST 2016

Tue Nov 15 16:48:23 JST 2016

0

Page 101: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Programming Model (Spring Batch)@SpringBootApplication @EnableBatchProcessing@EnableTaskpublic class DemoBatchApp { @Autowired JobBuilderFactory jobBuilderFactory; @Autowired StepBuilderFactory stepBuilderFactory; @Bean Step step1() { /* ... */ } @Bean Step step2() { /* ... */ } @Bean Job job() { return jobBuilderFactory.get("job") .start(step1()).next(step2()).build()} public static void main(String[] args) { SpringApplication.run(DemoTaskApp.class, args); }}

https://github.com/making/cf-spring-batch-demo

spring.application.name=hello-batch

Page 102: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Task Execution ListTask Name ID Start Time End Time Exit Code

hello-batch

5 Tue Nov 15 17:28:49 JST 2016

Tue Nov 15 17:28:49 JST 2016

0

hello-batch

4 Tue Nov 15 17:27:56 JST 2016

Tue Nov 15 17:27:57 JST 2016

0

Page 103: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Job Execution ListID Task ID Start Time Step Execution Count Definition Status

2 5 Tue Nov 15 17:28:49 JST 2016

2 Created

1 4 Tue Nov 15 17:27:56 JST 2016

2 Created

Page 104: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Step Execution ListID Step Name Job Exec Id Start Time End Time Status

1 step1 1 Tue Nov 15 17:28:49 JST 2016

Tue Nov 15 17:28:49 JST 2016

COMPLETED

2 step2 1 Tue Nov 15 17:27:56 JST 2016

Tue Nov 15 17:27:57 JST 2016

COMPLETED

Page 105: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Task Orchestration in SCDF>task create hello --definition="timestamp --format=¥"yyyy¥"">task launch hello

timestamp

Data Flow Server DB Task NameStart TimeEnd TimeExit CodeExit MessageLast Updated TimeParameters

Message Broker

Page 106: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Task Execution List

Page 107: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Job Execution List

Page 108: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Job Execution Details

Page 109: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring Cloud Data Flow -> Taskhttp | tasklaunchrequest --uri=... | task-lancher

timestamp

Data Flow Server DB

Message Broker

Page 110: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Demo (Scalable Tasks)

Page 111: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Pivotal Cloud Foundry

PDF PDF

PDF PDF

S3

Spring Cloud Data FlowTask

TaskTask

Task

PDF

PDF

Spring Cloud Task Spring Batch

index

index

source sink

Page 112: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Getting Started with SCDF on Cloud Foundry

Page 113: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Install PCF Dev• https://docs.pivotal.io/pcf-dev

•Cloud Foundry on your laptop

• Included

•Redis / RabbitMQ / MySQL

•Spring Cloud Services

• Install with cf dev start

Page 114: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

cf create-service p-mysql 512mb df-mysqlcf create-service p-rabbitmq standard df-rebbitmqcf create-service p-redis shared-vm df-rediscf push dataflow-server -p spring-cloud-dataflow-server-cloudfoundry-1.0.1.RELEASE.jar

Deploy SCDF Server on PCF Dev

Page 115: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Tutorial

•📗 https://blog.ik.am/entries/396

•💎 https://github.com/making-demo-scdf/spring-cloud-dataflow-cookbook

Page 116: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Upcoming Features•Some ‘porting’ from XD

• Batch Job DSL + Designer • Role based access

• Looking forward • Spring Cloud Sleuth • JavaDSL • In-place application version upgrades with Spinnaker • Application Groups • Polyglot • Expanded analytics with Redis and Python/R ecosystem • More provided apps/tasks

•SCDF Tile for Pivotal Cloud Foundry

Page 117: Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #springday

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Thanks!•References

• http://www.slideshare.net/SpringCentral/data-microservices-in-the-cloud ✨

• https://cloud.spring.io/spring-cloud-dataflow/

• http://cloud.spring.io/spring-cloud-stream/

• http://cloud.spring.io/spring-cloud-stream-app-starters/

• https://github.com/spring-cloud/spring-cloud-task/

• http://cloud.spring.io/spring-cloud-dataflow-server-cloudfoundry/