Local Out-Of-Process Plugin (LOOPP) will make our setup look a lot more like microservices system
Language independent
Efficient Data Compaction
Efficient serialization and deserialization (uses HTTP2)
Simple to use
To ensure that HTTP and Messaging stubs (used when developing the client) do exactly what the actual server-side implementation does.
To promote the ATDD (acceptance test-driven developement) method and the microservices architectural style.
TDD for services
To provide a way to publish changes in contracts that are immediately visible on both sides.
To generate boilerplate test code to be used on the server side
Purposes
Even if the API client had been been graciously provided for us by our Provider Team, it doesn't mean that we shouldn't write contract tests -
because the version of the client we have may not always be in sync with the deployed API
because we will write tests on the output appropriate to our specific needs.
Network Diagram
Gradle
After Test execution Pact will automatically send test results to Pact Broker
Consumer Pipeline
Provider Pipeline
Process
As a Provider and following CDC approach, you need to
Routine on Producer Side
Routine on Producer Side
Routine on Producer Side
Routine on Producer Side
Routine on Producer Side
Adjust Gradle config in order to map contracts to Base test classes
Generate and Run the tests
./gradlew generateContractTests - will only generate tests in build/generated-test-sources folder
./gradlew clean build - generate, run tests and create a Stub Runner based on a contract
Routine on Producer Side
Routine on Producer Side
Publish Contracts
As a Consumer and following CDC approach, you need to
Routine on Consumer Side
Add SCC dependencies to your consumer codebase
testImplementation("org.springframework.cloud:spring-cloud-starter-contract-stub-runner:<version>") - downloads Stub runner and configures it
Routine on Consumer Side
Add a Junit test where Provider side is invoked and setup Provider URL and Port and run the test
Routine on Consumer Side
Routine on Consumer Side
Download Provider Stub (Provider Mock) from
Routine on Consumer Side
Ways to generate a Stub
Complimentary Info
The ids of the stubs to run in "ivy" notation([groupId]:artifactId[:version][:classifier][:port]). version, classifier (default is "stubs") and port can be optional
stubsPerConsumer -
On the producer side the consumers can have a folder that contains contracts related only to them. By setting the flag to true we no longer register all stubs but only those that correspond to the consumer application's name. In other words we'll scan the path of every stub and if it contains the name of the consumer in the path only then will it get registered
Integrations
Integration with Spring AMQP
Basically, the same routine as for REST
Integration with Spring AMQP
Different schema for the contract
Integration with Spring AMQP
On Producer side: provide Base Test class which sends the Message
Integration with Spring AMQP
On Producer side: which will generate following Test
Integration with Spring AMQP
On Consumer side:
Assuming we have performed some changes in the API exposed by person-service and we have modified contracts on the producer side, we would like to publish them on a shared server.