1
© 2016 Pivotal
Consumer Driven Contracts and
Your Microservice Architecture
Marcin Grzejszczak, @mgrzejszczak
2
Spring Cloud developer at Pivotal
Working mostly on
● Spring Cloud Sleuth
● Spring Cloud Contract
● Spring Cloud Pipelines
About me
Twitter: @mgrzejszczak
Blog: http://toomuchcoding.com
3
Introduction
Demo
Summary
Agenda
4
What we will NOT be talking about?
5
●
●
●
●
●
What we will NOT be talking about?
THE IDEA OF SPRING CLOUD
CONTRACT IS NOT TO
INTRODUCE UNNECESSARY
COUPLING OR REPLICATE OLD
MISTAKES
6
●
○
●
○
●
○
●
○
Introduction
7
●
●
Introduction
What problems are we trying to solve?
8
Introduction
Typical situation
HTTP
CONSUMER PRODUCER
9
Introduction
How to write a test for it?
HTTP
CONSUMER PRODUCER
10
Introduction
How to write a test for it?
HTTP
CONSUMER PRODUCER
11
Introduction
Stub validity & reusability
WE’RE ON THE CONSUMER SIDE!!
CONSUMER OWNS THE STUB
DEFINITIONS
12
Introduction
Stub validity & reusability
13
Introduction
Let’s assume that we’re introducing a new
endpoint...
14
Introduction
Stub validity & reusability
15
●
●
●
Introduction
So now what?
16
Introduction
Ooops...
17
Introduction
What went wrong?
HTTP
CONSUMER PRODUCER
TEST
OK
HTTP
CONSUMER PRODUCER
REALITY
WAT?!
18
Introduction
Another example with messaging
CONSUMERPRODUCER
TEST
PRODUCER CONSUMER
REALITY
topic: bar topic: foo
topic: bar
19
●
●
●
●
●
●
Introduction
Stub validity & reusability
20
●
●
●
Introduction
Nice API creation
21
Introduction
Nice API creation - no cooperation results
22
Introduction
Nice API creation - no cooperation results
23
Demo
Potential answer
Spring Cloud Contract
24
●
○
○
●
○
●
○
○
Demo
What are we going to code?
25
●
○
●
○
●
○
Demo
What are we going to code?
26
Introduction
What are we going to code?
I’m 22 give me a beer
CONSUMER PRODUCER
There you go!
Can he get the beer?
Yes!
27
Introduction
What are we going to code?
I’m 17 give me a beer
CONSUMER PRODUCER
Get lost!
Can he get the beer?
No!
28
Introduction
What are we going to code?
Someone’s 22. Check him out!
CONSUMERPRODUCER
Positive verification took place
Messaging
29
Introduction
What are we going to code?
Someone’s 17. Check him out!
CONSUMERPRODUCER
Negative verification took place
Messaging
30
Introduction
What are we going to code?
BLACK TERMINAL
BLACK IDE
CONSUMER
WHITE TERMINAL
WHITE IDE
PRODUCER
31
Demo
32
Summary
33
Summary
PRODUCER CONSUMER
34
Summary
PRODUCER
CONSUMER
CLONES
PRODUCER
PRODUCER
CLONE CONSUMER
35
Summary
PRODUCER CONSUMER
CONSUMER
CLONES
PRODUCER
PRODUCER
CLONE
INTERACTION
36
Summary
PRODUCER CONSUMER
PRODUCER
CLONE
INTERACTION
CONSUMER FILES
A PR
37
Summary
38
Summary
PRODUCER
TAKES OVER THE PR
39
Summary
PRODUCER
TAKES OVER THE PR
WRITES THE MISSING
IMPLEMENTATION
40
Summary
PRODUCER
TAKES OVER THE PR
WRITES THE MISSING
IMPLEMENTATION
MERGES TO MASTER
CI UPLOADS TO NEXUS /
ARTIFACTORY
41
Summary
42
Summary
CONSUMER
SWITCHES TO
ONLINE MODE
DOWNLOADS STUBS OF
COLLABORATORS DURING
BUILD PHASE
43
Summary
44
Summary
45
I don’t want to keep my contracts with the producer
46
Demo
47
Common repo with contracts - consumer
PRODUCER CONSUMER
48
Common repo with contracts - consumer
PRODUCER CONSUMER
REPO WITH
CONTRACTS
49
Common repo with contracts - consumer
PRODUCER CONSUMER
REPO WITH
CONTRACTS
G
IT
C
LO
N
E
CLONED REPO
WITH
CONTRACTS
50
Common repo with contracts - consumer
PRODUCER CONSUMER
REPO WITH
CONTRACTS
G
IT
C
LO
N
E
CLONED REPO
WITH
CONTRACTS
INTERACTION
51
Common repo with contracts - consumer
PRODUCER CONSUMER
REPO WITH
CONTRACTS
CLONED REPO
WITH
CONTRACTSPR
52
Common repo with contracts - producer
PRODUCER CONSUMER
REPO WITH
CONTRACTS
53
Common repo with contracts - producer
PRODUCER CONSUMER
REPO WITH
CONTRACTS
CLONED REPO
WITH
CONTRACTS
PR
O
D
U
C
ER
TAKES
O
VER
PR
54
WRITES THE MISSING
IMPLEMENTATION
Common repo with contracts - producer
PRODUCER CONSUMER
REPO WITH
CONTRACTS
CLONED REPO
WITH
CONTRACTS
PR
O
D
U
C
ER
TAKES
O
VER
PR
55
WRITES THE MISSING
IMPLEMENTATION
Common repo with contracts - producer
PRODUCER CONSUMER
REPO WITH
CONTRACTS
CLONED REPO
WITH
CONTRACTS
M
ER
G
E
PR
56
WRITES THE MISSING
IMPLEMENTATION
Common repo with contracts - producer
PRODUCER CONSUMER
REPO WITH
CONTRACTS
CI UPLOADS TO NEXUS
/ ARTIFACTORY
57
●
●
●
●
●
I don’t want to keep my contracts with the producer
58
I don’t want to write any scripts!
59
Introduction
Don’t worry! You can use Spring Cloud
Contract WireMock with Rest Docs!!
60
Demo
61
●
●
●
●
●
Summary
62
●
●
●
●
●
●
Summary
63
QUESTIONS
64
Learn More. Stay Connected.
▪ Read the docs
▪ Check the samples
▪ Talk to us on Gitter
Twitter: twitter.com/springcentral
YouTube: spring.io/video
LinkedIn: spring.io/linkedin
Google Plus: spring.io/gplus
65
mgrzejszczak

Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG