Skip to content

Instantly share code, notes, and snippets.

@thalesmg
Created May 3, 2022 19:35
Show Gist options
  • Save thalesmg/56f0828dcdfe7684b498bf4284c31dab to your computer and use it in GitHub Desktop.
Save thalesmg/56f0828dcdfe7684b498bf4284c31dab to your computer and use it in GitHub Desktop.
example pulsar client using basic auth in clojure
# run main
clj -X:run
# rebel readline shell
clj -A:rebel
(ns pulsar-test.core
(:import (org.apache.pulsar.client.api PulsarClient)))
(defn make-consumer
[]
(let [props (doto (java.util.Properties.)
(.putAll {"userId" "super"
"password" "superpass"}))
client (-> (PulsarClient/builder)
(.serviceUrl "pulsar://localhost:6650")
(.authentication
"org.apache.pulsar.client.impl.auth.AuthenticationBasic"
props)
(.build))
consumer (-> (.newConsumer client)
(.topics ["my-topic"])
(.subscriptionName "my-sub")
(.subscribe))]
consumer))
(defn -main
[& _args]
(let [consumer (make-consumer)
message (.receive consumer)]
(println (String. (.getData message)))
(System/exit 0)))
{:deps {org.apache.pulsar/pulsar-client {:mvn/version "2.10.0"}}
:aliases {:rebel {:extra-deps {com.bhauman/rebel-readline {:mvn/version "0.1.4"}}
:main-opts ["-m" "rebel-readline.main"]}
:run {:exec-fn pulsar-test.core/-main}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment