Skip to content

znsio/specmatic-kafka-sample

Repository files navigation

Specmatic Kafka Sample

This sample project demonstrates how we can run contract tests against a service which interacts with a kafka broker.

Background

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.

Specmatic Kafka Sample Architecture

Pre-requisites

  • Gradle
  • JDK 17+
  • Docker

Run the tests

./gradlew clean test

Run the contract tests using specmatic-kafka docker image

  1. Start the kafka broker using Specmatic's Kafka Mock. [Note - You can use any kafka broker other than this too.]
    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
    Alternatively if you want to use a standard Kafka Docker image you can run below command.
    docker compose up
  2. Run the application.
    ./gradlew bootRun
  3. 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

Get information around other CLI args exposed by specmatic-kafka docker image

  1. To get information around all the CLI args of the virtualize command, run the following.
     docker run znsio/specmatic-kafka-trial virtualize --help
  2. To get information around all the CLI args of the test command, run the following.
     docker run znsio/specmatic-kafka-trial test --help

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages