SlideShare a Scribd company logo
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
● Schema
● WSDL
● ESB
● XSD
● XSLT
What we will NOT be talking about?
THE IDEA OF SPRING CLOUD
CONTRACT IS NOT TO
INTRODUCE UNNECESSARY
COUPLING OR REPLICATE OLD
MISTAKES
6
● Producer
○ service that exposes an API
● Consumer
○ service that consumes the API of the producer
● Contract
○ agreement between producer and consumer how the API will look like
● Consumer Driven Contracts
○ approach where the consumer drives the changes of the API of the producer
Introduction
7
● Stub validity & reusability in the integration tests
● Nice API creation
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
Stub validity & reusability
13
14
● My tests fail cause I’m shooting a request at a non existant URL
● I rewrote all my code to work with the new URL
● The unit and integration tests pass
● Now we deploy to an environment
where real integrations will take place...
Introduction
So now what?
15
Introduction
Ooops...
16
Stubs that were used in the build phase have nothing to do with the real API!!
Introduction
What went wrong?
HTTP
CONSUMER PRODUCER
TEST
OK
HTTP
CONSUMER PRODUCER
REALITY
WAT?!
17
● Stubs reside with the consumer
● Consumer controls the stubbing process
● How are you sure that the stubs are valid?
● What if other teams want to reuse those stubs?
Introduction
Stub validity & reusability
18
● It’s the consumer that uses the API
● Consumers should take part in the creation of the API of the producer
● The producer’s API change should be driven by consumers
Introduction
Nice API creation
19
Introduction
Nice API creation - no cooperation results
20
Introduction
Nice API creation - no cooperation results
21
Demo
Potential answer
Spring Cloud Contract
22
● Consumer
○ service that gets beer requests
○ has to ask another service if the client can get the beer
● Producer
○ service that checks if the client is old enough to buy beer
● Feature
○ if the user is too young - the beer will not be sold
○ otherwise the beer will be granted
Demo
What are we going to code?
23
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!
24
Introduction
What are we going to code?
I’m 17 give me a beer
CONSUMER PRODUCER
Get lost!
Can he get the beer?
No!
25
Introduction
What are we going to code?
BLACK TERMINAL
BLACK IDE
CONSUMER
WHITE TERMINAL
WHITE IDE
PRODUCER
26
Demo
27
Summary
Consumer’s offline
work
Consumer Phase 1 Consumer Phase 2
Consumer’s switching
to online
Producer phase
Producer’s
implementing the
feature
28
Summary
PRODUCER
Consumer flow 1
CONSUMER
29
Summary
PRODUCER
CONSUMER
CLONES
PRODUCER
PRODUCER
CLONE
Consumer flow 1
CONSUMER
30
Summary
PRODUCER CONSUMER
CONSUMER
CLONES
PRODUCER
PRODUCER
CLONE
INTERACTION
Consumer flow 1
31
Summary
PRODUCER CONSUMER
PRODUCER
CLONE
INTERACTION
CONSUMER FILES
A PR
Consumer flow 1
32
Summary
Consumer flow 1
starts TDD - writes the test for the feature
clones producer code to change the API locally
in the cloned producer code converts contracts into stubs and installs them locally
in the consumer code turns Stub Runner to offline mode
configures Stub Runner to download stubs of the producer
red - green - refactor on the API and tests
repeats the process until the tests are green and API acceptable
files a PR to the producer with the contract proposal
33
Summary
PRODUCER
TAKES OVER THE PR
Producer flow
34
Summary
PRODUCER
TAKES OVER THE PR
Producer flow
WRITES THE MISSING
IMPLEMENTATION
35
Summary
PRODUCER
TAKES OVER THE PR
Producer flow
WRITES THE MISSING
IMPLEMENTATION
MERGES TO MASTER
CI UPLOADS TO NEXUS /
ARTIFACTORY
36
Summary
Producer flow
takes over the PR
writes the missing implementation that will make the autogenerated tests pass
merges PR and deploys the JARs with the app and the stubs
37
Summary
CONSUMER
Consumer flow 2
SWITCHES TO
ONLINE MODE
DOWNLOADS STUBS OF
COLLABORATORS DURING
BUILD PHASE
38
Summary
Consumer flow 2
switches off the Stub Runner’s offline mode once the producer uploads the stubs
configure Stub Runner by providing the URL to a repo with stubs
will have its test broken if the producer makes any breaking changes of the API
39
I don’t want to keep my contracts with the producer
40
Common repo with contracts - consumer
PRODUCER CONSUMER
41
Common repo with contracts - consumer
PRODUCER CONSUMER
REPO WITH
CONTRACTS
42
Common repo with contracts - consumer
PRODUCER CONSUMER
REPO WITH
CONTRACTS
G
IT
C
LO
N
E
CLONED REPO
WITH
CONTRACTS
43
Common repo with contracts - consumer
PRODUCER CONSUMER
REPO WITH
CONTRACTS
G
IT
C
LO
N
E
CLONED REPO
WITH
CONTRACTS
INTERACTION
44
Common repo with contracts - consumer
PRODUCER CONSUMER
REPO WITH
CONTRACTS
CLONED REPO
WITH
CONTRACTSPR
45
Common repo with contracts - producer
PRODUCER CONSUMER
REPO WITH
CONTRACTS
46
Common repo with contracts - producer
PRODUCER CONSUMER
REPO WITH
CONTRACTS
CLONED REPO
WITH
CONTRACTS
PR
O
D
U
C
ER
TAKES
O
VER
PR
47
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
48
WRITES THE MISSING
IMPLEMENTATION
Common repo with contracts - producer
PRODUCER CONSUMER
REPO WITH
CONTRACTS
CLONED REPO
WITH
CONTRACTS
M
ER
G
E
PR
49
WRITES THE MISSING
IMPLEMENTATION
Common repo with contracts - producer
PRODUCER CONSUMER
REPO WITH
CONTRACTS
CI UPLOADS TO NEXUS
/ ARTIFACTORY
50
Sometimes, due to e.g. security reasons, you don’t have access to the producer’s code.
Then you can use a shared repo with contracts:
● that repo is built by your CI and produces a JAR with contract defintions
● the producer downloads the JAR with contracts and finds his contract definitions
either via convention or by provided property
● the producer creates tests and stubs from aforementioned contracts
● the producer deploys a fat JAR and JAR with stubs once the autogenerated tests pass
● the consumer via Stub Runner downloads the stubs from Nexus or can manually
create stubs from the shared repo for offline work
I don’t want to keep my contracts with the producer
51
With Spring Cloud Contract and Consumer Driven Contracts:
● we’ve created an API that suits the consumer and the producer
● expectations were defined by readable contracts
● expectations were tested against the producer
● producer stubs can be reused by consumers
● starting and setting stubs is fully automated
Summary
52
Why use Spring Cloud Contract Verifier?
● Possibility to do CDC with messaging
● Clear and easy to use, statically typed DSL
● Automatic generation of tests from the defined Contract
● Stub Runner functionality - the stubs are automatically downloaded at runtime from
Nexus / Artifactory
● Spring Cloud integration - no discovery service is needed for integration tests
● Integration with Cloud Foundry - Stub Runner Boot
Summary
53
QUESTIONS
54
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
55
mgrzejszczak

More Related Content

PPTX
CI/CD Overview
PPTX
Introduction to microservices
PPTX
Cypress Automation
PDF
Consumer-Driven Contract Testing
PDF
Contract testing and Pact
PDF
Contract Testing
PDF
e2e testing with cypress
PDF
"DevOps > CI+CD "
CI/CD Overview
Introduction to microservices
Cypress Automation
Consumer-Driven Contract Testing
Contract testing and Pact
Contract Testing
e2e testing with cypress
"DevOps > CI+CD "

What's hot (20)

PPTX
Angular
PPTX
Cypress for Testing
PPTX
Consumer-Driven Contract Testing PACT
PDF
An introduction to Behavior-Driven Development (BDD)
PPTX
Introduction to CI/CD
PPTX
Automated Test Framework with Cucumber
PPTX
Cypress E2E Testing
PPTX
Automation Testing With Appium
PPTX
MEAN stack
PDF
Introduzione ad angular 7/8
PPSX
Microservices Docker Kubernetes Istio Kanban DevOps SRE
PPT
Angular Introduction By Surekha Gadkari
PPTX
Introduction to SDET
PDF
Introduction to CICD
PDF
BDD in Action – principles, practices and real-world application
PDF
DevOps introduction
PDF
Deployment Strategies Powerpoint Presentation Slides
PDF
DevOps with GitHub Actions
PPTX
Trunk based development and Canary deployment
Angular
Cypress for Testing
Consumer-Driven Contract Testing PACT
An introduction to Behavior-Driven Development (BDD)
Introduction to CI/CD
Automated Test Framework with Cucumber
Cypress E2E Testing
Automation Testing With Appium
MEAN stack
Introduzione ad angular 7/8
Microservices Docker Kubernetes Istio Kanban DevOps SRE
Angular Introduction By Surekha Gadkari
Introduction to SDET
Introduction to CICD
BDD in Action – principles, practices and real-world application
DevOps introduction
Deployment Strategies Powerpoint Presentation Slides
DevOps with GitHub Actions
Trunk based development and Canary deployment
Ad

