<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Yushin Kim</title>
    <description>The latest articles on DEV Community by Yushin Kim (@yuus95).</description>
    <link>https://dev.to/yuus95</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4129050%2Fd982bfae-4db8-4df8-b2c4-b94eefa726dd.jpg</url>
      <title>DEV Community: Yushin Kim</title>
      <link>https://dev.to/yuus95</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yuus95"/>
    <language>en</language>
    <item>
      <title>Put a test message on a Kafka topic without writing a producer first</title>
      <dc:creator>Yushin Kim</dc:creator>
      <pubDate>Wed, 11 Nov 2026 03:21:06 +0000</pubDate>
      <link>https://dev.to/yuus95/put-a-test-message-on-a-kafka-topic-without-writing-a-producer-first-2je1</link>
      <guid>https://dev.to/yuus95/put-a-test-message-on-a-kafka-topic-without-writing-a-producer-first-2je1</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. One message with kcat
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/edenhill/kcat" rel="noopener noreferrer"&gt;kcat&lt;/a&gt; reads from stdin and produces to a topic. &lt;code&gt;-K:&lt;/code&gt; tells it the key and value are separated by a colon, and &lt;code&gt;-H&lt;/code&gt; adds a header.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'user_1001:{"eventId":"evt_001","userId":"user_1001","status":"ACTIVE"}'&lt;/span&gt; \
  &lt;span class="o"&gt;|&lt;/span&gt; kcat -b localhost:9092 -t user.events -P -K: \
      -H &lt;span class="s2"&gt;"eventType=USER_CREATED"&lt;/span&gt; -H &lt;span class="s2"&gt;"version=v1"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two things trip people up:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The delimiter splits at its first occurrence.&lt;/strong&gt; With &lt;code&gt;-K:&lt;/code&gt; a key such as &lt;code&gt;user:1001&lt;/code&gt; is cut at the first colon. Pick a delimiter that cannot appear in the key, for example &lt;code&gt;-K'|'&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Quote the JSON with single quotes&lt;/strong&gt; so the shell leaves the double quotes alone.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Several messages from a file
&lt;/h2&gt;

&lt;p&gt;Put one &lt;code&gt;key:value&lt;/code&gt; pair per line and pass the file with &lt;code&gt;-l&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kcat -b localhost:9092 -t user.events -P -K: -l messages.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Messages with the same key go to the same partition, so if your consumer depends on per-key ordering, reuse a key across lines to test it.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. From Java, when headers and types matter
&lt;/h2&gt;

&lt;p&gt;When the consumer reads headers or you want the same serializer as production, a &lt;code&gt;ProducerRecord&lt;/code&gt; is the honest test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;ProducerRecord&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;record&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ProducerRecord&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s2"&gt;"user.events"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"user_1001"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;objectMapper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writeValueAsString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"eventType"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"USER_CREATED"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;StandardCharsets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;UTF_8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"v1"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;StandardCharsets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;UTF_8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;producer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;record&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Header values are bytes. If the consumer decodes them with a different charset than the producer used, the header looks corrupted, so state UTF-8 on both sides.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check what landed
&lt;/h2&gt;

&lt;p&gt;Read the last message of each partition back, including key and headers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kcat -b localhost:9092 -t user.events -C -o -1 -e \
  -f &lt;span class="s1"&gt;'key=%k headers=%h value=%s\n'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the key is empty here, the &lt;code&gt;-K&lt;/code&gt; delimiter did not match when you produced.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting a payload that matches the schema
&lt;/h2&gt;

&lt;p&gt;The slow part is usually not the command but writing JSON that satisfies the schema: every required field, the right types, the nested records. I built a small browser tool for that step. You paste an Avro schema or a JSON Schema, set the topic, key field and headers, and it returns a matching sample payload, the full message, a &lt;code&gt;ProducerRecord&lt;/code&gt; snippet and a kcat command:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://json2class.com/en/kafka-message-generator/" rel="noopener noreferrer"&gt;Kafka message generator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://json2class.com/en/avro-schema-generator/" rel="noopener noreferrer"&gt;Avro schema generator&lt;/a&gt; if you only have a sample JSON message and need the schema first&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The values are fixed placeholders based on field type and name, not random data, and it makes up to 20 messages per run. That is enough to check that a consumer parses the message; it is not a load generator. Everything runs in the browser and the schema is not uploaded.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Need&lt;/th&gt;
&lt;th&gt;Use&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;One message, right now&lt;/td&gt;
&lt;td&gt;`echo ... \&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A batch, or ordering per key&lt;/td&gt;
&lt;td&gt;{% raw %}&lt;code&gt;kcat -P -K: -l file&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Headers and production serializers&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;ProducerRecord&lt;/code&gt; in a test&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Confirm key, headers and value&lt;/td&gt;
&lt;td&gt;&lt;code&gt;kcat -C -o -1 -e -f ...&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>kafka</category>
      <category>testing</category>
      <category>tutorial</category>
      <category>java</category>
    </item>
  </channel>
</rss>
