Contenu connexe Similaire à Ensure the integration of Microservices with Consumer Driven Contracts (20) Ensure the integration of Microservices with Consumer Driven Contracts1. 1 | Titel| 7. Juni 2019
1 | © GBTEC Software + Consulting AG 2019
Titelmasterformat durch Klicken bearbeiten
Folienmaster
Ingo Griebsch, Coding Architect @GBTEC
Ensure the integration of Microservices with Consumer Driven Contracts
2. 2 | Titel| 7. Juni 2019
2 | © GBTEC Software + Consulting AG 2019
@d0gb0t666
Coding Architect @GBTEC
Husband and father of two
Boardgame addict
Love Clutch as well as Tricky
Who am I
ingogriebsch
3. 3 | Titel| 7. Juni 2019
3 | © GBTEC Software + Consulting AG 2019
If anything is unclear or not understandable…
What the heck is he talking about?
4. 4 | Titel| 7. Juni 2019
4 | © GBTEC Software + Consulting AG 2019
Agenda
1. Terms and definitions
2. The problem
3. Possible solutions
4. Implementation
5. Conclusion
5. 5 | Titel| 7. Juni 2019
5 | © GBTEC Software + Consulting AG 2019
Terms and definitions
May I have your attention, please?
6. 6 | Titel| 7. Juni 2019
6 | © GBTEC Software + Consulting AG 2019
Terms and definitions
Microservices
- are an architectural style that structures an
application as a collection of services.
- enable the continuous deployment of large,
complex applications.
- are highly maintainable and testable, loosely
coupled and independently deployable.
7. 7 | Titel| 7. Juni 2019
7 | © GBTEC Software + Consulting AG 2019
Terms and definitions
(Microservices based) Application
- is a software designed to perform a group
of coordinated functions, tasks, or
activities for the benefit of the user.
- represents a suite of small services, each
communicating with lightweight
mechanisms, often a REST like API.
8. 8 | Titel| 7. Juni 2019
8 | © GBTEC Software + Consulting AG 2019
Representational State Transfer (REST)
- is an architectural style for providing
standards between computer systems on the
web, making it easier for systems to
communicate with each other.
- Services implementing REST allow to access
and manipulate textual representations of
resources by using a uniform and predefined
set of stateless operations.
Terms and definitions
9. 9 | Titel| 7. Juni 2019
9 | © GBTEC Software + Consulting AG 2019
Terms and definitions
Application Programming Interface (API)
- represents a set of clearly defined methods of
communication among various components.
- simplifies programming by abstracting the
underlying implementation and only exposing
objects or actions a developer needs.
- is typically defined as a set of specifications, such
as HTTP request messages, along with a
definition of the structure of response messages,
usually in an XML or JSON format.
10. 10 | Titel| 7. Juni 2019
10 | © GBTEC Software + Consulting AG 2019
Terms and definitions
Contract
- represents an agreement between a producer
and a consumer of an API how it will look like.
Producer
- is a service that exposes an API which is
consumed by several services.
Consumer
- is a service that consumes the API of a producer.
11. 11 | Titel| 7. Juni 2019
11 | © GBTEC Software + Consulting AG 2019
The problem
Why is this broken (again)?
12. 12 | Titel| 7. Juni 2019
12 | © GBTEC Software + Consulting AG 2019
The problem
A producer provides a specific API which is available through REST and allows the
access to specific resources hold inside the service.
13. 13 | Titel| 7. Juni 2019
13 | © GBTEC Software + Consulting AG 2019
The problem
A consumer wants to call the API of the producer through REST to receive some of
the hold resources.
14. 14 | Titel| 7. Juni 2019
14 | © GBTEC Software + Consulting AG 2019
The problem
The consumer expects a specific API (for whatever reason) which is NOT implemented
this way through the producer (not at all or not anymore).
15. 15 | Titel| 7. Juni 2019
15 | © GBTEC Software + Consulting AG 2019
The problem
There can be several reasons why the consumer expects an API which is not
provided that way by the producer:
- The producer changed the API because he did not (yet/anymore) expect the
consumer.
- The producer changed the API because of a requirement of another consumer.
- The producer changed the API by accident.
- The API is either incorrectly documented or not sufficiently documented.
- Producer and consumer have talked past each other.
- The consumer expects that the API should work that way.
16. 16 | Titel| 7. Juni 2019
16 | © GBTEC Software + Consulting AG 2019
Possible solutions
How could we solve this problem?
17. 17 | Titel| 7. Juni 2019
17 | © GBTEC Software + Consulting AG 2019
Possible solutions
When trying to test an application that communicates with other services then we
could do one of the following things:
- Deploy all microservices and perform end to end tests.
- Mock other microservices in integration tests.
- Define contracts to be able to generate and use real world mocks in integration tests.
18. 18 | Titel| 7. Juni 2019
18 | © GBTEC Software + Consulting AG 2019
Possible solutions
- Advantages
- Simulates production.
- Tests real communication between services.
- Disadvantages
- To test one microservice we would have to deploy several services, databases etc.
- The environment where the tests would be conducted is locked during the tests.
- Needs a long time to run the tests.
- Very late feedback.
Deploy all microservices and perform end to end tests
19. 19 | Titel| 7. Juni 2019
19 | © GBTEC Software + Consulting AG 2019
Possible solutions
- Advantages
- Very fast feedback.
- No infrastructure required.
- Disadvantages
- The consuming service creates mocks that might have nothing to do with reality.
- You can go to production with passing tests and failing production.
Mock other microservices in integration tests
20. 20 | Titel| 7. Juni 2019
20 | © GBTEC Software + Consulting AG 2019
Possible solutions
- Advantages (in addition to the already mentioned advantages)
- Ensures that the mocks behave exactly like the actual producer is implemented.
- Changes in contracts are immediately visible on both sides of the communication.
- Promote acceptance test driven development method and Microservices
architectural style.
Define contracts to be able to generate and use real world mocks
21. 21 | Titel| 7. Juni 2019
21 | © GBTEC Software + Consulting AG 2019
Implementation
Let’s do it!
22. 22 | Titel| 7. Juni 2019
22 | © GBTEC Software + Consulting AG 2019
Implementation
Developers who implement the consumer and developers who implement the
producer team up to define the contracts based on the needs of the consumer.
23. 23 | Titel| 7. Juni 2019
23 | © GBTEC Software + Consulting AG 2019
Implementation
The contracts will then bundled and stored in a repository. The repository is
available for both the consumer and the producer.
24. 24 | Titel| 7. Juni 2019
24 | © GBTEC Software + Consulting AG 2019
Implementation
The producer uses the contracts from the repository to verify that the API it
provides fulfills the contracts.
25. 25 | Titel| 7. Juni 2019
25 | © GBTEC Software + Consulting AG 2019
Implementation
The consumer uses the contracts from the repository to verify that they call the API
in the way the producer provides.
26. 26 | Titel| 7. Juni 2019
26 | © GBTEC Software + Consulting AG 2019
Conclusion
Nothing to worry about, we are on a good way!
27. 27 | Titel| 7. Juni 2019
27 | © GBTEC Software + Consulting AG 2019
Conclusion
- Communication in a Microservices world is a complex problem.
- There are solutions available which help you to effectively test the
behavior of and communication between microservices.
- Talk to each other! ;) Using APIs is something that can cross team
boundaries, so it’s essential to get all involved.
- Some preparation is necessary to be able to define and use
consumer driven contracts.
28. 28 | Titel| 7. Juni 2019
28 | © GBTEC Software + Consulting AG 2019
Questions
Brace yourself, questions are incoming!
29. 29 | Titel| 7. Juni 2019
29 | © GBTEC Software + Consulting AG 2019
Sources
- https://martinfowler.com/articles/consumerDrivenContracts.html
- https://reflectoring.io/7-reasons-for-consumer-driven-contracts/
- https://spring.io/projects/spring-cloud-contract
- https://docs.pact.io/
- https://en.wikipedia.org/wiki/Representational_state_transfer
- https://www.novatec-gmbh.de/en/blog/introduction-microservices-testing-
consumer-driven-contract-testing-pact/
- https://sketchingdev.co.uk/blog/consumer-driven-contracts-by-example.html
- https://www.youtube.com/watch?v=sAAklvxmPmk
- https://www.youtube.com/watch?v=-51Jlyrhskc&feature=youtu.be&t=19990
30. 30 | Titel| 7. Juni 2019
30 | © GBTEC Software + Consulting AG 2019
GBTEC Software + Consulting AG
Gesundheitscampus-Süd 23
44801 Bochum
Internet www.gbtec.de
E-Mail info@gbtec.de