{
  "id": 19436196,
  "title": "Put a test message on a Kafka topic without writing a producer first",
  "url": "https://urgent.news/2026/11/11/put-a-test-message-on-a-kafka-topic-without-writing-a-producer-first",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-11T03:21:06.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/yuus95/put-a-test-message-on-a-kafka-topic-without-writing-a-producer-first-2je1"
  },
  "original_language": "en",
  "account": "Producing a test message to a Kafka topic without creating a producer application entails employing a few methods, ranging from the quickest to the most accurate. These techniques enable you to swiftly validate a consumer's ability to handle a message without the complexity of a full producer setup.\n\nThe first approach utilizes the `kcat` command-line tool, which reads from the standard input and forwards data to a Kafka topic. By specifying options such as `K` to define the delimiter separating the key and value, and `H` to include headers, one can craft a message. The command example provided utilizes `echo` to generate a sample message with a key, JSON payload, and custom headers. However, the primary caution noted is the delimiter's role; it splits the input at the first colon, so selecting a delimiter that is unlikely to appear within the key is crucial.\n\nFor generating multiple messages, one can draft a text file where each line contains a key-value pair separated by a colon. Executing `kcat` with the `-l` option allows the tool to read the file line by line, thereby distributing messages across Kafka partitions based on key values. This method proves useful when a consumer's logic depends on messages being processed in a specific order within a partition, as messages with identical keys are routed to the same partition.\n\nIn scenarios where the consumer necessitates headers or the same serialization as the production environment, the third method involves crafting a `ProducerRecord` in Java. This involves initializing a `ProducerRecord` with the topic and key, serializing the payload using an object mapper, and then adding headers as byte arrays. It is essential to ensure that the character encoding used for headers matches that of the consumer to avoid any decoding issues. This approach offers a more authentic test, particularly when headers and serialization are integral to the consumer's operation.\n\nTo verify that the message has been successfully produced and received, the `kcat` tool can be employed again in a different configuration. By specifying options that include reading the last message from each partition (`-C -o -1 -e`) and formatting the output to display key, headers, and value, you can confirm the presence of the generated message. Crucially, the key should match what was produced, indicating that the delimiter used in the message creation aligns correctly. This final step validates the complete flow from message generation to confirmation, ensuring the integrity of the testing process.",
  "summary": "You wrote a consumer and want to see it handle one message. Writing a throwaway producer app for that is slow. Here are three ways to do it, from fastest to most realistic. 1. One message with kcat kcat reads from stdin and produces to a topic. -K: tells it the key and value are separated by a colon, and -H adds a header. echo…",
  "key_points": [
    "Use kcat command-line tool to send test message to Kafka topic.",
    "Craft message with echo command, specifying key, JSON payload, headers.",
    "Employ kcat with -l option to generate multiple messages from file."
  ],
  "editors_take": "Using command-line tools or manual record crafting bypasses the overhead of full application development, allowing engineers to isolate and validate consumer logic through rapid, targeted message injection.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}