Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

232
‹#› © 2016 Pivotal Software, Inc. All rights reserved. Event Driven Microservices with Spring Cloud Stream Toshiaki Maki (@making) 2016-12-03 JJUG CCC 2016 Fall #jjug_ccc #ccc_ab3 http://bit.ly/making_ccc_a3 (source code)

Transcript of Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

Page 1: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Event Driven Microservices with Spring Cloud Stream

Toshiaki Maki (@making) 2016-12-03 JJUG CCC 2016 Fall #jjug_ccc #ccc_ab3 http://bit.ly/making_ccc_a3 (source code)

Page 2: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Contents

•Spring Cloud Stream (25min) •Advanced Topic (20min) •Spring Cloud Data Flow (2min) •Deploy Stream Apps to Cloud Foundry (3min)

Page 4: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Microservices

Frontend Customer Service

Email Service

Point Service

Post Service

Page 5: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Microservices

Frontend Customer Service

Email Service

Point Service

Post Service

HTTP / REST?

Page 6: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Microservices

Frontend Customer Service

Email Service

Point Service

Post Service

ABC Service

XYZ Service

Page 7: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Microservices

Frontend Customer Service

Email Service

Point Service

Post Service

ABC Service

XYZ Service

Page 8: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Microservices

Frontend Customer Service

Email Service

Point Service

Post Service

ABC Service

XYZ Service

Page 9: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Microservices

Frontend Customer Service

Email Service

Point Service

Post Service

ABC Service

XYZ Service😩

Page 10: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Microservices

Frontend Customer Service

Email Service

Point Service

Post Service

ABC Service

XYZ Service😩

Orchestration Style

Page 11: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Read Failure

Frontend Customer Service

Email Service

HTTP GET

Page 12: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Read Failure

Frontend Customer Service

Email Service

🔥HTTP GET

Page 13: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Read Failure

Frontend Customer Service

Email Service

🔥HTTP GET

Circuit Breaker

Page 14: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Read Failure

Frontend Customer Service

Email Service

🔥HTTP GET

Circuit Breaker

Page 15: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Write Failure

Frontend Customer Service

Email Service

HTTP POST

Page 16: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Write Failure

🔥Frontend Customer

ServiceEmail

Service

HTTP POST

Page 17: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Write Failure

🔥Frontend Customer

ServiceEmail

Service

😲HTTP POST

Page 18: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Event Driven MicroServices

Frontend Customer Service

Email Service

Point Service

Post Service

Page 19: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Event Driven MicroServices

Frontend Customer Service

Email Service

Point Service

Post Service

Page 20: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Event Driven MicroServices

Frontend Customer Service

Email Service

Point Service

Post Service

Subscribe

Page 21: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Event Driven MicroServices

Frontend Customer Service

Email Service

Point Service

Post Service

Subscribe

Publish

Page 22: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Event Driven MicroServices

Frontend Customer Service

Email Service

Point Service

Post Service

Subscribe

ABC Service

XYZ Service

Publish

Page 23: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Event Driven MicroServices

Frontend Customer Service

Email Service

Point Service

Post Service

Subscribe

ABC Service

XYZ Service

Publish

Page 24: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Event Driven MicroServices

Frontend Customer Service

Email Service

Point Service

Post Service

Subscribe

ABC Service

XYZ Service

🤓

Publish

Page 25: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Choreography Style

https://www.thoughtworks.com/insights/blog/scaling-microservices-event-stream

Page 26: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Spring Cloud Stream

Page 27: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 28: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Source | Sink

Sink

inpu

t

Source

outp

ut

Page 29: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Source | Processor | Sink

Sourceou

tput

Processor

outp

ut

inpu

t

Sink

inpu

t

Page 30: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 31: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 32: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Message Binders• @EnableBinding•Binder Implementations

•Production-Ready

•Rabbit MQ

•Apache Kafka

•Experimental

• JMS

•Google PubSub

Page 33: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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.getPayload()); } public static void main(String[] args) { SpringApplication.run(DemoSinkApp.class, args); } }

Page 34: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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.getPayload()); } public static void main(String[] args) { SpringApplication.run(DemoSinkApp.class, args); } }

