Skip to main content
Quick navigation

Chaos Simulate Message Corruption

This interceptor simulates message corruption by appending random bytes to messages produced.

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
  • zookeeper
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 virtual cluster teamA

Creating virtual cluster teamA on gateway gateway1 and reviewing the configuration file to access it

# Generate virtual cluster teamA with service account sa
token=$(curl \
--request POST "http://localhost:8888/admin/vclusters/v1/vcluster/teamA/username/sa" \
--header 'Content-Type: application/json' \
--user 'admin:conduktor' \
--silent \
--data-raw '{"lifeTimeSeconds": 7776000}' | jq -r ".token")

# Create access file
echo """
bootstrap.servers=localhost:6969
security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username='sa' password='$token';
""" > teamA-sa.properties

# Review file
cat teamA-sa.properties

Creating topic with-random-bytes on teamA

Creating on teamA:

  • Topic with-random-bytes with partitions:1 and replication-factor:1
kafka-topics \
--bootstrap-server localhost:6969 \
--command-config teamA-sa.properties \
--replication-factor 1 \
--partitions 1 \
--create --if-not-exists \
--topic with-random-bytes

Adding interceptor simulate-massage-corruption

Let's create the interceptor against the virtual cluster teamA, instructing Conduktor Gateway to simulate message corruption by appending random bytes to messages produced.

Creating the interceptor named simulate-massage-corruption of the plugin io.conduktor.gateway.interceptor.chaos.ProduceSimulateMessageCorruptionPlugin using the following payload

{
"pluginClass" : "io.conduktor.gateway.interceptor.chaos.ProduceSimulateMessageCorruptionPlugin",
"priority" : 100,
"config" : {
"topic" : "with-random-bytes",
"sizeInBytes" : 10,
"rateInPercent" : 100
}
}

Here's how to send it:

curl \
--request POST "http://localhost:8888/admin/interceptors/v1/vcluster/teamA/interceptor/simulate-massage-corruption" \
--header 'Content-Type: application/json' \
--user 'admin:conduktor' \
--silent \
--data @step-07-simulate-massage-corruption.json | jq

Listing interceptors for teamA

Listing interceptors on gateway1 for virtual cluster teamA

curl \
--request GET 'http://localhost:8888/admin/interceptors/v1/vcluster/teamA' \
--header 'Content-Type: application/json' \
--user 'admin:conduktor' \
--silent | jq

Send message to our created topic

Producing 1 message in with-random-bytes in cluster teamA

Sending 1 event

{
"message" : "hello world"
}

with

echo '{"message": "hello world"}' | \
kafka-console-producer \
--bootstrap-server localhost:6969 \
--producer.config teamA-sa.properties \
--topic with-random-bytes

Let's consume the message, and confirm message was appended random bytes

This should produce output similar to this:

{"message": "hello world"}T[�   �X�{�
kafka-console-consumer \
--bootstrap-server localhost:6969 \
--consumer.config teamA-sa.properties \
--topic with-random-bytes \
--from-beginning \
--timeout-ms 10000 | jq

returns

jq: parse error: Invalid numeric literal at line 1, column 29
{
"message": "hello world"
}
Processed a total of 1 messages

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 Message Corruption is simple as it!