Viewers also liked (20)

PDF
Spring Cloud Contract And Your Microservice Architecture
PDF
Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG
PDF
Microservices: Consumer Driven Contracts in Practice
PPTX
Consumer Driven Contracts for microservices
PDF
Microservices Tracing With Spring Cloud and Zipkin @Szczecin JUG
PDF
Consumer Driven Contracts and Your Microservice Architecture
PDF
Microservices Tracing with Spring Cloud and Zipkin
PDF
Consumer Driven Contracts (DDD Perth 2016)
PDF
Microservices Tracing with Spring Cloud and Zipkin (devoxx)
ODP
Testing strategies for micro services - Ketan Soni, Jesal Mistry, ThoughtWorks
PPTX
Building REST APIs with Spring Boot and Spring Cloud
PDF
Implementing microservices tracing with spring cloud and zipkin (spring one)
PDF
Scalable QA With Docker
PPTX
Consumer-driven contracts: avoid microservices integration hell! (LondonCD - ...
PDF
Must.kill.mutants. TopConf Tallinn 2016
PDF
TAPOST Conference 2016 Riga // Better Products Faster: Let's bring the user i...
PPTX
How to generate a rest application - DevFest Vienna 2016
PDF
Swagger 2.0: Latest and Greatest
PPTX
Microservices - firststatedot.net - 13-oct-15
PDF
MicroProfile Devoxx.us
Spring Cloud Contract And Your Microservice Architecture
Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG
Microservices: Consumer Driven Contracts in Practice
Consumer Driven Contracts for microservices
Microservices Tracing With Spring Cloud and Zipkin @Szczecin JUG
Consumer Driven Contracts and Your Microservice Architecture
Microservices Tracing with Spring Cloud and Zipkin
Consumer Driven Contracts (DDD Perth 2016)
Microservices Tracing with Spring Cloud and Zipkin (devoxx)
Testing strategies for micro services - Ketan Soni, Jesal Mistry, ThoughtWorks
Building REST APIs with Spring Boot and Spring Cloud
Implementing microservices tracing with spring cloud and zipkin (spring one)
Scalable QA With Docker
Consumer-driven contracts: avoid microservices integration hell! (LondonCD - ...
Must.kill.mutants. TopConf Tallinn 2016
TAPOST Conference 2016 Riga // Better Products Faster: Let's bring the user i...
How to generate a rest application - DevFest Vienna 2016
Swagger 2.0: Latest and Greatest
Microservices - firststatedot.net - 13-oct-15
MicroProfile Devoxx.us
Ad

Similar to Consumer Driven Contracts and Your Microservice Architecture (20)

PDF
Consumer Driven Contracts like TDD to the API - Olga Maciaszek-Sharma & Marci...
PDF
Consumer Driven Contracts To Enable API Evolution @Geecon
PDF
TDD for Microservices
PDF
Consumer Driven Contracts and Your Microservice Architecture
PPTX
Consumer driven contracts in java world
PPTX
Consumer Driven Contracts and Your Microservice Architecture
PPTX
Coordinating Micro-Services with Spring Cloud Contract
PDF
SpringOne 2016 in a nutshell
PDF
Consumer driven contract testing
PDF
Continuous Deployment of your Application @jSession#5
PDF
Building Distributed Systems with Netflix OSS and Spring Cloud
PDF
Creating and testing REST contracts with Accurest Gradle
PDF
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
PDF
Square Pegs, Square Holes: CI/CD That Fits
PDF
Ensure the integration of Microservices with Consumer Driven Contracts
PDF
Continuous Deployment To The Cloud @DevoxxPL 2017
PPTX
Spring Test Framework
PPTX
Contract driven development
PDF
Resilient and Adaptable Systems with Cloud Native APIs
PPTX
Collaborative Contract Driven Development
Consumer Driven Contracts like TDD to the API - Olga Maciaszek-Sharma & Marci...
Consumer Driven Contracts To Enable API Evolution @Geecon
TDD for Microservices
Consumer Driven Contracts and Your Microservice Architecture
Consumer driven contracts in java world
Consumer Driven Contracts and Your Microservice Architecture
Coordinating Micro-Services with Spring Cloud Contract
SpringOne 2016 in a nutshell
Consumer driven contract testing
Continuous Deployment of your Application @jSession#5
Building Distributed Systems with Netflix OSS and Spring Cloud
Creating and testing REST contracts with Accurest Gradle
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Square Pegs, Square Holes: CI/CD That Fits
Ensure the integration of Microservices with Consumer Driven Contracts
Continuous Deployment To The Cloud @DevoxxPL 2017
Spring Test Framework
Contract driven development
Resilient and Adaptable Systems with Cloud Native APIs
Collaborative Contract Driven Development

More from Marcin Grzejszczak (9)

PDF
Continuous Deployment of your Application @JUGtoberfest
PDF
Continuous Deployment To The Cloud
PDF
Continuous Deployment To The Cloud With Spring Cloud Pipelines @WarsawCloudNa...
PDF
Microservices Tracing With Spring Cloud and Zipkin @CybercomDEV
PDF
Spring Cloud’s Groovy
PDF
Microservices - enough with theory, let's do some code @Geecon Prague 2015
PDF
Stick to the rules - Consumer Driven Contracts. 2015.07 Confitura
PDF
Do you think you're doing microservice architecture? What about infrastructur...
PDF
Introduction to Groovy runtime metaprogramming and AST transforms
Continuous Deployment of your Application @JUGtoberfest
Continuous Deployment To The Cloud
Continuous Deployment To The Cloud With Spring Cloud Pipelines @WarsawCloudNa...
Microservices Tracing With Spring Cloud and Zipkin @CybercomDEV
Spring Cloud’s Groovy
Microservices - enough with theory, let's do some code @Geecon Prague 2015
Stick to the rules - Consumer Driven Contracts. 2015.07 Confitura
Do you think you're doing microservice architecture? What about infrastructur...
Introduction to Groovy runtime metaprogramming and AST transforms

Recently uploaded (20)

PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
sap open course for s4hana steps from ECC to s4
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Encapsulation theory and applications.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Cloud computing and distributed systems.
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
KodekX | Application Modernization Development
“AI and Expert System Decision Support & Business Intelligence Systems”
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Reach Out and Touch Someone: Haptics and Empathic Computing
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
sap open course for s4hana steps from ECC to s4
The AUB Centre for AI in Media Proposal.docx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Programs and apps: productivity, graphics, security and other tools
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation theory and applications.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Cloud computing and distributed systems.
Chapter 3 Spatial Domain Image Processing.pdf
Encapsulation_ Review paper, used for researhc scholars
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
KodekX | Application Modernization Development

Consumer Driven Contracts and Your Microservice Architecture