{"id":9575,"date":"2022-10-31T18:42:00","date_gmt":"2022-10-31T23:42:00","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=9575"},"modified":"2022-11-01T12:55:19","modified_gmt":"2022-11-01T17:55:19","slug":"kafka-messages-not-appearing-in-topic","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=9575","title":{"rendered":"Kafka &#8211; Messages Not Appearing in Topic"},"content":{"rendered":"\n<p>I created a few new Kafka topics for a project today &#8212; but, in testing, messages sent to the topic weren&#8217;t there. I normally echo some string into &#8220;kafka-console-producer.sh&#8221; to test messages. Evidently, STDERR wasn&#8217;t getting rendered back to my screen this way. I ran the producer script to get the &#8220;>&#8221; prompt and tried again &#8212; voila, a useful error:<\/p>\n\n\n\n<p>[2022-10-31 15:36:23,471] ERROR Error when sending message to topic MyTopic with key: null, value: 4 bytes with error: (org.apache.kafka.clients.pro.internals.ErrorLoggingCallback)<br>org.apache.kafka.common.InvalidRecordException: Compacted topic cannot accept message without key in topic partition MyTopic-0.<\/p>\n\n\n\n<p>Ohhh &#8212; that makes sense! They&#8217;ve got an existing process on a different Kafka server, and I just mirrored the configuration without researching <em>what<\/em> the configuration meant. They use &#8220;compact&#8221; as their cleanup policy &#8212; so messages don&#8217;t really <em>age out<\/em> of the topic. They age out <em>when a newer message with that key gets posted<\/em>. It&#8217;s a neat algorithm that I remember encountering when I first started reading the Kafka documentation &#8230; but it&#8217;s <em>not<\/em> something I had a reason to use. The other data we have transiting our Kafka cluster is time-series data where we want <em>all<\/em> of the info for trending. Having just the most recent, say, CPU utilization on my server isn&#8217;t terribly useful. But it makes sense &#8212; if I instruct the topic to clean up old data <em>but<\/em> retain the most recent message for each key &#8230; I need to be giving it a key!<\/p>\n\n\n\n<p>Adding a parameter to parse the string into a key\/value pair and provide the separator led to data being published to the clients:<\/p>\n\n\n\n<p>echo &#8220;test:EchoTest&#8221; | \/kafka\/bin\/kafka-console-producer.sh &#8211;bootstrap-server $(hostname):9092 &#8211;topic MyTopic &#8211;property &#8220;parse.key=true&#8221; &#8211;property &#8220;key.separator=:&#8221;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I created a few new Kafka topics for a project today &#8212; but, in testing, messages sent to the topic weren&#8217;t there. I normally echo some string into &#8220;kafka-console-producer.sh&#8221; to test messages. Evidently, STDERR wasn&#8217;t getting rendered back to my screen this way. I ran the producer script to get the &#8220;>&#8221; prompt and tried &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1762],"tags":[1361],"class_list":["post-9575","post","type-post","status-publish","format-standard","hentry","category-kafka","tag-kafka"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/9575","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9575"}],"version-history":[{"count":1,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/9575\/revisions"}],"predecessor-version":[{"id":9576,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/9575\/revisions\/9576"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}