Consumer-Driven Contracts
to enable API evolution
Marcin Grzejszczak
Marcin Grzejszczak @mgrzejszczak, 17-19 May 2017
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
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!
26
Introduction
What are we going to code?
I’m 17 give me a beer
CONSUMER PRODUCER
GET LOST
Can he get the beer?
No!
27
Demo
Who is who?
BLACK TERMINAL
BLACK IDE
CONSUMER
WHITE TERMINAL
WHITE IDE
PRODUCER
28
Demo
29
Demo
PRODUCER CONSUMER
30
Demo
PRODUCER
CONSUMER
CLONES
PRODUCER
PRODUCER
CLONE CONSUMER
31
Demo
PRODUCER CONSUMER
CONSUMER
CLONES
PRODUCER
PRODUCER
CLONE
INTERACTION
32
Demo
PRODUCER CONSUMER
PRODUCER
CLONE
INTERACTION
CONSUMER FILES
A PR
33
Demo
34
Demo
PRODUCER
TAKES OVER THE PR
35
Demo
PRODUCER
TAKES OVER THE PR
WRITES THE MISSING
IMPLEMENTATION
36
Demo
PRODUCER
TAKES OVER THE PR
WRITES THE MISSING
IMPLEMENTATION
MERGES TO MASTER
CI UPLOADS TO NEXUS /
ARTIFACTORY
37
Demo
38
Demo
CONSUMER
SWITCHES TO
ONLINE MODE
DOWNLOADS STUBS OF
COLLABORATORS DURING
BUILD PHASE
39
I don’t want to keep my contracts with the producer
40
I don’t want to keep my contracts with the producer
You can keep the contracts
in a dedicated repository!
41
Common repo with contracts
PRODUCER CONSUMERREPO WITH
CONTRACTS
INTERACTIONINTERACTION
42
Summary
43
Summary
44
I don’t want to write any scripts!
45
Spring Cloud Contract with Rest Docs
Don’t worry! You can use Spring Cloud
Contract WireMock with Rest Docs!!
46
Spring Cloud Contract with Rest Docs - producer side
47
●
●
●
●
●
Summary
48
●
●
●
●
○
○
●
●
Summary
49
●
○
○
○
○
●
●
●
● stubMatchers testMatchers
Summary
50
Learn More. Stay Connected.
▪ Read the docs
http://cloud.spring.io/spring-cloud-contract/spring-cloud-contract.html
▪ Check the samples
https://github.com/spring-cloud-samples/spring-cloud-contract-samples
▪ Talk to us on Gitter
https://gitter.im/spring-cloud/spring-cloud-contract
Twitter: twitter.com/springcentral
YouTube: spring.io/video
LinkedIn: spring.io/linkedin
Google Plus: spring.io/gplus
51
Survey
http://tiny.cc/geeconcdc
52
QUESTIONS
53
mgrzejszczak

Consumer Driven Contracts To Enable API Evolution @Geecon