public interface Sink { String INPUT = "input"; @Input(Sink.INPUT) SubscribableChannel input(); }

Page 35: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Sink

Properties (Sink)

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

demo-strm in

put

Page 36: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

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

Page 37: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

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

public interface Source { String OUTPUT = "output"; @Output(Source.OUTPUT) MessageChannel output(); }

Page 38: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 39: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Properties (Source)

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

demo-strm

Source

outp

ut

Page 40: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Properties (Source)spring.cloud.stream.bindings.output.destination=demo-strmspring.cloud.stream.bindings.output.contentType=application/json

demo-strm

Source

outp

ut

Page 41: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 42: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 43: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Sink

Pipeline

demo-strm in

put

Source

outp

ut

source | sink

Page 44: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

RabbitMQdemo-strm

Page 45: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

RabbitMQdemo-strm

Source

Page 46: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

RabbitMQ

dem

o-st

rm

Topic Exchange

demo-strm

Source

Page 47: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

RabbitMQ

dem

o-st

rm

Topic Exchange

demo-strm

Source

Page 48: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

RabbitMQ

dem

o-st

rm

Topic Exchange

demo-strm

Source Sink

Page 49: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

RabbitMQ

dem

o-st

rm

Topic Exchange

demo-strm.anonymous.x

Queuedemo-strm

Source Sink

Page 50: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

RabbitMQ

dem

o-st

rm

Topic Exchange

demo-strm.anonymous.x

Queuedemo-strm

Source Sink

Page 51: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 52: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 53: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 54: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Reactive API Support by Reactor@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 55: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Reactive API Support by Reactor

@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 56: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

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

Page 57: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Persistent Pub-Sub

HTTP Average Top Ns1.http s1.ave

Message Broker

Page 58: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Persistent Pub-Sub

HTTP Average

HDFS

Top Ns1.http s1.ave

Message Broker

Page 59: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Persistent Pub-Sub

HTTP Average

HDFS

Top N

FaultDetection

s1.http s1.ave

Message Broker

Page 60: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 61: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 62: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 63: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

HTTP Average

HDFS

Top N

FaultDetection

s1.http s1.ave

Message Broker

AverageAverage

HDFSHDFS

Page 65: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 66: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 67: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 68: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Topic Exchange

dem

o-st

rm

demo-strm.anonymous.1

Queue

Page 70: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Topic Exchange

dem

o-st

rm

demo-strm.anonymous.1

Queue

Page 71: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Topic Exchange

dem

o-st

rm

demo-strm.anonymous.1

Queue

demo-strm.anonymous.2

Page 72: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Topic Exchange

dem

o-st

rm

demo-strm.anonymous.1

Queue

demo-strm.anonymous.2

Consumer Group

Page 73: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Topic Exchange

dem

o-st

rm

demo-strm.anonymous.1

Queue

demo-strm.anonymous.2

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

Consumer Group

Page 74: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Consumer Group

dem

o-st

rm

demo-strm.ave

QueueTopic Exchange

Page 75: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 76: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 77: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 78: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 79: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 80: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 81: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Durability

dem

o-st

rm

demo-strm.ave

Queue

🚑

Topic Exchange

Page 82: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Durability

dem

o-st

rm

demo-strm.ave

Queue

🚑

Topic Exchange

Page 83: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Durability

dem

o-st

rm

demo-strm.ave

Queue

🚑

🏀

Topic Exchange

Page 84: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Durability

dem

o-st

rm

demo-strm.ave

Queue

🚑

🏀

Topic Exchange

Page 85: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Durability

dem

o-st

rm

demo-strm.ave

Queue

🚑

🏀

Topic Exchange

Page 86: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Durability

dem

o-st

rm

demo-strm.ave

Queue

🚑

🏀

Topic Exchange

Page 87: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Durability

dem

o-st

rm

demo-strm.ave

Queue

🚑

🏀

Topic Exchange

Page 88: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Customer Service

Email Service

Point Service

Post Service

Source

Sink

Page 89: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Customer Service

Email Service

Point Service

Post Service

Source

Sink

spring.cloud.stream.bindings.output.destination=customerspring.cloud.stream.bindings.output.contentType=application/json

Page 90: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Customer Service

Email Service

Point Service

Post Service

SubscribeSource

