This sample project demonstrates how we can run contract tests against a service which interacts with a kafka broker.
This project includes a consumer that listens to messages on a specific topic. Upon receiving a message, the consumer processes it and publishes a new message to two other designated topics.
- Gradle
- JDK 17+
- Docker
./gradlew clean test
- Start the kafka broker using Specmatic's Kafka Mock. [Note - You can use any kafka broker other than this too.]
Alternatively if you want to use a standard Kafka Docker image you can run below command.
docker run -p 9092:9092 -p 2181:2181 -p 29092:29092 -v "$PWD/specmatic.yaml:/usr/src/app/specmatic.yaml" znsio/specmatic-kafka-trial virtualize
docker compose up
- Run the application.
./gradlew bootRun
- Run the contract tests.
docker run --network="host" -v "$PWD/specmatic.yaml:/usr/src/app/specmatic.yaml" -v "$PWD/src/test/resources:/usr/src/app/examples" znsio/specmatic-kafka-trial test --examples=examples
- To get information around all the CLI args of the
virtualize
command, run the following.docker run znsio/specmatic-kafka-trial virtualize --help
- To get information around all the CLI args of the
test
command, run the following.docker run znsio/specmatic-kafka-trial test --help