Skip to content

Commit c1d55d9

Browse files
committed
store updated project
1 parent f5482a5 commit c1d55d9

File tree

6 files changed

+76
-83
lines changed

6 files changed

+76
-83
lines changed

README.adoc

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ A Clojure library for the Apache Kafka (distributed stream-processing software p
44

55
Uses KF protocol and does not rely on ZooKeeper.
66

7-
NOTE: Still contains zookeeper as a dependency.
8-
97
Tries to be as lightweigh as possible thus depends only on
108

11-
- `org.apache.kafka/kafka_2.12 "3.4.0"`
12-
- `org.apache.kafka/kafka-clients "3.4.0"`
13-
- `org.apache.zookeeper/zookeeper "3.8.1"`
9+
- `org.apache.kafka/kafka_2.12 "3.9.0"`
10+
- `org.apache.kafka/kafka-clients "4.0.0"`
11+
12+
but excluding `jmx*` and logging.
1413

15-
but excluding `jms`,`jmx*` and logging.
14+
NOTE: The Zookeeper dependency has been removed as it's not required by modern Kafka clients for standard operations.
1615

1716
NOTE: Some builds (for instance of `v0.4.x` branch) may partially (sometimes even fully) be incompatible with some versions of other libraries that also use NIO! If you’re experiencing build problems and/or your application is unexpectedly crashed on start - try check your project dependencies more deeply, may be you will need to correct existing dependencies version or to add an actual version of full `[io.netty/netty-all]`
1817

@@ -31,12 +30,12 @@ image:https://img.shields.io/github/last-commit/source-c/clj-kafka-x?style=for-t
3130

3231
Add the following to your http://github.com/technomancy/leiningen[Leiningen's]
3332
`project.clj`:
34-
33+
3534
[source,clojure]
3635
----
37-
[net.tbt-post/clj-kafka-x "0.7.5"]
36+
[net.tbt-post/clj-kafka-x "0.8.0"]
3837
----
39-
38+
4039
== Usage
4140

4241
=== Producer
@@ -124,7 +123,7 @@ $ lein install
124123

125124
== License
126125

127-
Copyright © 2016-2023
126+
Copyright © 2016-2025
128127

129128
Distributed under the
130129
http://www.apache.org/licenses/LICENSE-2.0[Apache License v 2.0]

profiles.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
{:dev {:dependencies [[midje "1.10.9"]]}
1+
{:dev {:dependencies [[midje "1.10.10"]]}
22
:docs {:plugins [[lein-codox "0.10.8"]
33
[org.timmc/nephila "0.3.0"]]}
4-
:provided {:dependencies [[org.clojure/clojure "1.11.1"]]}
4+
:provided {:dependencies [[org.clojure/clojure "1.12.0"]]}
55
:jar {:aot :all}}

project.clj

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
(defproject net.tbt-post/clj-kafka-x "0.7.6"
1+
(defproject net.tbt-post/clj-kafka-x "0.8.0"
22
:description "A Clojure wrapper for Apache Kafka v2/v3 client"
33
:url "https://github.com/source-c/clj-kafka-x"
44
:license {:name "Apache License 2.0"
55
:url "http://www.apache.org/licenses/LICENSE-2.0"}
6-
:dependencies [[org.apache.kafka/kafka_2.12 "3.5.0"
7-
:exclusions [javax.jms/jms
8-
com.sun.jdmk/jmxtools
6+
:dependencies [[org.apache.kafka/kafka_2.12 "3.9.0"
7+
:exclusions [com.sun.jdmk/jmxtools
98
com.sun.jmx/jmxri
109
org.slf4j/slf4j-log4j12]]
11-
[org.apache.zookeeper/zookeeper "3.8.1"
12-
:exclusions [org.slf4j/slf4j-log4j12]]
13-
[org.apache.kafka/kafka-clients "3.5.0"]])
10+
[org.apache.kafka/kafka-clients "4.0.0"]])

src/clj_kafka_x/consumers/simple.clj

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(ns ^{:doc "Clojure interface for Kafka Consumer API.
22
For complete JavaDocs, see:
3-
https://kafka.apache.org/34/javadoc/org/apache/kafka/clients/consumer/package-summary.html"}
3+
https://kafka.apache.org/40/javadoc/org/apache/kafka/clients/consumer/package-summary.html"}
44
clj-kafka-x.consumers.simple
55
(:require [clj-kafka-x.data :refer :all]
66
[clj-kafka-x.impl.helpers :refer :all])
@@ -20,12 +20,12 @@
2020
"Takes a map of config options and returns a `KafkaConsumer` for consuming records from Kafka.
2121
2222
NOTE `KafkaConsumer` instances are NOT thread-safe, see
23-
https://kafka.apache.org/34/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#multithreaded
24-
23+
https://kafka.apache.org/40/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#multithreaded
24+
2525
For more information and available config options,
26-
see: https://kafka.apache.org/34/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html
26+
see: https://kafka.apache.org/40/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html
2727
http://kafka.apache.org/documentation.html#newconsumerconfigs
28-
28+
2929
Usage:
3030
3131
;; Created using just a map of configs, in this case the keys
@@ -88,12 +88,12 @@
8888
{:topic \"topic-b\" :partitions #{0 1}}
8989
{:topic \"topic-c\" :partitions #{0}}])
9090
;; => nil
91-
91+
9292
For more in-depth information
93-
https://kafka.apache.org/34/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#subscribe(java.util.Collection)
94-
http://kafka.apache.org/34/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#subscribe(java.util.Collection,%20org.apache.kafka.clients.consumer.ConsumerRebalanceListener)
95-
http://kafka.apache.org/34/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#subscribe(java.util.regex.Pattern,%20org.apache.kafka.clients.consumer.ConsumerRebalanceListener)
96-
https://kafka.apache.org/34/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#assign(java.util.Collection)
93+
https://kafka.apache.org/40/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#subscribe(java.util.Collection)
94+
http://kafka.apache.org/40/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#subscribe(java.util.Collection,%20org.apache.kafka.clients.consumer.ConsumerRebalanceListener)
95+
http://kafka.apache.org/40/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#subscribe(java.util.regex.Pattern,%20org.apache.kafka.clients.consumer.ConsumerRebalanceListener)
96+
https://kafka.apache.org/40/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#assign(java.util.Collection)
9797
"
9898
[^Consumer consumer topics & {:keys [assigned-callback revoked-callback]
9999
:or {assigned-callback (fn [_])
@@ -279,13 +279,13 @@
279279
([^Consumer consumer offset-commit-fn]
280280
(let [callback (reify OffsetCommitCallback
281281
(onComplete [_ offsets exception]
282-
(offset-commit-fn (tp-om-map->map offsets) exception)))]
282+
(offset-commit-fn (topic-partition-offsets->clj offsets) exception)))]
283283
(.commitAsync consumer callback)))
284284
([^Consumer consumer topic-partition-offsets-metadata offset-commit-fn]
285285
(let [callback (reify OffsetCommitCallback
286286
(onComplete [_ offsets exception]
287-
(offset-commit-fn (tp-om-map->map offsets) exception)))
288-
tp-om-map (map->tp-om-map topic-partition-offsets-metadata)]
287+
(offset-commit-fn (topic-partition-offsets->clj offsets) exception)))
288+
tp-om-map (clj->topic-partition-offsets-map topic-partition-offsets-metadata)]
289289
(.commitAsync consumer tp-om-map callback))))
290290

291291

@@ -311,15 +311,15 @@
311311
"
312312
([^Consumer consumer] (.commitSync consumer))
313313
([^Consumer consumer topic-partitions-offsets-metadata]
314-
(let [tp-om-map ^Map (map->tp-om-map topic-partitions-offsets-metadata)]
314+
(let [tp-om-map ^Map (clj->topic-partition-offsets-map topic-partitions-offsets-metadata)]
315315
(.commitSync consumer tp-om-map))))
316316

317317

318318
(defn ^:deprecated last-committed-offset
319319
"Gets the last committed offset for the partition of a topic.
320320
NOTE This function is a blocking I/O operation.
321321
322-
see http://kafka.apache.org/0100/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#committed(org.apache.kafka.common.TopicPartition)
322+
see http://kafka.apache.org/40/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#committed(org.apache.kafka.common.TopicPartition)
323323
324324
Usage:
325325
@@ -336,11 +336,11 @@
336336
(defn list-all-topics
337337
"Get metadata about ALL partitions for ALL topics that the user is authorized to view.
338338
NOTE This function is a blocking I/O operation.
339-
340-
See https://kafka.apache.org/34/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#listTopics()
341-
339+
340+
See https://kafka.apache.org/40/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#listTopics()
341+
342342
Usage :
343-
343+
344344
(list-all-topics consumer)
345345
;; =>{\"topic-a\"
346346
;; [{:topic \"topic-a\",
@@ -366,16 +366,16 @@
366366
;; :in-sync-replicas [{:id 2, :host \"172.17.0.3\", :port 9093}]}]}
367367
"
368368
[^Consumer consumer]
369-
(str-pi-map->map (.listTopics consumer)))
369+
(topic-partitions-info->clj (.listTopics consumer)))
370370

371371
(defn list-all-partitions
372372
"Get metadata about all partitions for a particular topic.
373373
NOTE This function is a blocking I/O operation.
374-
375-
See https://kafka.apache.org/34/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#partitionsFor(java.lang.String)
376-
374+
375+
See https://kafka.apache.org/40/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#partitionsFor(java.lang.String)
376+
377377
Usage :
378-
378+
379379
(list-all-partitions consumer)
380380
;; => [{:topic \"topic-b\",
381381
;; :partition 2,
@@ -400,10 +400,10 @@
400400
(defn pause
401401
"Stops messages being consumed from the given partitions.
402402
This takes effect on the next call on the messages function
403-
See https://kafka.apache.org/34/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#pause(java.util.Collection)
404-
403+
See https://kafka.apache.org/40/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#pause(java.util.Collection)
404+
405405
Usage:
406-
406+
407407
(pause consumer {:topic \"topic-a\" :partition 2}
408408
{:topic \"topic-b\" :partition 0})
409409
"
@@ -416,10 +416,10 @@
416416
(defn resume
417417
"Resumes messages being consumed from the given partitions.
418418
This takes effect on the next call on the messages function
419-
See https://kafka.apache.org/34/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#resume(java.util.Collection)
420-
419+
See https://kafka.apache.org/40/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#resume(java.util.Collection)
420+
421421
Usage:
422-
422+
423423
(resume consumer {:topic \"topic-a\" :partition 2}
424424
{:topic \"topic-b\" :partition 0})
425425
"

src/clj_kafka_x/data.clj

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@
8585
(if (or (nil? offset) (nil? metadata))
8686
(throw (ex-info "Provided map is missing offset or metadata keys" m))
8787
(OffsetAndMetadata. offset metadata)))
88-
89-
;;NOT happy with this function name
90-
(defn tp-om-map->map
88+
89+
(defn topic-partition-offsets->clj
9190
"Takes a java.util.Map made of TopicPartition as keys and OffsetAndMetadata as values,
9291
converts them to the following clojure equivalent data structure
9392
@@ -96,32 +95,30 @@
9695
{:topic \"dev\", :partition 1} {:offset 234, :metadata \"loads of data\"},
9796
{:topic \"dev\", :partition 7} {:offset 23, :metadata \"mega data\"}}
9897
"
99-
[^Map tp-om]
98+
[^Map topic-partition-offsets-map]
10099
(let [reduce-fn (fn [m [^TopicPartition tp ^OffsetAndMetadata om]]
101100
(assoc m (to-clojure tp) (to-clojure om)))]
102-
(reduce reduce-fn {} tp-om)))
103-
104-
;;NOT happy with this function name
105-
(defn map->tp-om-map
101+
(reduce reduce-fn {} topic-partition-offsets-map)))
102+
103+
(defn clj->topic-partition-offsets-map
106104
"Takes a Clojure map (see below for example) and converts it to a java.util.Map made of TopicPartition as keys and OffsetAndMetadata as values
107-
105+
108106
{{:topic \"test\", :partition 77} {:offset 34, :metadata \"data data\"},
109107
{:topic \"prod\", :partition 4} {:offset 24, :metadata \"more data\"},
110108
{:topic \"dev\", :partition 1} {:offset 234, :metadata \"loads of data\"},
111109
{:topic \"dev\", :partition 7} {:offset 23, :metadata \"mega data\"}}
112110
"
113111
[m]
114-
(let [tp-om-map (HashMap.)
112+
(let [^Map java-map (HashMap.)
115113
reduce-fn (fn [^Map m kv]
116114
(.put m (map->topic-partition (first kv))
117115
(map->offset-metadata (second kv)))
118116
m)]
119-
(reduce reduce-fn tp-om-map m)))
120-
121-
122-
;;NOT happy with this function name
123-
(defn str-pi-map->map
124-
"Takes a java.util.Map made of Strings as keys and java.util.List <PartitionInfo> as values,
117+
(reduce reduce-fn java-map m)))
118+
119+
120+
(defn topic-partitions-info->clj
121+
"Takes a java.util.Map made of Strings (topic names) as keys and java.util.List <PartitionInfo> as values,
125122
converts it to a Map with the keys being the topic name and the values being a vector of maps (each map representing information about a topic partition)
126123
e.g
127124
@@ -147,10 +144,10 @@
147144
:in-sync-replicas [{:id 3, :host \"172.17.0.4\", :port 9094} {:id 1, :host \"172.17.0.3\", :port 9092} {:id 2, :host \"172.17.0.2\", :port 9093}]}]}
148145
"
149146
[^Map str-pi]
150-
(let [reduce-fn (fn [m [name pi-list]]
151-
(assoc m name (mapv to-clojure pi-list)))]
147+
(let [reduce-fn (fn [clj-map [name pi-list]]
148+
(assoc clj-map name (mapv to-clojure pi-list)))]
152149
(reduce reduce-fn {} str-pi)))
153-
150+
154151
(defn metrics->map
155152
"Returns a sequence of maps, with each map representing a metric.
156153
The composition of each map is :group :name :description :tags :value

src/clj_kafka_x/producer.clj

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(ns ^{:doc "Clojure interface for Kafka Producer API. For
22
complete JavaDocs, see:
3-
https://kafka.apache.org/34/javadoc/org/apache/kafka/clients/producer/package-summary.html"}
3+
https://kafka.apache.org/37/javadoc/org/apache/kafka/clients/producer/package-summary.html"}
44
clj-kafka-x.producer
55
(:refer-clojure :exclude [send flush])
66
(:require [clj-kafka-x.data :refer :all]
@@ -30,12 +30,12 @@
3030
"Takes a map of config options and returns a `KafkaProducer` for publishing records to Kafka.
3131
3232
NOTE `KafkaProducer` instances are thread-safe and should generally be shared for best performance.
33-
33+
3434
For more information and available config options,
35-
see: https://kafka.apache.org/34/javadoc/org/apache/kafka/clients/producer/KafkaProducer.html
35+
see: https://kafka.apache.org/37/javadoc/org/apache/kafka/clients/producer/KafkaProducer.html
3636
https://kafka.apache.org/documentation.html#producerconfigs
37-
38-
37+
38+
3939
Usage:
4040
4141
;; Created using just a map of configs, in this case the keys
@@ -74,11 +74,11 @@
7474
a callback fn that will be called when the operation completes.
7575
Callback should be a fn of two arguments, a map as above, and an
7676
exception. Exception will be nil if operation succeeded.
77-
78-
See: https://kafka.apache.org/34/javadoc/org/apache/kafka/clients/producer/KafkaProducer.html#send(org.apache.kafka.clients.producer.ProducerRecord)
79-
77+
78+
See: https://kafka.apache.org/37/javadoc/org/apache/kafka/clients/producer/KafkaProducer.html#send(org.apache.kafka.clients.producer.ProducerRecord)
79+
8080
Usage:
81-
81+
8282
;;To send the message asynchronously and return a Future
8383
(send producer (record \"topic-a\" \"Test message 1\"))
8484
;; => #object[string representation of future object]
@@ -101,19 +101,19 @@
101101
(onCompletion [_ metadata exception]
102102
(callback (and metadata (to-clojure metadata)) exception))))]
103103
(map-future-val fut to-clojure))))
104-
104+
105105
(defn flush
106-
"See: https://kafka.apache.org/34/javadoc/org/apache/kafka/clients/producer/KafkaProducer.html#flush()"
106+
"See: https://kafka.apache.org/37/javadoc/org/apache/kafka/clients/producer/KafkaProducer.html#flush()"
107107
[^Producer producer]
108108
(.flush producer))
109109

110110
(defn close
111111
"Like `.close`, but with a default time unit of ms for the arity with timeout.
112-
112+
113113
See:
114-
115-
- https://kafka.apache.org/34/javadoc/org/apache/kafka/clients/producer/KafkaProducer.html#close()
116-
- https://kafka.apache.org/34/javadoc/org/apache/kafka/clients/producer/KafkaProducer.html#close(java.time.Duration)"
114+
115+
- https://kafka.apache.org/37/javadoc/org/apache/kafka/clients/producer/KafkaProducer.html#close()
116+
- https://kafka.apache.org/37/javadoc/org/apache/kafka/clients/producer/KafkaProducer.html#close(java.time.Duration)"
117117
([^Producer producer]
118118
(.close producer))
119119
([^Producer producer timeout-ms]

0 commit comments

Comments
 (0)