Sink

Page 91: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Customer Service

Email Service

Point Service

Post Service

SubscribeSource

Sinkgroup=point-service

group=email-service

group=post-service

Page 92: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Customer Service

Email Service

Point Service

Post Service

SubscribeSource

Sinkgroup=point-service

group=email-service

group=post-service

spring.cloud.stream.bindings.input.destination=customerspring.cloud.stream.bindings.input.group=point-service

Page 93: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Customer Service

Email Service

Point Service

Post Service

SubscribeSource

Sinkgroup=point-service

group=email-service

group=post-service

spring.cloud.stream.bindings.input.destination=customerspring.cloud.stream.bindings.input.group=point-service

spring.cloud.stream.bindings.input.destination=customerspring.cloud.stream.bindings.input.group=email-service

Page 94: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Customer Service

Email Service

Point Service

Post Service

SubscribeSource

Sinkgroup=point-service

group=email-service

group=post-service

spring.cloud.stream.bindings.input.destination=customerspring.cloud.stream.bindings.input.group=point-service

spring.cloud.stream.bindings.input.destination=customerspring.cloud.stream.bindings.input.group=email-service

spring.cloud.stream.bindings.input.destination=customerspring.cloud.stream.bindings.input.group=post-service

Page 95: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

customer

Customer Service

outp

ut

Point Service

inpu

t

Email Service

inpu

t

Post Service

inpu

t

Page 96: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

cust

omer

customer.point-service

Queue

Consumer Group

customer.email-service

customer.post-

service

Topic Exchange

Page 97: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

HTTP

Average

s1.http

Average

Page 98: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 99: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 100: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 101: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 102: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 103: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 104: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 105: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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}

😩

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

Partitioning Support(Stateful Stream)

Page 106: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Partitioning Support(Stateful Stream)

HTTP

Average

s1.http

Average

Page 107: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 108: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 109: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 110: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 111: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 112: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 113: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Test SupportSource

outp

utSink

inpu

t

Page 114: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Test SupportSource

outp

utSink

inpu

t

TestSupportBinder

Page 115: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Test Support

<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-stream-test-support</artifactId> <scope>test</scope></dependency>

Page 116: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Unit Test (Sink)@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.NONE) public class DemoSinkAppTest { @Autowired Sink sink; @Rule public OutputCapture capture = new OutputCapture(); @Test public void testReceive() { sink.input() .send(MessageBuilder.withPayload("foo").build()); assertThat(capture.toString()) .isEqualsTo("Received foo"); }}

Page 117: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Unit Test (Source)@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.NONE) public class DemoSourceAppTest { @Autowired DemoSourceApp app; @Autowired MessageCollector collector; @Autowired Source source; @Test public void testSend() { app.send("foo"); Message<String> message = collector .forChannel(source.output()).poll(); assertThat(message.getPayload()).isEqualsTo("foo"); }}

Page 118: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Advanced Topics

Page 119: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Advanced Topics•Multi Binding •Distributed Tracing •Error Handling •Consumer Driven Contract

Page 120: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Multi Bindings

Page 121: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

customer

Customer Service

outp

ut

Email Service

inpu

t

Page 122: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

customer

Customer Service

outp

ut

Email Service

inpu

t

CustomerCreateEvent

Page 123: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

customer

Customer Service

outp

ut

Email Service

inpu

t

Page 124: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

customer

Customer Service

outp

ut

Email Service

inpu

t

CustomerDeleteEvent

Page 125: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

customer

Customer Service

outp

ut

Email Service

inpu

t

CustomerDeleteEvent

ClassCastException!!

Page 126: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

create

Email Service

crea

te-

inpu

tde

lete

-in

put

Customer Service

crea

te-

outp

utde

lete

-ou

tput

delete

CustomerCreateEvent

CustomerDeleteEvent

Page 127: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

public interface CustomerEventSource { String CREATE_OUTPUT = "create-output"; String DELETE_OUTPUT = "delete-output"; @Output(CustomerEventSource.CREATE_OUTPUT) MessageChannel createOutput(); @Output(CustomerEventSource.DELETE_OUTPUT) MessageChannel deleteOutput(); }

Multi Bindings

Page 128: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

