consumer driven contracts for microservices
TRANSCRIPT
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
Agenda
What are Consumer Driven Contracts?
What problems are we trying to solve?
Spring Cloud Contract for microservices
Demo
What are Consumer Driven Contracts?
Internal Marketing
App
External Reseller
App
Product SearchService
API
{ catalogid, name, price, manufacturer }
{ catalogid, name, price }
Product Schema
{ catalogid, name, price, manufacturer,inStock }
Producer Contract
Expectation
Consumer Contract
Consumer Driven Contract
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.
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.
Spring Cloud ContractSpring 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 with wiremock.
Typical CDC Flow Consumer Phase 1 Producer Phase Consumer Phase 2
Consumer Offline Work
Producer Implementing Feature
Consumer Online Work
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
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
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
ResourcesDocs : https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract.html
MeetUp Demo : https://github.com/reshmik/spring-cloud-contract-login-demo.git
Consumer Driven Contracts (MarcinGrzejszczak) : http://www.slideshare.net/MarcinGrzejszczak/consumer-driven-contracts-and-your-microservice-architecture-67641511
More Samples : https://github.com/spring-cloud/spring-cloud-contract/tree/1.0.x/samples
Talk to the SpringCloudContract Team : https://gitter.im/spring-cloud/spring-cloud-contract