<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Martin Hynar on Medium]]></title>
        <description><![CDATA[Stories by Martin Hynar on Medium]]></description>
        <link>https://medium.com/@martinhynar?source=rss-54ff12967859------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*9JbUSIkcYsWmWUgd.</url>
            <title>Stories by Martin Hynar on Medium</title>
            <link>https://medium.com/@martinhynar?source=rss-54ff12967859------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 03:04:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@martinhynar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[kafkacat usage notes for Fedora]]></title>
            <link>https://martinhynar.medium.com/kafkacat-usage-notes-for-fedora-6ac9e7f476ea?source=rss-54ff12967859------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ac9e7f476ea</guid>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[shell]]></category>
            <category><![CDATA[kafkacat]]></category>
            <dc:creator><![CDATA[Martin Hynar]]></dc:creator>
            <pubDate>Tue, 23 Mar 2021 08:21:57 GMT</pubDate>
            <atom:updated>2021-03-23T08:21:57.324Z</atom:updated>
            <content:encoded><![CDATA[<p>In Kafka’s user toolbox, kafkacat is one one of the frequently used application. Unfortunately, for Fedora users, it is not packaged as rpm, so not available instantly. This is what I do to have it.</p><p>What i really do not, is to compile my own binary. There are few simple steps described on <a href="https://github.com/edenhill/kafkacat#build">kafkacat’s github page</a> but having latest version at my fingertips without need to recompile, that is my preference.</p><h4>My setup</h4><p>I use kafkacat docker image to run all operations, so I have alias defined</p><pre>export KAFKACAT_VERSION=1.6.0<br>export KAFKACAT_IMAGE=edenhill/kafkacat:${KAFKACAT_VERSION}</pre><pre>alias kafkacat=&quot;docker run --rm --network=host ${KAFKACAT_IMAGE} kafkacat $@&quot;</pre><p>This is it, kafkacat executable in shell, no need to compile anything.</p><p>The use of --network=host is necessary to be able to address host as localhost not the container’s inner localhost.</p><p><strong>Frequently used Kafka clusters?</strong></p><p>In addition to the general kafkacat setup above, I usually work with few Kafka clusters.</p><ul><li>local development cluster</li><li>some sandbox or lab (you name it) cluster</li><li>production cluster</li></ul><p>To ease usage, to avoid typos, to save typing, to know where you are working, I define few more aliases based on the general one.</p><pre>alias kafkacat_local=&quot;kafkacat -b localhost:9092 $@&quot;</pre><pre>alias kafkacat_sand=&quot;kafkacat -b kafka-sandbox.domain.com:9092 $@&quot;</pre><pre>alias kafkacat_prod=&quot;kafkacat -b kafka-prod.domain.com:9092 $@&quot;</pre><p>More aliases for frequently used operations is the next optional step.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ac9e7f476ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Strategies for deletion of records in Kafka topic]]></title>
            <link>https://martinhynar.medium.com/strategies-for-deletion-of-records-in-kafka-topic-c13f2fbe0f82?source=rss-54ff12967859------2</link>
            <guid isPermaLink="false">https://medium.com/p/c13f2fbe0f82</guid>
            <category><![CDATA[kafka]]></category>
            <dc:creator><![CDATA[Martin Hynar]]></dc:creator>
            <pubDate>Mon, 22 Mar 2021 20:53:03 GMT</pubDate>
            <atom:updated>2021-03-23T06:59:07.609Z</atom:updated>
            <content:encoded><![CDATA[<p>For whatever reason, the need to delete records in Kafka topic is inevitable. There are few possible ways how to accomplish it based on actual case. Lets review them and discuss when each alternative can be used.</p><h3><strong>Delete then create again</strong></h3><p>The simplest option of all. Delete existing topic and create it again. To delete topic, use</p><pre>kafka-topics \<br>--bootstrap-server localhost:9092 \<br>--topic TOPIC \<br>--delete</pre><p>And now create the topic again with all the settings you desire</p><pre>kafka-topics \<br>--bootstrap-server localhost:9092 \<br>--topic TOPIC \<br>--create \<br>--replication-factor 1 \<br>--partitions 5 \<br>--config retention.ms=60000</pre><p>This is simple, right? But there are conditions that might affect this procedure.</p><ul><li><strong>Is deletion of Kafka topic allowed?</strong></li></ul><p>Depending on configuration of your Kafka cluster, you might be unable to delete topic. This is controlled by delete.topic.enable property that is true by default.</p><ul><li><strong>Are there producers writing into the topic?</strong></li></ul><p>When there are existing producers and you delete topic, the topic will be immediately recreated. The problem is that it will be created with default settings that might be different than what you want.</p><p>If you are unable to stop your producers, and default topic options are not correct for your topic, don’t use this approach. You might end up in undesired state.</p><ul><li><strong>Are there consumers reading from the topic?</strong></li></ul><p>Similar situation is with consumers, topic will be recreated with default topic parameters.</p><p><strong>Summary</strong></p><p>Use this approach when you are able to control your producers and consumers or when automatic re-creation of topic yield topic with desired parameters.</p><h3>Delete all records in topic using retention</h3><p>To delete topic data while not deleting the topic itself you can tweak with topic retention interval. To delete all data in topic, lower the interval to value that is lower than age of all records in topic.</p><pre>kafka-configs \<br>--bootstrap-server localhost:9092 \<br>--topic TOPIC \<br>--alter \<br>--add-config retention.ms=1000</pre><p>The deletion does not occur immediately, retention is a scheduled job that periodically removes obsolete data, so we need to wait. How you know that retention was applied on your topic?</p><ul><li>You shall see relevant log messages in Kafka server log</li></ul><pre>[Log partition=TOPIC-0, dir=/data/kafka/logs] Deleting segments</pre><ul><li>You can check topic’s start and end offsets. You will get list of partitions and respective offsets — when the offset value is equal (start=end) retention took place and records are removed</li></ul><pre># START offset (time = -2)<br>kafka-run-class kafka.tools.GetOffsetShell \<br>--broker-list localhost:9092 \<br>--topic TOPIC \<br>--time -2</pre><pre># END offset  (time = -1)<br>kafka-run-class kafka.tools.GetOffsetShell \<br>--broker-list localhost:9092 \<br>--topic TOPIC \<br>--time -1</pre><p>Now you can reset retention interval back to original value to keep new message persistent.</p><ul><li><strong>Are there producers writing into the topic?</strong></li></ul><p>Topic as such is existing for the whole time of the deletion operation. If you keep you consumers running, all data that will match retention limit will be removed too. If this is OK, the you are good to go.</p><ul><li><strong>Are there consumers reading from the topic?</strong></li></ul><p>Consumers will continue to read from topic as topic exist. Based on when scheduled retention occurs, how fast is consumer with reading records (small records and fast processing vs. large records and slow processing) there could occurs some inconsistencies with record delivery (e.g. consumer is not able to read all topic data before they are removed by retention).</p><p><strong>Summary</strong></p><p>This alternative shall be used when complete removal of topic is not desired or not possible. It can be used while both producers and consumers are running, but possible inconsistencies shall be considered.</p><h4>Specific deletion using kafka-delete-records</h4><p>The most fine-grained record deletion alternative is to use kafka-delete-records command line tool that allows to remove records by defining positions in partitions of the topic. The tool is executed like this.</p><pre>kafka-delete-records \<br>--bootstrap-server localhost:9092 \<br>--offset-json-file specification.json</pre><p>The specification.json file has following format.</p><pre>{<br>  &quot;partitions&quot;: [<br>    {<br>      &quot;topic&quot;: &quot;TOPIC&quot;,<br>      &quot;partition&quot;: 0,<br>      &quot;offset&quot;: OFFSET<br>    }<br>  ],<br>  &quot;version&quot;: 1<br>}</pre><p>Execution of the above command moves partition start offset to OFFSET which effectively means that everything before that offset is deleted. The operation is executed immediately (in contrast to waiting for scheduled retention operation).</p><p>It is possible to remove data only on tail. Deleting in the middle or on head of the topic is not available.</p><p>What is possible, is to remove data only in selected partitions. This means, if you use sophisticated partitioning, you may remove in certain partitions (fulfilling given criteria that assigned it to certain partition) while retaining records in other partitions.</p><ul><li><strong>Are there producers writing into the topic?</strong></li></ul><p>Producers are not influenced by this operation at all as deletion is done on offset relocation basis.</p><ul><li><strong>Are there consumers reading from the topic?</strong></li></ul><p>Consumers might be affected if the offset is reset after actual offset of the consumer. In that case, consumer reading offset is moved to new beginning of the partition and continues with consuming data.</p><p><strong>Summary</strong></p><p>This alternative shall be used in situations where immediate deletion of data is desired or when only parts of topic shall be removed (located in specific partitions). Both producers and consumers can remain running.</p><h3>Conclusion</h3><p>We have seen here 3 strategies to get rid of unwanted records in topic. Each of them can be used in specific situation but none of them allows to delete records that are either in middle of the topic, scattered over all partitions, matching certain criteria. To provide functionality like that, programmatic solution need to be created and records need to be produced to new topic (e.g. Kafka Streams).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c13f2fbe0f82" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick into to Avro in Python and how to make it Pandas DataFrame]]></title>
            <link>https://martinhynar.medium.com/quick-into-to-avro-in-python-and-how-to-make-it-pandas-dataframe-37bd0ae30ac6?source=rss-54ff12967859------2</link>
            <guid isPermaLink="false">https://medium.com/p/37bd0ae30ac6</guid>
            <dc:creator><![CDATA[Martin Hynar]]></dc:creator>
            <pubDate>Fri, 04 Dec 2020 15:15:31 GMT</pubDate>
            <atom:updated>2020-12-04T15:20:20.703Z</atom:updated>
            <content:encoded><![CDATA[<h3>Quick intro to Avro in Python and how to make it Pandas DataFrame</h3><p>This article is to provide quick intro to processing Avro data in Python.</p><p>Avro is widely used binary format for data interchange between systems. Those systems of course can be implemented in various programming languages. Python is widely used programming language and Avro is well supported there.</p><h4>Avro Schema</h4><p>Avro data are always defined by Avro schema. So, before any Avro data can be generated, there must be defined the schema.</p><p>For this post, let use use this simple schema definition that describe population and area of cities for given year.</p><pre>{<br>  &quot;namespace&quot;: &quot;org.example.avro&quot;,<br>  &quot;type&quot;: &quot;record&quot;,<br>  &quot;name&quot;: &quot;City&quot;,<br>  &quot;fields&quot;: [<br>    {&quot;name&quot;: &quot;name&quot;, &quot;type&quot;: &quot;string&quot;},<br>    {&quot;name&quot;: &quot;year&quot;, &quot;type&quot;: &quot;int&quot;},<br>    {&quot;name&quot;: &quot;population&quot;, &quot;type&quot;: &quot;int&quot;},<br>    {&quot;name&quot;: &quot;area&quot;, &quot;type&quot;: &quot;int&quot;}<br>  ]<br>}</pre><p>To give it quick description, we have</p><ul><li>Record <strong>City</strong> in namespace <strong>org.example.avro</strong></li><li>This record has 4 fields (name, year, population and area) and all of them are mandatory.</li></ul><h3>Into the Python</h3><p>To work with Avro, there is official package named — <strong>avro</strong> — that has straightforward API.</p><p><strong>Note:</strong> There were 2 packages — for Python 2 and Python 2 — but they were recently joined to provide support in both versions.</p><h4>Writing Avro</h4><p>Let us start with code that allows to write Avro data</p><pre>from avro.schema import parse<br>from avro.datafile import DataFileWriter<br>from avro.io import DatumWriter<br><br><br>class AvroWriter:<br>    def __init__(self, avro_schema_file, avro_data_file):<br>        self.avro_data_file = avro_data_file<br>        <strong>self.schema = parse(open(avro_schema_file, &quot;rb&quot;).read())<br></strong><br>    def write_sample(self):<br>        with <strong>DataFileWriter(open(self.avro_data_file, &quot;wb&quot;),<br>                            DatumWriter(),<br>                            self.schema) as writer</strong>:<br>            <strong>writer.append</strong>({&#39;name&#39;: &#39;Prague&#39;,<br>                           &quot;year&quot;: 2020,<br>                           &quot;population&quot;: 1324277,<br>                           &quot;area&quot;: 496})<br>            writer.append({&#39;name&#39;: &#39;Berlin&#39;,<br>                           &quot;year&quot;: 2019,<br>                           &quot;population&quot;: 3769495,<br>                           &quot;area&quot;: 891})<br>            writer.append({&#39;name&#39;: &#39;Vienna&#39;,<br>                           &quot;year&quot;: 2018,<br>                           &quot;population&quot;: 1888776,<br>                           &quot;area&quot;: 414})</pre><p>First, we load schema definition from file. If we have syntax error or semantic error in the definition, <strong>parse</strong> method will fail.</p><p>In write_sample() method we use this schema object to write actual data. First there is defined DataFileWritter instance that takes following parameters:</p><ul><li>File handle where Avro data will be stored</li><li>DatumWriter — this is object that knows how to write individual data types in Avro.</li><li>The schema that was parsed earlier</li></ul><p>On calling of <strong>writer.append()</strong>, individual records are written into target file.</p><h4>Reading Avro</h4><p>Similar API is available also for the reading part.</p><pre>class AvroReader:<br>    def __init__(self, data_file):<br>        self.avro_reader = <strong>DataFileReader(open(data_file, &quot;rb&quot;),<br>                                          DatumReader())</strong><br><br>    def print(self):<br>        # There is schema available in meta field<br>        print(&quot;---- SCHEMA ----&quot;)<br>        # Print schema as dict<br>        print(<strong>self.avro_reader.meta</strong>)<br>        # Or load it into json<br>        schema_json = json.loads(self.avro_reader.meta.get(&#39;avro.schema&#39;).decode(&#39;utf-8&#39;))</pre><pre>        print(&#39;Avro schema [{}]: {}.{}&#39;.format(schema_json[&#39;type&#39;], schema_json[&#39;namespace&#39;], schema_json[&#39;name&#39;]))<br><br>        for field in schema_json[&#39;fields&#39;]:<br>            print(&#39;{}:{}&#39;.format(field[&#39;name&#39;], field[&#39;type&#39;]))</pre><pre>        <strong>records = [record for record in self.avro_reader]</strong></pre><pre>        print(&quot;---- AVRO RECORDS ----&quot;)<br>        print(records)<br>        print(&quot;---- PANDAS DATAFRAME ----&quot;)<br>        print(<strong>DataFrame.from_records(records)</strong>)</pre><p>Here, we are opening Avro data file using <strong>DataFileReader</strong> that takes the input file and <strong>DatumReader</strong> as parameters. <strong>DatumReader</strong> is responsible for decoding binary representation into Python types.</p><p>As schema is in this case carried together with data, we have access to the Avro schema as well. It is available in the <strong>meta</strong> field of the reader as dictionary.</p><p>Bellow that, there is example parsing and sniffing of the schema using json library. This gives us possibility to know the internals. The output would be:</p><pre>Avro schema [record]: org.example.avro.City<br>name:string<br>year:int<br>population:int<br>area:int</pre><p>At this point, iterating over the reader object will give us individual records from the Avro file.</p><pre>for record in self.avro_reader:<br>    print(record)</pre><h4>Pandas!</h4><p>It is quite common to process data with great Pandas library. How to make from our Avro data a Pandas DataFrame object. Luckily, the way is this two-liner:</p><pre><strong>records = [record for record in self.avro_reader]</strong><br>df = <strong>DataFrame.from_records(records)</strong></pre><p>What to do next with the data is different story…</p><h4>References</h4><ul><li><a href="https://avro.apache.org/docs/1.10.0/gettingstartedpython.html">Avro Python getting started guide</a></li><li><a href="https://pypi.org/project/avro/">Avro Pypi page</a></li><li><a href="https://avro.apache.org/docs/1.10.0/spec.html">Avro 1.10.0 specification</a></li><li><a href="https://pandas.pydata.org/">Pandas</a></li><li><a href="https://github.com/martinhynar/python-avro-pandas">Complete code from this story</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37bd0ae30ac6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kafka, NiFi, Schema Registry … all in Docker]]></title>
            <link>https://martinhynar.medium.com/kafka-nifi-schema-registry-all-in-docker-9113529b1f99?source=rss-54ff12967859------2</link>
            <guid isPermaLink="false">https://medium.com/p/9113529b1f99</guid>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[schemaregistry]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[nifi]]></category>
            <dc:creator><![CDATA[Martin Hynar]]></dc:creator>
            <pubDate>Wed, 11 Nov 2020 16:21:11 GMT</pubDate>
            <atom:updated>2020-11-11T16:21:11.893Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kafka, NiFi, Schema Registry … all in Docker</h3><p>This is description of setup to get working lab environment with following components:</p><p><strong>Apache Kafka/ Confluent Platform</strong></p><p>Apache Kafka is a distributed streaming platform. You publish data on one end and consume on the other end. Kafka takes care of persistence, replication, retention, …</p><ul><li><a href="https://kafka.apache.org/">Apache Kafka Project</a> — Vanilla open source project under the hood of Apache Organisation</li><li><a href="https://www.confluent.io/">Confluent Platform</a> — Commercial product delivering Apache Kafka with extra tooling. Still provides community version.</li></ul><p><strong>Apache NiFi</strong></p><p>Apache NiFi is platform for distributing and processing data.</p><ul><li><a href="https://nifi.apache.org/">Apache NiFi Project</a></li></ul><p><strong>Confluent Schema Registry</strong></p><p>One of the components in Confluent Platform suite. Schema Registry provides interface for serving versioned data schemes (e.g. AVRO, JSON Schema)</p><ul><li><a href="https://docs.confluent.io/current/schema-registry/index.html">Schema Registry documentation</a></li></ul><p><strong>Confluent Kafka REST</strong></p><p>Component that allows to communicate with Kafka using REST API. Using Kafka REST might be good alternative for simple clients that does not need to implement full-fledged Kafka communication.</p><p><a href="https://docs.confluent.io/current/kafka-rest/index.html">Kafka REST documentation</a></p><p><strong>Apache ZooKeeper</strong></p><p>ZooKeeper is hierarchical key-value store that is used by distributed systems for coordinating and synchronizing their operations.</p><ul><li><a href="https://zookeeper.apache.org/">Apache ZooKeeper Project</a> — Vanilla open source project under the hood of Apache Organisation</li><li><a href="https://www.confluent.io/">Confluent Platform</a> — Commercial product delivering Apache Kafka with extra tooling. Still provides community version.</li></ul><h3>Docker Compose File</h3><p>The source for the Docker Compose is available in <a href="https://github.com/martinhynar/docker-kafka-nifi-schemaregistry"><strong>martinhynar/docker-kafka-nifi-schemaregistry</strong></a>. The GitHub version is the one to use, it may contain fixes or addons that are not reflected in this article.</p><p><strong>Common network</strong></p><p>All components deployed in this docker compose configuration need to talk to each other. For this purpose, use dedicated network definition.</p><pre>networks:<br>  docker-kafka-nifi-schemaregistry:<br>    driver: bridge</pre><p><strong>ZooKeeper</strong></p><p>The essential part in this Docker Compose configuration is ZooKeeper that is used by other services.</p><pre>zookeeper:<br>  image: confluentinc/cp-zookeeper:6.0.0<br>  container_name: zookeeper<br>  environment:<br>    ZOOKEEPER_CLIENT_PORT: 2181<br>    ZOOKEEPER_TICK_TIME: 2000<br>  networks:<br>    - docker-kafka-nifi-schemaregistry</pre><ul><li>Start <strong>zookeeper</strong> service</li><li>Listen on port <strong>2181</strong></li><li>Use image <strong>cp-zookeeper</strong> maintained by Confluent</li></ul><p><strong>Kafka</strong></p><pre>kafka:<br>  image: confluentinc/cp-kafka:6.0.0<br>  container_name: kafka<br>  depends_on:<br>    - zookeeper<br>  networks:<br>    - docker-kafka-nifi-schemaregistry<br>  hostname: kafka<br>  ports:<br>    - 9092:9092<br>  environment:<br>    KAFKA_BROKER_ID: 1<br>    KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181<br><em>    </em>KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092<br>    KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT<br>    KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT<br>    KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1</pre><ul><li>Start <strong>kafka</strong> service</li><li>Use image <strong>cp-kafka</strong> maintained by Confluent</li><li>Publish port <strong>9092</strong> outside of the docker environment</li><li>Service <strong>kafka</strong> is dependent on <strong>zookeeper</strong> service. Service <strong>kafka</strong> connects to <strong>zookeeper:2081</strong>.</li><li>Service <strong>kafka</strong> listens also on port <strong>29092</strong>. This port is used by other components in this docker container configuration. It is not published outside.</li><li>The is no authentication of transport security enabled.</li></ul><p><strong>Schema Registry</strong></p><pre>schema-registry:<br>  image: confluentinc/cp-schema-registry:6.0.0<br>  container_name: schema-registry<br>  depends_on:<br>    - kafka<br>  networks:<br>    - docker-kafka-nifi-schemaregistry<br>  hostname: schema-registry<br>  ports:<br>    - 8085:8085<br>  environment:<br>    SCHEMA_REGISTRY_HOST_NAME: schema-registry<br>    SCHEMA_REGISTRY_LISTENERS: http://0.0.0.0:8085<br>    SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: kafka:29092</pre><ul><li>Start <strong>schema-registry</strong> service</li><li>Use image <strong>cp-schema-registry</strong> maintained by Confluent</li><li>Publish port <strong>8085</strong> outside of the docker environment. This port can be used to control maintained schemes from outside (e.g. in browser).</li><li>Service <strong>schema-registry</strong> is dependent on <strong>kafka</strong> service. Service <strong>schema-registry</strong> connects to <strong>kafka:29092</strong>. Schema Registry uses Kafka as persistent store for schemes it maintains.</li><li>The is no authentication of transport security enabled.</li></ul><p><strong>Kafka REST</strong></p><pre>rest-proxy:<br>  image: confluentinc/cp-kafka-rest:6.0.0<br>  container_name: rest-proxy<br>  depends_on:<br>    - kafka<br>    - schema-registry<br>  networks:<br>    - docker-kafka-nifi-schemaregistry<br>  hostname: rest-proxy<br>  ports:<br>    - 8082:8082<br>  environment:<br>    KAFKA_REST_HOST_NAME: rest-proxy<br>    KAFKA_REST_LISTENERS: &quot;http://0.0.0.0:8082&quot;<br>    KAFKA_REST_SCHEMA_REGISTRY_URL: schema-registry:8085<br>    KAFKA_REST_BOOTSTRAP_SERVERS: kafka:29092<br>    KAFKA_REST_SECURITY_PROTOCOL: &quot;PLAINTEXT&quot;<br>    KAFKA_REST_CLIENT_SECURITY_PROTOCOL: &quot;PLAINTEXT&quot;</pre><ul><li>Start <strong>rest-proxy</strong> service</li><li>Use image <strong>cp-kafka-rest</strong> maintained by Confluent</li><li>Publish port <strong>8082</strong> outside of the docker environment. This port can be used to publish or consume messages from Kafka using HTTP.</li><li>Service <strong>rest-proxy</strong> is dependent on <strong>kafka</strong> service. Service <strong>rest-proxy</strong> connects to <strong>kafka:29092</strong>. Kafka REST provides HTTP Proxy when communicating with Kafka.</li><li>Service <strong>rest-proxy</strong> is dependent on <strong>schema-registry</strong> service. Service <strong>rest-proxy</strong> connects to <strong>schema-registry:8085</strong>. Kafka REST uses Schema Registry when working with messages that reference schema (e.g. AVRO) maintained by Schema Registry.</li><li>The is no authentication of transport security enabled.</li></ul><p><strong>NiFi</strong></p><pre>nifi:<br>  image: apache/nifi:latest<br>  container_name: nifi<br>  depends_on:<br>    - zookeeper<br>    - kafka<br>    - schema-registry<br>  networks:<br>    - docker-kafka-nifi-schemaregistry<br>  hostname: nifi<br>  ports:<br>    - 8080:8080<br>  environment:<br>    - NIFI_WEB_HTTP_PORT=8080<br>    - NIFI_CLUSTER_IS_NODE=true<br>    - NIFI_CLUSTER_NODE_PROTOCOL_PORT=8082<br>    - NIFI_ZK_CONNECT_STRING=zookeeper:2181<br>    - NIFI_ELECTION_MAX_WAIT=1 min</pre><ul><li>Start <strong>nifi</strong> service</li><li>Use image <strong>apache/nifi</strong> maintained by Apache Software Foundation.</li><li>Publish port <strong>8080</strong> outside of the docker environment. This port can be used to access NiFi user interface.</li><li>Service <strong>nifi</strong> is dependent on <strong>zookeeper</strong> service. Service <strong>kafka</strong> connects to <strong>zookeeper:2081</strong>. This is direct dependency NiFi needs to start correctly</li><li>Service <strong>nifi</strong> is dependent on <strong>kafka</strong> and <strong>schema-registry</strong> services. These are indirect dependencies, only to make sure that these services are running to be usable by NiFi processors in user defined flows.</li><li>The is no authentication of transport security enabled.</li></ul><h3><strong>Running Docker Compose</strong></h3><p>By running this Docker Compose configuration, the described services will be started. After all services are up and running, there will be several ports available to be used outside of the docker environment.</p><p><strong>Kafka — port 9092</strong></p><p>You can connect your clients running on host system to port 9092 and communicate with Kafka.</p><p><strong>Kafka REST — port 8082</strong></p><p>Instead of directly connecting to Kafka, use HTTP Proxy provided by Kafka REST. Consult full set of operations in <a href="https://docs.confluent.io/current/kafka-rest/api.html">Kafka REST API documentation</a>.</p><p>To list existing topics: <a href="http://localhost:8082/topics">http://localhost:8082/topics</a></p><p><strong>Schema Registry — port 8085</strong></p><p>Manage schemes in Schema Registry using REST API operations. Complete list of operations is available in <a href="https://docs.confluent.io/current/schema-registry/develop/api.html">Schema Registry API documentation</a>.</p><p>To list existing subjects: <a href="http://localhost:8085/subjects">http://localhost:8085/subjects</a></p><p><strong>NiFi — port 8080</strong></p><p>Use this to access NiFi user interface and start with definition of your data flows.</p><p>Open NiFi user interface: <a href="http://localhost:8080/nifi">http://localhost:8080/nifi</a></p><h3>Summary</h3><p>Docker Compose configuration described in this article will set up environment with components that will allow you to start play with definition of NiFi data flows while being able to consume data from Kafka topics and produce them back to Kafka.</p><p>The configuration is easily extensible with other services — e.g. ElasticSearch — to be able to load and store data from and to more data repositories.</p><p>In some other posts, I will show what practical use cases can be solved using this setup.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9113529b1f99" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beware the space in version of your Clojure project under Leiningen]]></title>
            <link>https://martinhynar.medium.com/beware-the-space-in-version-of-your-clojure-project-under-leiningen-7fa672e7adf8?source=rss-54ff12967859------2</link>
            <guid isPermaLink="false">https://medium.com/p/7fa672e7adf8</guid>
            <category><![CDATA[leiningen]]></category>
            <category><![CDATA[clojure]]></category>
            <dc:creator><![CDATA[Martin Hynar]]></dc:creator>
            <pubDate>Fri, 07 Oct 2016 12:13:18 GMT</pubDate>
            <atom:updated>2016-10-07T12:13:18.498Z</atom:updated>
            <content:encoded><![CDATA[<p>Using Clojure? Yes. Building with Leinigen? Yes.</p><p>Good. When changing version in project.clj, make sure you don’t put accidental <strong>space</strong> in there …</p><pre>(<strong>defproject </strong>example/example &quot;0.1.2 &quot; ...</pre><p>If it is there, deploying the final jar to Nexus repository (maybe other repositories too)will fail with this error…</p><pre>java.lang.IllegalArgumentException: Bad artifact coordinates example:example:pom:0.1.2 , expected format is &lt;groupId&gt;:&lt;artifactId&gt;[<em>:&lt;extension&gt;</em>[<em>:&lt;classifier&gt;</em>]]<em>:&lt;version&gt;</em></pre><p>In the exception message, it is not immediately apparent, but there is extra space here <strong>‘0.1.2 ,’</strong>. Remove the space in version definition and you are good to go again.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7fa672e7adf8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stalled SCP transfer? Switch to RSYNC]]></title>
            <link>https://martinhynar.medium.com/stalled-scp-transfer-switch-to-rsync-9ed4317b457f?source=rss-54ff12967859------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ed4317b457f</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[rsync]]></category>
            <category><![CDATA[scp]]></category>
            <category><![CDATA[ssh]]></category>
            <dc:creator><![CDATA[Martin Hynar]]></dc:creator>
            <pubDate>Wed, 31 Aug 2016 08:47:11 GMT</pubDate>
            <atom:updated>2016-08-31T08:47:11.371Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>Having unstable ssh connection to server from which you want to download some larger data file? Ending up in this state, nothing is moving on?</p><pre>$ scp -C user@server:/path/to/bigfile .<br>bigfile    14% 40MB 24.0KB/s - stalled -</pre><p>There is quick and simple replacement that enables for restarting there transfer where it left off. The replacement is called <strong>rsync</strong></p><pre>rsync --rsh=&#39;ssh&#39; -v --archive --progress --partial user@server:/path/to/bigfile .</pre><p>If now the transfer stales, stop it and restart. The <strong>rsync</strong> command will continue transferring data from last ending position.</p><p>Note that <em>rsh</em> option (which remote shell to use) could contain more information, e.g.</p><pre>rsync --rsh=&#39;ssh -i /path/to/identity_file -o ConnectTimeout=30&#39; ...</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ed4317b457f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setup instantly local SMTP or HTTP server for debugging. Python to the rescue.]]></title>
            <link>https://martinhynar.medium.com/setup-instantly-local-smtp-or-http-server-for-debugging-python-to-the-rescue-edb9e32601e?source=rss-54ff12967859------2</link>
            <guid isPermaLink="false">https://medium.com/p/edb9e32601e</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[smtp]]></category>
            <category><![CDATA[https]]></category>
            <category><![CDATA[shell]]></category>
            <dc:creator><![CDATA[Martin Hynar]]></dc:creator>
            <pubDate>Wed, 27 Apr 2016 00:00:00 GMT</pubDate>
            <atom:updated>2017-03-30T09:48:42.432Z</atom:updated>
            <content:encoded><![CDATA[<p>Ever needed quickly setup HTTP or SMTP server for quick debugging of your application? Python is saving you, it has that prepared.</p><h3>HTTP server</h3><p>The following command will serve contents of the folder where it is executed.</p><p>python -m SimpleHTTPServer</p><h3>SMTP Server</h3><p>To start SMTP server on default port 25, you need sudo privileges, because 25 is reserved port in &lt;0, 1024&gt; range. Running following command will start SMTP process under nobody user.</p><p>sudo python -m smtpd -c DebuggingServer localhost:25</p><p>If you cannot get sudo privilege, you need to change listening port to something &gt;1024. Still, process ownership is changed to nobody, so if you run this on non-unix system, you need to avoid it. This command will run SMTP server as current user on port 1025.</p><p>sudo python -m smtpd -c DebuggingServer -n localhost:1025</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edb9e32601e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>