2. About Us
Reshmi Krishna
● Software Engineer
● Platform Architect, Pivotal Cloud Foundry
● Women In Tech Community Member
Twitter : @reshmi9k
MeetUp : Cloud-Native-New-York
Vinay Upadhya
● Software Engineer
● Platform Architect, Pivotal Cloud Foundry
● Application Architecture Evangelist
Twitter : @vinayu
3. Agenda
What are Consumer Driven Contracts?
What problems are we trying to solve?
Spring Cloud Contract for microservices
Demo
4. What are Consumer Driven Contracts?
Internal
Marketing
App
External
Reseller
App
Product
Search
Service
A
P
I
{ catalogid, name,
price,
manufacturer }
{ catalogid,
name, price }
Product Schema
{ catalogid, name, price,
manufacturer,
inStock }
Producer
Contract
Expectation
Consumer
Contract
Consumer Driven
Contract
5. What are Consumer Driven Contracts ( CDC )
Not a new concept but becoming more prevalent in today’s world of
microservices.
It is a pattern for evolving services and their API’s without breaking
backward or forward compatibility.
CDC driven testing is TDD applied at an architectural level of the project.
6. What problems are we trying to solve?
1. Provide a framework for consumers to set
expectations with consumer contracts and
drive the producer API.
2. Producer test lifecycle includes validating
consumer contracts.
3. Provide reusable producer stubs for
consumers to use in their integration tests.
4. Minimize E2E integration tests.
7. Spring Cloud Contract
Spring Cloud Contract provides support for CDC and service schemas in Spring Apps.
Being part of Spring Cloud it can help stub out Spring Cloud components like Eureka, Consul
etc.
Comprised of three main projects :-
Spring Cloud Contract Verifier : Library on server side to test if the server isn’t breaking any
consumer contracts.
Spring Cloud Contract Wiremock : Wrapper around wiremock to help start stubs with
wiremock json stubs.
Spring Cloud Contract Stub Runner : Helper library to pull stubs from maven and run them
12. Consumer Flow 1 (Login Client)
Start TDD - writes the test for the feature
Write the missing implementation
Clone the Producer (LoginServerService) repository locally
Define the contract locally in the repo of Producer
Add the Spring Cloud Contract Verifier plugin
Run the integration tests
13. Producer Flow (Login Server)
Take over the PR
Write the missing implementation that will make the autogenerated tests pass
Merge PR and deploys the JARs with the app and the stubs
14. Consumer Flow 2 (Login Client)
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