@Component public class CustomerService { @Autowired CustomerEventSource source; public void create(...) { source.createOutput().send(...); } public void delete() { source.deleteOutput().send(...); } }

@SpringBootApplication@EnableBinding(CustomerEventSource.class) public class CustomerServiceApplication { /* ... */ }

Page 129: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

@Component public class CustomerService { @Autowired CustomerEventSource source; public void create(...) { source.createOutput().send(...); } public void delete() { source.deleteOutput().send(...); } }

@SpringBootApplication@EnableBinding(CustomerEventSource.class) public class CustomerServiceApplication { /* ... */ }

spring.cloud.stream.bindings.create-output.destination=createspring.cloud.stream.bindings.delete-output.destination=delete

Page 130: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

public interface CustomerEventSink { String CREATE_INPUT = "create-input"; String DELETE_INPUT = "delete-input"; @Input(CustomerEventSink.CREATE_INPUT) SubscribableChannel createInput(); @Input(CustomerEventSink.DELETE_INPUT) SubscribableChannel deleteInput(); }

Multi Bindings

Page 131: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

@Component public class PointService { @StreamListener(CustomerEventSink.CREATE_INPUT) public void handleCreate(CustomerCreateEvent event) { }

@StreamListener(CustomerEventSink.DELETE_INPUT) public void handleDelete(CustomerDeleteEvent event) { } }

@SpringBootApplication@EnableBinding(CustomerEventSink.class) public class PointServiceApplication { /* ... */ }

Page 132: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

@Component public class PointService { @StreamListener(CustomerEventSink.CREATE_INPUT) public void handleCreate(CustomerCreateEvent event) { }

@StreamListener(CustomerEventSink.DELETE_INPUT) public void handleDelete(CustomerDeleteEvent event) { } }

@SpringBootApplication@EnableBinding(CustomerEventSink.class) public class PointServiceApplication { /* ... */ }spring.cloud.stream.bindings.create-input.destination=createspring.cloud.stream.bindings.create-input.group=point-servicespring.cloud.stream.bindings.delete-intput.destination=deletespring.cloud.stream.bindings.delete-input.group=point-service

Page 133: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

crea

te create.point-service

Queue

dele

te delete.point-service

Topic Exchange

Page 134: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Frontend Customer Service

Email Service

Point Service

Post Service

Subscribe

ABC Service

XYZ Service

Page 135: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Frontend Customer Service

Email Service

Point Service

Post Service

Subscribe

ABC Service

XYZ Service

🕝

Page 136: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Frontend Customer Service

Email Service

Point Service

Post Service

Subscribe

ABC Service

XYZ Service🤔

🕝

Page 137: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Frontend Customer Service

Email Service

Point Service

Post Service

Subscribe

ABC Service

XYZ Service🤔

🕝🕵 🕵

🕵

🕵 🕵

🕵🕵

Page 138: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Frontend Customer Service

Email Service

Point Service

Post Service

Subscribe

ABC Service

XYZ Service🤔

🕝🕵 🕵

🕵

🕵 🕵

🕵🕵

Page 139: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Frontend Customer Service

Email Service

Point Service

Post Service

Subscribe

ABC Service

XYZ Service🤔

🕝🕵 🕵

🕵

🕵 🕵

🕵🕵

TraceID, SpanID

Page 140: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Spring Cloud Sleuth•Distributed tracing solution for Spring Cloud

• Interactions with external systems should be instrumented automatically

•Capture data simply in logs, or by sending it to Zipkin via RestTemplate / Spring Cloud Stream / ...

Page 141: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Spring Cloud Sleuth Stream

<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-stream-slueth</artifactId></dependency>

Page 142: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Spring Cloud Sleuth Stream

customer

Customer Service

outp

ut

Email Service

inpu

t

Page 143: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Spring Cloud Sleuth Stream

customer

Customer Service

outp

ut

Email Service

inpu

t

sleuth sleuth

Page 144: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Zipkin Stream Server<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-sleuth-zipkin-stream</artifactId></dependency>

Page 145: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Zipkin Stream Server<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-sleuth-zipkin-stream</artifactId></dependency>

@SpringBootApplication @EnableZipkinStreamServer public class ZipkinStreamServer { public static void main(String[] args) { SpringApplication.run(DemoSinkApp.class, args); } }

