Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

830 views

Published on

TDD introduced many improvements into the development process, but in our opinion the biggest impact relates to code design. Looking at the code from the usage perspective (by first writing an acceptance test) allows us to focus on usability rather than concrete implementation. Unfortunately, we usually rest on our laurels not trying to uplift this practice to the architecture level.

This presentation will show you how you can use the Spring Cloud Contract Verifier functionality in order to have a fully automated solution to stub your HTTP / Messaging collaborators. Just by adding proper configuration, you'll surround the microservices you are testing with faked stubs that are tested against their producer, making much more realistic tests.

We will write a system using the CDC approach together with Spring Boot, Spring Cloud and Spring Cloud Contract Verifier. I'll show you how easy it is to write applications that have a consumer-driven API, allowing a developer to speed up the time for writing better quality software.

Code Samples are available here - https://github.com/spring-cloud-samples/spring-cloud-contract-samples

Published in: Technology
  • Be the first to comment

Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

  1. 1. 1 © 2016 Pivotal Consumer Driven Contracts and Your Microservice Architecture Marcin Grzejszczak, @mgrzejszczak
  2. 2. 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. 3. 3 Introduction Demo Summary Agenda
  4. 4. 4 What we will NOT be talking about?
  5. 5. 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. 6. 6 ● ○ ● ○ ● ○ ● ○ Introduction
  7. 7. 7 ● ● Introduction What problems are we trying to solve?
  8. 8. 8 Introduction Typical situation HTTP CONSUMER PRODUCER
  9. 9. 9 Introduction How to write a test for it? HTTP CONSUMER PRODUCER
  10. 10. 10 Introduction How to write a test for it? HTTP CONSUMER PRODUCER
  11. 11. 11 Introduction Stub validity & reusability WE’RE ON THE CONSUMER SIDE!! CONSUMER OWNS THE STUB DEFINITIONS
  12. 12. 12 Introduction Stub validity & reusability
  13. 13. 13 Introduction Let’s assume that we’re introducing a new endpoint...
  14. 14. 14 Introduction Stub validity & reusability
  15. 15. 15 ● ● ● Introduction So now what?
  16. 16. 16 Introduction Ooops...
  17. 17. 17 Introduction What went wrong? HTTP CONSUMER PRODUCER TEST OK HTTP CONSUMER PRODUCER REALITY WAT?!
  18. 18. 18 Introduction Another example with messaging CONSUMERPRODUCER TEST PRODUCER CONSUMER REALITY topic: bar topic: foo topic: bar
  19. 19. 19 ● ● ● ● ● ● Introduction Stub validity & reusability
  20. 20. 20 ● ● ● Introduction Nice API creation
  21. 21. 21 Introduction Nice API creation - no cooperation results
  22. 22. 22 Introduction Nice API creation - no cooperation results
  23. 23. 23 Demo Potential answer Spring Cloud Contract
  24. 24. 24 ● ○ ○ ● ○ ● ○ ○ Demo What are we going to code?
  25. 25. 25 ● ○ ● ○ ● ○ Demo What are we going to code?
  26. 26. 26 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!
  27. 27. 27 Introduction What are we going to code? I’m 17 give me a beer CONSUMER PRODUCER Get lost! Can he get the beer? No!
  28. 28. 28 Introduction What are we going to code? Someone’s 22. Check him out! CONSUMERPRODUCER Positive verification took place Messaging
  29. 29. 29 Introduction What are we going to code? Someone’s 17. Check him out! CONSUMERPRODUCER Negative verification took place Messaging
  30. 30. 30 Introduction What are we going to code? BLACK TERMINAL BLACK IDE CONSUMER WHITE TERMINAL WHITE IDE PRODUCER
  31. 31. 31 Demo
  32. 32. 32 Summary
  33. 33. 33 Summary PRODUCER CONSUMER
  34. 34. 34 Summary PRODUCER CONSUMER CLONES PRODUCER PRODUCER CLONE CONSUMER
  35. 35. 35 Summary PRODUCER CONSUMER CONSUMER CLONES PRODUCER PRODUCER CLONE INTERACTION
  36. 36. 36 Summary PRODUCER CONSUMER PRODUCER CLONE INTERACTION CONSUMER FILES A PR
  37. 37. 37 Summary
  38. 38. 38 Summary PRODUCER TAKES OVER THE PR
  39. 39. 39 Summary PRODUCER TAKES OVER THE PR WRITES THE MISSING IMPLEMENTATION
  40. 40. 40 Summary PRODUCER TAKES OVER THE PR WRITES THE MISSING IMPLEMENTATION MERGES TO MASTER CI UPLOADS TO NEXUS / ARTIFACTORY
  41. 41. 41 Summary
  42. 42. 42 Summary CONSUMER SWITCHES TO ONLINE MODE DOWNLOADS STUBS OF COLLABORATORS DURING BUILD PHASE
  43. 43. 43 Summary
  44. 44. 44 Summary
  45. 45. 45 I don’t want to keep my contracts with the producer
  46. 46. 46 Demo
  47. 47. 47 Common repo with contracts - consumer PRODUCER CONSUMER
  48. 48. 48 Common repo with contracts - consumer PRODUCER CONSUMER REPO WITH CONTRACTS
  49. 49. 49 Common repo with contracts - consumer PRODUCER CONSUMER REPO WITH CONTRACTS G IT C LO N E CLONED REPO WITH CONTRACTS
  50. 50. 50 Common repo with contracts - consumer PRODUCER CONSUMER REPO WITH CONTRACTS G IT C LO N E CLONED REPO WITH CONTRACTS INTERACTION
  51. 51. 51 Common repo with contracts - consumer PRODUCER CONSUMER REPO WITH CONTRACTS CLONED REPO WITH CONTRACTSPR
  52. 52. 52 Common repo with contracts - producer PRODUCER CONSUMER REPO WITH CONTRACTS
  53. 53. 53 Common repo with contracts - producer PRODUCER CONSUMER REPO WITH CONTRACTS CLONED REPO WITH CONTRACTS PR O D U C ER TAKES O VER PR
  54. 54. 54 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
  55. 55. 55 WRITES THE MISSING IMPLEMENTATION Common repo with contracts - producer PRODUCER CONSUMER REPO WITH CONTRACTS CLONED REPO WITH CONTRACTS M ER G E PR
  56. 56. 56 WRITES THE MISSING IMPLEMENTATION Common repo with contracts - producer PRODUCER CONSUMER REPO WITH CONTRACTS CI UPLOADS TO NEXUS / ARTIFACTORY
  57. 57. 57 ● ● ● ● ● I don’t want to keep my contracts with the producer
  58. 58. 58 I don’t want to write any scripts!
  59. 59. 59 Introduction Don’t worry! You can use Spring Cloud Contract WireMock with Rest Docs!!
  60. 60. 60 Demo
  61. 61. 61 ● ● ● ● ● Summary
  62. 62. 62 ● ● ● ● ● ● Summary
  63. 63. 63 QUESTIONS
  64. 64. 64 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
  65. 65. 65 mgrzejszczak

×