Skip to main content
On this page

Chaos Simulate Duplicate Messages

This interceptor injects duplicate records on produce requests.

This demo will run you through some of these use cases step-by-step.

View the full demo in realtime

You can either follow all the steps manually, or watch the recording

Review the docker compose environment

As can be seen from docker-compose.yaml the demo environment consists of the following services:

  • gateway1
  • gateway2
  • kafka-client
  • kafka1
  • kafka2
  • kafka3
  • schema-registry
cat docker-compose.yaml

Starting the docker environment

Start all your docker processes, wait for them to be up and ready, then run in background

  • --wait: Wait for services to be running|healthy. Implies detached mode.
  • --detach: Detached mode: Run containers in the background
docker compose up --detach --wait

Creating topic topic-duplicate on gateway1

Creating on gateway1:

  • Topic topic-duplicate with partitions:1 and replication-factor:1
kafka-topics \
--bootstrap-server localhost:6969 \
--replication-factor 1 \
--partitions 1 \
--create --if-not-exists \
--topic topic-duplicate

Adding interceptor duplicate-messages

Let's create the interceptor, instructing Conduktor Gateway to inject duplicate records on produce requests.

step-06-duplicate-messages-interceptor.json:

{
"kind" : "Interceptor",
"apiVersion" : "gateway/v2",
"metadata" : {
"name" : "duplicate-messages"
},
"spec" : {
"comment" : "Adding interceptor: duplicate-messages",
"pluginClass" : "io.conduktor.gateway.interceptor.chaos.DuplicateMessagesPlugin",
"priority" : 100,
"config" : {
"rateInPercent" : 100,
"topic" : "topic-duplicate",
"target" : "PRODUCE"
}
}
}
curl \
--silent \
--request PUT "http://localhost:8888/gateway/v2/interceptor" \
--header "Content-Type: application/json" \
--user "admin:conduktor" \
--data @step-06-duplicate-messages-interceptor.json | jq

Listing interceptors

Listing interceptors on gateway1

curl \
--silent \
--request GET "http://localhost:8888/gateway/v2/interceptor" \
--user "admin:conduktor" | jq

Send message to our created topic

Producing 1 message in topic-duplicate in cluster gateway1

Sending 1 event

{
"message" : "hello world"
}
echo '{"message": "hello world"}' | \
kafka-console-producer \
--bootstrap-server localhost:6969 \
--topic topic-duplicate

Let's consume the message, and confirm message was duplicated

Let's consume the message, and confirm message was duplicated in cluster gateway1

kafka-console-consumer \
--bootstrap-server localhost:6969 \
--topic topic-duplicate \
--from-beginning \
--max-messages 3 \
--timeout-ms 3000 | jq

returns 2 events

{
"message" : "hello world"
}
{
"message" : "hello world"
}

Tearing down the docker environment

Remove all your docker processes and associated volumes

  • --volumes: Remove named volumes declared in the "volumes" section of the Compose file and anonymous volumes attached to containers.
docker compose down --volumes

Conclusion

Yes, Chaos Simulate Duplicate Messages is simple as it!