Page 146: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Zipkin Stream Server

customer

Customer Service

outp

ut

Email Service

inpu

t

sleuth sleuth

Page 147: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Zipkin Stream Server

customer

Customer Service

outp

ut

Email Service

inpu

t

sleuth sleuth

sleuth

sleu

th

Page 148: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Zipkin Stream Server

customer

Customer Service

outp

ut

Email Service

inpu

t

sleuth sleuth

sleuth

sleu

th

Page 149: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Zipkin Stream Server

customer

Customer Service

outp

ut

Email Service

inpu

t

sleuth sleuth

sleuth

sleu

th

Page 150: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Zipkin Stream Server

customer

Customer Service

outp

ut

Email Service

inpu

t

sleuth sleuth

sleuth

sleu

th

TraceID,SpanID TraceID,SpanID

Page 151: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Zipkin Stream Server

customer

Customer Service

outp

ut

Email Service

inpu

t

sleuth sleuth

sleuth

sleu

th

Page 152: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Zipkin UI

Page 153: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Zipkin UI

Trace

Page 154: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Zipkin UI

Trace

Span

Page 155: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Page 156: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Error Handling•Depends on the message binder implementation •(Ex.) RabbitMQ binder routes the failed message to the Dead-Letter Queue(DLQ). No mechanism to handle DLQs.

Page 157: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Dead-Letter Queue Processing

dem

o-st

rm

Topic Exchange

demo-strm.ave

Source Sink

Rab

bitM

Q B

inde

r

Page 158: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Dead-Letter Queue Processing

dem

o-st

rm

Topic Exchange

demo-strm.ave

Source Sink

DLX

Rab

bitM

Q B

inde

r

Page 159: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Dead-Letter Queue Processing

dem

o-st

rm

Topic Exchange

demo-strm.ave

Source Sink

DLX

Rab

bitM

Q B

inde

r

spring.cloud.stream.bindings.input.destination=demo-strmspring.cloud.stream.bindings.input.group=avespring.cloud.stream.rabbit.bindings.input.consumer.autoBindDlq=true

Page 160: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Dead-Letter Queue Processing

dem

o-st

rm

Topic Exchange

demo-strm.ave

Source Sink

DLX demo-strm.ave.dlq

Rab

bitM

Q B

inde

r

spring.cloud.stream.bindings.input.destination=demo-strmspring.cloud.stream.bindings.input.group=avespring.cloud.stream.rabbit.bindings.input.consumer.autoBindDlq=true

Page 161: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Dead-Letter Queue Processing

dem

o-st

rm

Topic Exchange

demo-strm.ave

Source Sink

DLX demo-strm.ave.dlq

Rab

bitM

Q B

inde

r

Page 162: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Dead-Letter Queue Processing

dem

o-st

rm

Topic Exchange

demo-strm.ave

Source Sink

DLX demo-strm.ave.dlq

Rab

bitM

Q B

inde

r

Page 163: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Dead-Letter Queue Processing

dem

o-st

rm

Topic Exchange

demo-strm.ave

Source Sink

DLX demo-strm.ave.dlq

Rab

bitM

Q B

inde

r

Page 164: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Dead-Letter Queue Processing

dem

o-st

rm

Topic Exchange

demo-strm.ave

Source Sink

DLX demo-strm.ave.dlq

Rab

bitM

Q B

inde

r

🔥

Page 165: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Dead-Letter Queue Processing

dem

o-st

rm

Topic Exchange

demo-strm.ave

Source Sink

DLX demo-strm.ave.dlq

Rab

bitM

Q B

inde

r

🔥 Retry 3 times by default

Page 166: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Dead-Letter Queue Processing

dem

o-st

rm

Topic Exchange

demo-strm.ave

Source Sink

DLX demo-strm.ave.dlq

Rab

bitM

Q B

inde

r

🔥 Retry 3 times by default

Page 167: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Page 168: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Page 169: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Page 170: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Page 171: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Page 172: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Handling DLQ

@Component public class DlqHander { @RabbitListener(queues = "customer.email-service.dlq") public void handle(Message event) { // Re-deliver if you want } }

Page 173: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

DLQ Recovery Center 😛

https://github.com/making-demo-scst/dlq-recover-service

Page 174: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Trace everything

Page 175: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

customer

Customer Service

outp

ut

Point Service

inpu

t

Email Service

inpu

t

Post Service

inpu

t

Page 176: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

customer

Customer Service

outp

ut

Point Service

inpu

t

Email Service

inpu

t

Post Service

inpu

t

Page 177: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

customer

Customer Service

outp

ut

Point Service

inpu

t

Email Service

inpu

t

Post Service

inpu

t

Page 178: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

customer

Customer Service

outp

ut

Point Service

inpu

t

Email Service

inpu

t

Post Service

inpu

t

Page 179: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

customer

Customer Service

outp

ut

Point Service

inpu

t

Email Service

inpu

t

Post Service

inpu

t

Page 180: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

customer

Customer Service

outp

ut

Point Service

inpu

t

Email Service

inpu

t

Post Service

inpu

t

😗 Breaking Change

Page 181: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

customer

Customer Service

outp

ut

Point Service

inpu

t

Email Service

inpu

t

Post Service

inpu

t

😗 Breaking Change

Page 182: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

customer

Customer Service

outp

ut

Point Service

inpu

t

Email Service

inpu

t

Post Service

inpu

t

😗 Breaking Change

Page 183: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

customer

Customer Service

outp

ut

Point Service

inpu

t

Email Service

inpu

t

Post Service

inpu

t

😗 Breaking Change

Page 184: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

customer

Customer Service

outp

ut

😗 Breaking Change 😡

😡

😡

😨

Page 185: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Consumer Driven Contracts•Consumer shares "expectation" with

Producer via "Contract" (≈ DSL) •The contract violation should be detected by

generated tests on the producer side.

Page 186: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Consumer Driven Contracts•Consumer shares "expectation" with

Producer via "Contract" (≈ DSL) •The contract violation should be detected by

generated tests on the producer side.

ContractConsumer Producer

Page 187: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Flow of Consumer Driven ContractsConsumer Producer

Page 188: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Flow of Consumer Driven ContractsConsumer ProducerContract

Page 189: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Flow of Consumer Driven ContractsConsumer Producer

Contract

Page 190: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Flow of Consumer Driven ContractsConsumer Producer

ContractAcceptance Test

Page 191: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Flow of Consumer Driven ContractsConsumer Producer

Contract

Acceptance Test

Page 192: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Flow of Consumer Driven ContractsConsumer Producer

Contract

Acceptance Test

Page 193: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Flow of Consumer Driven ContractsConsumer Producer

Contract

Acceptance Test

Stub

Page 194: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Flow of Consumer Driven ContractsConsumer Producer

Contract

Acceptance Test

Stub✅

Page 195: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Flow of Consumer Driven ContractsConsumer Producer

Contract

Acceptance Test

Stub

Unit Test✅

Page 196: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Flow of Consumer Driven ContractsConsumer Producer

Contract

Acceptance Test

Stub

Unit Test✅✅

Page 197: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Spring Cloud Contract•A CDC Solution for JVM apps (especially Spring) •Contract DSL using Groovy •Generates Acceptance test (JUnit or Spock) for producer •Generates Stub for consumer •WireMock Support for REST Test •Messaging Support (Spring Integration, Spring Cloud

Stream and Apache Camel)

Page 198: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Contract DSLContract.make { label 'create-customer' input { } outputMessage { sentTo('demo-strm') headers({header('Content-Type':'...')}) body('''{"name":"@making"}''') }}

shouldCreateCustomer.groovy

Page 199: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Contract DSLContract.make { label 'create-customer' input { } outputMessage { sentTo('demo-strm') headers({header('Content-Type':'...')}) body('''{"name":"@making"}''') }}

shouldCreateCustomer.groovy

Created by Consumer

Page 200: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Prepare Parent Test Class@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.NONE)@AutoConfigureMessageVerifier public abstract class MsgTestBase { @Autowired CustomerService service;

protected void create() { service.create("@making"); }}

Page 201: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Prepare Parent Test Class@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.NONE)@AutoConfigureMessageVerifier public abstract class MsgTestBase { @Autowired CustomerService service;

protected void create() { service.create("@making"); }}

