In microservices architecture
Bartosz Frąckowiak
How can we ensure that two separate systems (such as two microservices) are compatible and are able to communicate with one other?
| INTEGRATION | CONTRACT |
|---|---|
| Validate subset of execution logic | Validates only service endpoints structure |
| Can include contract specification check into scope | Based on the contract specification |
| broaden scope | tight scope |
| causes side effects on service | no mocking required |
| Validates actual response | Validates only contract specification |
Can a service provider know about its consumers?
Can consumers know about service provider flows?
Who creates/owns the tests?
Where tests should be run?
What about other communication protocols than HTTP?
Pack.io demo
Implements spec 2.0
Only Sync HTTP calls
Not data type validation
Platform-specific
The specification in form of plain .NET code
reflection-based tests
Versioning, hosting server out of the box
Technology coupling
How to test the NuGet package on FE?
The OpenAPI Specification (OAS) defines a standard, language-agnostic interface to RESTful APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection. When properly defined, a consumer can understand and interact with the remote service with a minimal amount of implementation logic.
The AsyncAPI Specification is a project used to describe and document message-driven APIs in a machine-readable format. It’s protocol-agnostic, so you can use it for APIs that work over any protocol (e.g., AMQP, MQTT, WebSockets, Kafka, STOMP, HTTP, Mercure, etc).
OpenAPI and AsyncAPI specs demo
Update service contract with Semantic versioning
After each merge to master build agent uploads OpenAPI spec to dedicated storage
Dedicated storage keeps tract of each contract specification of each service
Each Contract test on consumer side get specification of provider in particular version using simple HTTP protocol and keeps in memory
Consumer runs a PR-gate build, within contract tests inside
Asserting is done in a fasy and efective way. Each asseret do not casue any state change on eight consumer or provider side.
OpenAPI contract test demo
"We can solve any problem by introducing an extra level of indirection."
is a term originated by Andrew Koenig to describe a remark by Butler Lampson[1] attributed to David J. Wheeler:[2]