2. 2
Spring Cloud developer at Pivotal
Working mostly on
● Spring Cloud Contract
● Spring Cloud Netflix
● Spring Cloud Gateway
About us
Twitter: @olga_maciaszek
3. 3
Spring Cloud developer at Pivotal
Working mostly on
● Spring Cloud Sleuth
● Spring Cloud Contract
● CI / CD
About us
Twitter: @mgrzejszczak
Blog: http://toomuchcoding.com
6. 6
● 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
7. 7
● Producer
○ service that exposes an API / sends a message
● Consumer
○ service that consumes the API of the producer / listens to a message
from the producer
● Contract
○ agreement between producer and consumer how the API / message
will look like
● Consumer Driven Contracts
○ approach where the consumer drives the changes of the API of the
producer
Introduction
8. 8
● Stub validity & reusability in the integration tests
● Nice API creation
Introduction
What problems are we trying to solve?
17. 17
● I write the missing code to work with the new URL
● The unit and integration tests pass
● Now we deploy to an environment
where real integrations take place...
Introduction
So now what?
19. 19
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?!
20. 20
Stubs that were used in the build phase have nothing to do with the real communication!!
Introduction
Another example with messaging
CONSUMERPRODUCER
TEST
PRODUCER CONSUMER
REALITY
topic:
bar
topic:
foo
topic:
bar
21. 21
● 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?
● How are you sure you’re listening to the proper topic / queue?
● Are you sure you’ll deserialize your message properly?
Introduction
Stub validity & reusability - typical problems
22. 22
● 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
26. 26
● 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?
27. 27
Introduction
What are we going to code?
I’m 22 give me a beer
CONSUMER PRODUCER
THERE YOU GO
Can the beer be sold?
status: OK, name: marcin
28. 28
Introduction
What are we going to code?
I’m 17 give me a beer
CONSUMER PRODUCER
GET LOST
Can the beer be sold?
status: NOT_OK, name: marcin
45. 45
Spring Cloud Contract with Rest Docs
You can also use
Spring Cloud Contract with Rest Docs!!
45
46. 46
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
47. 47
Learn More. Stay Connected.
▪ Read the docs
http://cloud.spring.io/spring-cloud-contract/
▪ 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