Created by Producer

Page 202: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Contract DSLContract.make { label 'create-customer' input { triggeredBy('create()') } outputMessage { sentTo('demo-strm') headers({header('Content-Type':'...')}) body('''{"name":"@making"}''') }}

shouldCreateCustomer.groovy

Page 203: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Contract DSLContract.make { label 'create-customer' input { triggeredBy('create()') } outputMessage { sentTo('demo-strm') headers({header('Content-Type':'...')}) body('''{"name":"@making"}''') }}

shouldCreateCustomer.groovy

Updated by Producer

Page 204: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Generated Acceptance Testpublic class ContractVerifierTest extends MsgTestBase { // ... @Test public void validate_shouldCreateCustomer() { create(); ContractVerifierMessage res = verifierMessaging .receive("customer"); assertThat(res).isNotNull(); DocumentContext parsedJson = JsonPath.parse( objectMapper.writeValueAsString(res.getPayload())); assertThatJson(parsedJson).field("name") .isEqualTo("@making"); }}

Page 205: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Spring Cloud Contract Maven Pluginmvn spring-cloud-contract:generateTests

mvn spring-cloud-contract:convert

mvn spring-cloud-contract:generateStubs

Acceptance Test

WireMock stub file (only for REST)

Stub jar file

Page 206: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Consumer Side Test@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.NONE)@AutoConfigureStubRunner(ids = "com.example:customer-service", workOffline = true) public class PointServiceConsumerTest { @Autowired StubTrigger stubTrigger; // ... @Test public void testCreateCustomer() { stubTrigger.trigger("create-customer"); // assert that the message is received ... }}

Page 207: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Check sample code•http://bit.ly/making_ccc_a3

Page 208: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

(FYI) CQRS and Event Sourcing• https://spring.io/blog/2016/11/08/cqrs-and-event-sourcing-

with-jakub-pilimon

• https://github.com/pilloPl/event-source-cqrs-sample

Page 209: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Data Microservices with Spring Cloud Data Flow

Page 210: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 211: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 212: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 213: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 214: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 215: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 216: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 such as Cloud Foundry

Page 217: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 such as Cloud Foundry

Page 218: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 such as Cloud Foundry

Page 219: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 220: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 221: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 222: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

‹#›© 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 223: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Check my slide• http://www.slideshare.net/makingx/data-microservices-with-

spring-cloud-stream-task-and-data-flow-jsug-springday

Page 224: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Deploy Stream Apps to Cloud Foundry

Page 225: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Cloud Foundry•https://www.cloudfoundry.org/ •Cloud Native Platform •OSS

•Spring ❤ Cloud Foundry

•Support Multi IaaS (AWS, Azure, GCP, vSphere, OpenStack)

Page 226: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Cloud Foundry everywhere

Public Cloud Foundry

Private Cloud Foundry

Development

OSS ver Pivotal Cloud Foundry

on Premise

on Public Cloud

Page 227: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

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 228: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Pivotal Web Services•https://run.pivotal.io/ •Public Cloud Foundry managed by Pivotal •$0.03/GB-hr (≈ ¥2200/GB-month) •$87 of free trial credit.

Page 229: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Deploy Spring Cloud Stream Apps

cf push my-source my-source.jar --no-startcf bind-service my-source my-bindercf start my-source

cf push my-sink my-sink.jar --no-startcf bind-service my-sink my-bindercf start my-sink

# in case of PCF Devcf create-service p-rabbitmq standard my-binder# in case of Pivotal Web Servicescf create-service cloudamqp lemur my-binder

Page 230: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Sample Application http://bit.ly/making_ccc_a3

Pivotal Web Services / PCF Dev

Frontend Customer Service

Email Service

Point Service

Post ServiceZipkin

Server

MySQL

SendGrid

MySQL

MySQL

DLQ Recovery

RabbitMQ

HTTP

Page 231: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Tutorialhttps://github.com/Pivotal-Japan/spring-cloud-stream-tutorial

Page 232: Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3

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

Thanks!!• https://cloud.spring.io/spring-cloud-stream/

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

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

• http://zipkin.io/

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

• https://projects.spring.io/spring-amqp/

• https://run.pivotal.io/