Getting started

Dependency

// Add xkafka to your build; %%% picks the artifact for your platform
libraryDependencies += "io.github.pmbmegalom" %%% "xkafka-client" % "0.7.1"

The same code compiles for the JVM, Scala.js and Scala Native, and each runs on its platform's Kafka client.

Modules

Most applications need xkafka-client only. The other modules are:

Versioning

xkafka follows early semantic versioning.

Within a series, upgrades keep binary compatibility. Code built against 0.1.0 runs against 0.1.1 without recompiling.

Across a series, upgrades may break compatibility, in both binary and source form. Going from 0.1.x to 0.2.0 can mean recompiling, and changing code.

After 1.0.0, that boundary moves to the major version, and every 1.x.y will stay binary compatible with 1.0.0.

While the major version is 0, expect the API to change between series.

If another dependency brings in a version across one of these boundaries, sbt warns about it.

Constructing a client

// Construct the client, in the same way on every platform
import cats.effect.IO

import xkafka.*

val client = KafkaClient[IO]

What each platform needs at run time is described below. Once your project builds, Producing and Consuming show how to write and read records, and Settings covers what you can configure.

JVM

Nothing else is needed. xkafka brings in the Apache Kafka Java client, and runs on Java 17 or newer.

Scala.js

On Scala.js, xkafka runs on Node.js 24, not in browsers. It uses librdkafka from the npm package @xkafka/librdkafka, which ships a prebuilt library for each platform it supports, so you install nothing else. The sbt-scalajs-bundler plugin installs the package. Add it, and enable it in your Scala.js project:

// In project/plugins.sbt: add the plugin that installs the npm package
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.21.1")
// In build.sbt: enable that plugin for the Scala.js side of a cross project
.jsConfigure(_.enablePlugins(ScalaJSBundlerPlugin))

In a project that builds for Scala.js only, call .enablePlugins(ScalaJSBundlerPlugin) on it instead. See Platform notes for the packages npm installs.

Scala Native

On Scala Native, xkafka links librdkafka 2.16.0. Install it where your compiler and linker can find it. Platform notes gives the linking recipes, including the flags a static link needs.