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, Real-Time Data

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.

Related Blog Posts
Natively Compiled Java on Google App Engine
Google App Engine is a platform-as-a-service product that is marketed as a way to get your applications into the cloud without necessarily knowing all of the infrastructure bits and pieces to do so. Google App […]
Building Better Data Visualization Experiences: Part 2 of 2
If you don't have a Ph.D. in data science, the raw data might be difficult to comprehend. This is where data visualization comes in.
Unleashing Feature Flags onto Kafka Consumers
Feature flags are a tool to strategically enable or disable functionality at runtime. They are often used to drive different user experiences but can also be useful in real-time data systems. In this post, we’ll […]
A security model for developers
Software security is more important than ever, but developing secure applications is more confusing than ever. TLS, mTLS, RBAC, SAML, OAUTH, OWASP, GDPR, SASL, RSA, JWT, cookie, attack vector, DDoS, firewall, VPN, security groups, exploit, […]