Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Collaborative Contract-Driven Development

248 Aufrufe

Veröffentlicht am

SpringOne Platform 2019
Session Title: Collaborative Contract-Driven Development
Speaker: Billy Korando, Developer Advocate, IBM
Youtube: https://youtu.be/buJdbBNJARc

Veröffentlicht in: Software
  • Als Erste(r) kommentieren

  • Gehören Sie zu den Ersten, denen das gefällt!

Collaborative Contract-Driven Development

  1. 1. Collaborative Contract Driven Development Billy Korando Developer Advocate - IBM @BillyKorando william.korando@ibm.com 📬
  2. 2. @BillyKorando Subscribe to the Java Newsletter https://developer.ibm.com/newsletters/java/ For your Spring & JakartaEE needs https://cloud.ibm.com/docs/java
  3. 3. @BillyKorando https://billykorando.com/category/automated-testing/
  4. 4. @BillyKorando CONTRACT DRIVEN DEVELOPMENT DEFINED (BRIEFLY)
  5. 5. @BillyKorando DEFINING THE BEHAVIOR OF AN API SERVICE CLIENT Response: 200 { … } Request /api/… { … }
  6. 6. @BillyKorando DECONSTRUCTING THE STATUS QUO (i.e. WHY DEVELOPMENT IS DIFFICULT WITHOUT CONTRACTS)
  7. 7. @BillyKorando POORLY DEFINED SERVICES
  8. 8. @BillyKorando POORLY DEFINED SERVICES
  9. 9. @BillyKorando SCENE BREAKDOWN ● Poorly defined or undocumented API ● Inconsistent behavior or patterns ● Testing against a live service can lead to inconsistent results
  10. 10. @BillyKorando VERY SERIAL DEVELOPMENT
  11. 11. @BillyKorando VERY SERIAL DEVELOPMENT
  12. 12. @BillyKorando SCENE BREAKDOWN ● Inability to develop in parallel ● Timeline impacted by delays from both service and client developers ● Client developer will have to get back up to speed
  13. 13. @BillyKorando I AM ALTERING THE API
  14. 14. @BillyKorando I AM ALTERING THE API
  15. 15. @BillyKorando SCENE BREAKDOWN ● Breaking API changes not caught until production ● API design governed almost entirely by service developer
  16. 16. @BillyKorando CONTRACT DRIVEN DEVELOPMENT EXPLAINED USING SPRING CLOUD CONTRACT
  17. 17. @BillyKorando SPRING CLOUD CONTRACT ● Very active project ● Inter-operable with other tools/standards: OpenAPI, Pact, Swagger ● Flexible documentation support with Spring REST Docs ● Polyglot support More: https://spring.io/projects/spring-cloud-contract
  18. 18. @BillyKorando WRITING THE CONTRACT Contract.make { label “Add New Person” request { method 'POST' url '/api/persons' body([ fName: “John” lName: “Doe”]) headers { header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)} } response { status 201 headers { header(HttpHeaders.LOCATION, 'api/persons/1')} } }
  19. 19. @BillyKorando VALIDATING THE CONTRACT ✅ Add New Person Service
  20. 20. @BillyKorando SHARING THE CONTRACT Stubs Artifact
  21. 21. @BillyKorando SHARING THE CONTRACT Artifact RepositoryStubs Artifact
  22. 22. @BillyKorando DOCUMENTING THE API
  23. 23. @BillyKorando VALIDATING AGAINST THE CONTRACT Stubs Artifact Client✅
  24. 24. @BillyKorando CONTRACT DRIVEN DEVELOPMENT IN REVIEW 1. Write contract(s) to define API behavior 2. Contracts validate API matches behavior 3. Bundle contracts as shareable artifact 4. Generate documentation from contracts 5. Clients can test/develop against artifact }Automated
  25. 25. @BillyKorando
  26. 26. @BillyKorando PRODUCER DRIVEN CONTRACTS THE API WILL LOOK LIKE THIS OK SERVICE CLIENT
  27. 27. @BillyKorando CONSUMER DRIVEN CONTRACTS OK I NEED THIS FROM THE SERVICE SERVICE CLIENT
  28. 28. @BillyKorando WHY COLLABORATION IS IMPORTANT ● Better utilization of developer time ● More input from parties on API design ● More buy-in from parties on API design
  29. 29. @BillyKorando CAN’T SPELL “COLLABORATIVE” WITHOUT “POLYGLOT”
  30. 30. @BillyKorando Javascript Developers JDK Maven Java friendly IDE Docker Text editor Java Developers JDK Maven Java friendly IDE Docker Text editor Other Developers JDK Maven Java friendly IDE Docker Text editor ✅ ✅ ✅ ✅ ✅ ❌ ❌ ❌ ✅ ✅ ❌ ❌ ❌ ✅ ✅ LANGUAGE INDEPENDENT TOOLS
  31. 31. @BillyKorando YAML CONTRACT request: label: “Add New Person” method: POST url: /api/persons body: fName: “John” lName: “Doe” headers: Content-Type: application/json response: status: 201 headers: Location: api/persons/1
  32. 32. @BillyKorando DOCKER IMAGES FOR READING CONTRACTS ● Encapsulates all Java and Spring Cloud Contract logic within a Docker container ● Images for both consumers and producers ● Configured by passing in environment variables ● Example of using producer image link ● Example of using consumer image link
  33. 33. @BillyKorando CONTRACT TESTING WITH DOCKER Client✅ Stubs Artifact
  34. 34. @BillyKorando Service✅ CONTRACT TESTING WITH DOCKER
  35. 35. DEMO TIME!
  36. 36. @BillyKorando POORLY DEFINED SERVICES X
  37. 37. @BillyKorando SCENE BREAKDOWN ● API is documented automatically as a result of the process ● Accurate documentation encourages discussion on design/consistency ● Clients can develop/test against contracts which give consistent results
  38. 38. @BillyKorando VERY SERIAL DEVELOPMENT X
  39. 39. @BillyKorando SCENE BREAKDOWN ● Client and service developers can work in parallel once contract is written ● Process encourages discussion on API design
  40. 40. @BillyKorando I AM ALTERING THE API X
  41. 41. @BillyKorando SCENE BREAKDOWN ● API is checked as part of build process ● Changes will cause either service or client to fail ● Prevents “rogue” changes from reaching PROD and becoming “finalized”
  42. 42. @BillyKorando FINAL POINTS ● Not just REST/HTTP, can also write contracts for messages ● It’s ok to change contracts ● Contract tests are not acceptance tests nor replace end-to-end tests ○ Not tested: ■ Resiliency ■ Timeout ■ Performance ■ Edge cases
  43. 43. @BillyKorando Q & A
  44. 44. @BillyKorando SOURCES Code: https://github.com/wkorando/collaborative-contract-driven-development-2-0 Additional Reading: https://cloud.spring.io/spring-cloud-contract/single/spring-cloud-contract.html https://spring.io/blog/2018/02/13/spring-cloud-contract-in-a-polyglot-world IBM Cloud sign up: https://ibm.biz/springonelab Twitter: @BillyKorando Email: William.Korando@ibm.com

×