Aug 14, 2018

3 Kotlin Features to Improve Your Kafka Connect Development

Kafka Connect is the hub that connects your Kafka cluster to any other system. The framework aims to make it easy to pull data into Kafka as well as copy data out of Kafka. As mentioned in a previous post on building a Kafka Connector with Gradle, there are a variety of open source connectors available for use but there are still use cases that will require the development of a custom connector.

If you find yourself starting from scratch, here are a few reasons to consider Kotlin as your language of choice.

1) Eliminate Boilerplate Code with Data Classes

Kafka connectors have a relatively simple task. They either fetch data from a source and push it to Kafka (source connector) or pull data from Kafka and sync it to a system (sink connector).

Both types of connectors require a fair amount of mapping data to and from domain models. Kotlin’s data classes provide a streamlined way of defining objects and leaving out the boilerplate code traditionally found in POJOs. Data classes also provide ways to copy and destructure objects should the need arise.

Here’s a comparison of a data class and a traditional POJO (that doesn’t include all of the properties/functionality that the data class has).

2) Cleanup Struct Conversion with Extension Methods

Many times the data source you want to interact with has a library you can use to jumpstart development. In this case, you won’t have control over the domain models and end up writing a variety of helper functions to convert the models to and from the Struct objects that Kafka expects so that Avro and the Schema Registry can be used.

Kotlin’s extension methods provide a nice way to tack on functionality to a class and keep your code clear of helper clutter.

Here’s an example of adding a toStruct method to a model pulled in from a 3rd party library.

3) Java Interoperability

Java is the dominant language in the Kafka space so being able to pull in Java libraries or experiment with Kotlin in a Java project is one of the most powerful features that Kotlin offers. If you are trying to introduce Kotlin to your team, there is no problem bringing it in one class at a time so that you can show off some of the other features that Kotlin users love.


Disclaimer: Once you start writing Kotlin you may start to notice more and more .kt files appearing in your project.

About the Author

Matt Schroeder profile.

Matt Schroeder

Director, Modern API

A wide range of professional experience and a Master’s Degree in Software Engineering have become the foundation that enables Matt to lead teams to the best solution for every problem.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Blog Posts
Performance Test Liquibase Update
When doing a liquibase update to a database if you’re having performance issues, it can be hard to find out which updates are causing problems. If you need to measure the time to apply each […]
TICK Stack Monitoring for the Non-Technical
TICK – Telegraf, Influx, Chronograf, and Kapacitor – is a method of monitoring your systems and applications. In this article, I discuss in non-technical terms what the difference is between TICK and Prometheus Grafana A […]
Design Systems, Part 1 • Introduction
Business leaders need a practical guide to plan and execute Design System Initiatives. The aim of this series is to be that guide. This installment introduces terms and definitions as a primer on Design Systems.
ML for Translating Dysarthria Speech (Pre-Part 1)
What is Dysarthria? Per the Mayo Clinic, Dysarthria occurs when the muscles you use for speech are weak or you have difficulty controlling them. Dysarthria often causes slurred or slow speech that can be difficult […]