Skip to content

Latest commit

 

History

History
66 lines (43 loc) · 1.95 KB

File metadata and controls

66 lines (43 loc) · 1.95 KB

Kafka Sample Generator Tool

This tool generates base64-encoded serialized products for testing the Kafka consumer functions with different serialization formats.

Supported Formats

  • JSON: Generates base64-encoded JSON serialized products
  • Avro: Generates base64-encoded Avro serialized products
  • Protobuf: Generates base64-encoded Protobuf serialized products

Usage

Run the following Maven commands from this directory:

# Generate Avro and Protobuf classes from schemas
mvn generate-sources

# Compile the code
mvn compile

Generate JSON Samples

# Run the JSON sample generator
mvn exec:java -Dexec.mainClass="org.demo.kafka.tools.GenerateJsonSamples"

The tool will output base64-encoded values for JSON products that can be used in ../events/kafka-json-event.json.

Generate Avro Samples

# Run the Avro sample generator
mvn exec:java -Dexec.mainClass="org.demo.kafka.tools.GenerateAvroSamples"

The tool will output base64-encoded values for Avro products that can be used in ../events/kafka-avro-event.json.

Generate Protobuf Samples

# Run the Protobuf sample generator
mvn exec:java -Dexec.mainClass="org.demo.kafka.tools.GenerateProtobufSamples"

The tool will output base64-encoded values for Protobuf products that can be used in ../events/kafka-protobuf-event.json.

Output

Each generator produces:

  1. Three different products (Laptop, Smartphone, Headphones)
  2. An integer key (42) and one entry with a nullish key to test for edge-cases
  3. A complete sample event structure that can be used directly for testing

Example

After generating the samples, you can copy the output into the respective event files:

  • ../events/kafka-json-event.json for JSON samples
  • ../events/kafka-avro-event.json for Avro samples
  • ../events/kafka-protobuf-event.json for Protobuf samples

These event files can then be used to test the Lambda functions with the appropriate deserializer.