Skip to content

Commit

Permalink
- Using temporary volumes in docker-compose.yaml so that Kafka starts…
Browse files Browse the repository at this point in the history
… with zero messages from previous run

- Updating README to use particular Docker image version of Specmatic Kafka
- Removing unused test container code
  • Loading branch information
harikrishnan83 committed Jan 31, 2025
1 parent ca26e36 commit 8d1b603
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 37 deletions.
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
* [Specmatic Website](https://specmatic.io)
* [Specmatic Documenation](https://specmatic.io/documentation.html)

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

**NOTE**: This project uses **AsyncAPI 2.6** specification. For equivalent sample project that uses **AsyncAPI 3.0** spec please refer to **[specmatic-kafka-sample-asyncapi3](https://github.com/znsio/specmatic-kafka-sample-asyncapi3)**.

## Background
This project includes a consumer that listens to messages on a specific topic.
Expand All @@ -22,13 +24,9 @@ Upon receiving a message, the consumer processes it and publishes a new message
./gradlew clean test
```

## Run the contract tests using specmatic-kafka docker image
## 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.]
```shell
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.
1. Start the kafka broker using below command.
```shell
docker compose up
```
Expand All @@ -38,7 +36,7 @@ Upon receiving a message, the consumer processes it and publishes a new message
```
3. Run the contract tests.
```shell
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
docker run --network host -v "$PWD/specmatic.yaml:/usr/src/app/specmatic.yaml" -v "$PWD/src/test/resources:/usr/src/app/examples" -v "$PWD/build/reports:/usr/src/app/build/reports" znsio/specmatic-kafka-trial:0.22.13 test --examples=examples
```

## Get information around other CLI args exposed by specmatic-kafka docker image
Expand Down
6 changes: 5 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ services:
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
volumes:
- /var/lib/zookeeper

kafka:
image: confluentinc/cp-kafka:latest
Expand All @@ -22,4 +24,6 @@ services:
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
depends_on:
- zookeeper
- zookeeper
volumes:
- /var/lib/kafka/data

This file was deleted.

0 comments on commit 8d1b603

Please sign in to comment.