Last active
July 28, 2017 09:23
-
-
Save tolitius/38795c53d0db8e886d0abdbd7877d5df to your computer and use it in GitHub Desktop.
edn to gregor (kafka) conf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.string :as s] | |
'[gregor.core :as gregor]) | |
(defn to-prop [k] | |
(-> k name (s/replace #"-" "."))) | |
(defn to-props | |
"ranames keys by converting them to strings and substituting dashes with periods | |
only does top level keys" | |
[conf] | |
(into {} | |
(for [[k v] conf] | |
[(to-prop k) v]))) | |
(defn edn-to-gregor [{:keys [bootstrap-servers group-id topics] :as conf}] | |
[bootstrap-servers | |
group-id | |
topics | |
(to-props (dissoc conf :topics))]) | |
;; -------------------------------------------- | |
(def conf {:bootstrap-servers "localhost:9092" | |
:group-id "testgroup" | |
:auto-offset-reset "earliest" | |
:enable-auto-commit "false" | |
:key-deserializer "org.apache.kafka.common.serialization.ByteArrayDeserializer" | |
:value-deserializer "org.apache.kafka.common.serialization.ByteArrayDeserializer" | |
:topics ["my-topic"]}) | |
(apply gregor/consumer (edn-to-gregor conf)) | |
;; => #object[org.apache.kafka.clients.consumer.KafkaConsumer 0x2fb84b38 "org.apache.kafka.clients.consumer.KafkaConsumer@2fb84b38"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment