The Jackdaw Streams API is a thin wrapper around the Kafka Streams DSL. It lets you define streaming applications with idiomatic Clojure functions in place of the Java interop.
Kafka Streams can be a good choice if all of these conditions are true:
For a simple transformation, consider SMT Transforms with Kafka Connect.
If you've used the Java API, you'll be aware that the core operators are defined
as methods on the KStream and KTable classes. In Jackdaw, we expose these
methods as functions in the jackdaw.streams namespace with names that are
hyphenated versions of the corresponding Java method.
The API docs should be consulted for full details but the essential elements of a typical streams app are described below
(def topic-metadata
{:input
{:topic-name "input"
:partition-count 1
:replication-factor 1
:key-serde (jackdaw.serdes.edn/serde)
:value-serde (jackdaw.serdes.edn/serde)}
:output
{:topic-name "output"
:partition-count 1
:replication-factor 1
:key-serde (jackdaw.serdes.edn/serde)
:value-serde (jackdaw.serdes.edn/serde)}})
(ns my.example.word-count
(:require
[clojure.string :as str]
[jackdaw.streams :as j]))
(defn split-lines
[input-string]
(str/split (str/lower-case input-string) #"\W+"))
(defn topology-builder
[topic-metadata]
(fn [builder]
(let [text-input (j/kstream builder (:input topic-metadata))
counts (-> text-input
(j/flat-map-values split-lines)
(j/group-by (fn [[_ v]] v))
(j/count))]
(-> counts
(j/to-kstream)
(j/to (:output topic-metadata)))
builder)))
(defn -main
[& args]
(let [app-config (parse-args args)
builder (j/streams-builder)
topology ((topology-builder topic-metadata) builder)
app (j/kafka-streams topology app-config)]
(j/start app)
app))
Can you improve this documentation? These fine people already did:
Savyasachi, Andrea Crotti, Alex Popov & Charles ReeseEdit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |