Skip to main content
Back to Dev generators

Dev

Mock Kafka Message Generator

Testing a Kafka consumer correctly requires realistic message records — not just the payload, but the topic, partition, offset, key, and headers that a real broker sends. Writing these by hand is tedious and easy to get wrong. This generator produces complete Kafka record objects with all those fields for five event domains: user.created, order.placed, payment.processed, inventory.updated, and session.started. The Topic Name field populates the topic field in every generated record — enter your actual topic name so the output needs no editing before use in tests. The Event Type selector determines the payload structure. user.created produces a userId, name, email, and createdAt. order.placed outputs an orderId, customerId, totalAmount, currency, itemCount, and placedAt. payment.processed includes a paymentId, orderId, amount, currency, status enum (SUCCESS, FAILED, PENDING), and processedAt. inventory.updated contains productId, SKU, previousStock, newStock, warehouseId, and updatedAt. session.started generates sessionId, userId, IP address, userAgent, and startedAt. Each message also includes realistic headers: content-type, event-type, source-service, and a correlation-id UUID. Partition is a random integer 0–11, and offset is a large random integer simulating a mid-stream position. Paste the output into a Spring Kafka test via TestInputTopic.pipeInput(), into a Kafka Streams TopologyTestDriver, or into kafka-console-producer for replay against a local Docker broker.

Read the complete guide — 4 min read

How to use

  1. Choose your options above
  2. Click Generate
  3. Copy your result

Detailed instructions

  1. Enter your Kafka topic name in the Topic Name field to match your actual topic, e.g. order-service.events.
  2. Select the Event Type that matches the domain you are testing — user.created, order.placed, or payment.processed.
  3. Set the How Many counter to the number of records your test scenario requires, then click Generate.
  4. Copy the generated JSON array and paste it into your unit test, MockConsumer setup, or kafka-console-producer input file.
  5. Adjust individual field values in the copied payload to cover edge cases like null amounts or missing user IDs.

Use Cases

  • Seeding a Kafka Streams TestInputTopic with realistic user.created events inside a JUnit 5 test suite
  • Testing Spring Kafka @KafkaListener offset-commit logic using MockConsumer with generated record batches
  • Creating dead-letter queue handler fixtures by generating payment.processed messages with edge-case field values
  • Demoing Kafka record anatomy — headers, UUID key, partition, offset — during microservices onboarding sessions
  • Replaying order.placed message batches through kafka-console-producer against a local Docker Kafka broker

Tips

  • Match the topic name exactly to your environment's naming convention so generated messages need no editing before use in tests.
  • Generate a batch of 10 or more, then cherry-pick specific records to cover both happy-path and failure scenarios in the same test suite.
  • The message key is a UUID by default — replace it with a fixed value when testing partition-ordered processing to ensure all test records land on the same partition.
  • Copy the headers object into a Spring Kafka MessageHeaders or a Flink KafkaRecordSerializationSchema to test header-aware consumer branches.
  • Combine payment.processed and user.created events in a single test to verify that your consumer correctly routes multiple event types from the same topic.
  • When testing offset-commit logic, edit the offset field in consecutive generated records to be sequential integers starting from a non-zero value, simulating a mid-stream consumer restart.

FAQ

how do I use generated kafka messages in a topologytestdriver test

Copy the generated JSON value field into your test via TestInputTopic.pipeInput(), using the key field as the record key and mapping the headers object to a Kafka Headers instance. No broker is needed — TestInputTopic handles everything in-process. For Spring Kafka, drop the same payload into a MockConsumer or pass the key and value to an EmbeddedKafkaBroker to drive a real @KafkaListener.

are mock kafka messages safe to paste into CI pipelines or share with teammates

Yes. All messages are generated entirely in your browser — no data is sent to any server and no broker is contacted. The payloads are fully synthetic, so there is zero risk of leaking production event data. Commit the JSON output as a static test fixture and reference it in your pipeline like any other resource.

what is the difference between the kafka message key and the partition field

The key is a value you attach to a record — here a UUID — that Kafka's default partitioner hashes to decide which partition receives it. The partition is the broker-assigned integer bucket within the topic. Kafka guarantees ordering only within a single partition, so using a consistent key (like a user or order UUID) ensures all related events land in sequence.

which event types does this generator support

Five event types are available: user.created (userId, name, email, createdAt), order.placed (orderId, customerId, totalAmount, currency, itemCount, placedAt), payment.processed (paymentId, orderId, amount, currency, status, processedAt), inventory.updated (productId, sku, previousStock, newStock, warehouseId, updatedAt), and session.started (sessionId, userId, ip, userAgent, startedAt). Custom event schemas are not supported.

You might also like

Popular tools from other categories that share themes with this one.

Try these next

More free tools from other corners of the catalog, picked by shared themes.