refactor: Mark client functions as deprecated and redirect to API calls
This commit is contained in:
@@ -1 +1,13 @@
|
|||||||
(ns milquetoast.client)
|
(ns milquetoast.client
|
||||||
|
(:require [milquetoast.api :as api])
|
||||||
|
(:import [clojure.lang ExceptionInfo]))
|
||||||
|
|
||||||
|
(defn- deprecated [f]
|
||||||
|
(fn [& args]
|
||||||
|
(println (str "WARNING: The function '" (name f) "' in the 'milquetoast.client' namespace is deprecated. Please use 'milquetoast.api' instead."))
|
||||||
|
(apply f args)))
|
||||||
|
|
||||||
|
(defmacro defdeprecated [name & body]
|
||||||
|
`(def ~name (deprecated (fn ~@body))))
|
||||||
|
|
||||||
|
(println "WARNING: The 'milquetoast.client' namespace is deprecated. Please use 'milquetoast.api' instead.")
|
||||||
|
|||||||
@@ -7,22 +7,11 @@
|
|||||||
(:import [org.eclipse.paho.client.mqttv3 MqttClient MqttConnectOptions MqttMessage IMqttMessageListener]
|
(:import [org.eclipse.paho.client.mqttv3 MqttClient MqttConnectOptions MqttMessage IMqttMessageListener]
|
||||||
org.eclipse.paho.client.mqttv3.persist.MemoryPersistence))
|
org.eclipse.paho.client.mqttv3.persist.MemoryPersistence))
|
||||||
|
|
||||||
(defn create-mqtt-client!
|
(defdeprecated create-mqtt-client!
|
||||||
"Creates and connects an MQTT client with the provided broker URI, username, and password.
|
|
||||||
Returns the connected MQTT client instance."
|
|
||||||
[& {:keys [broker-uri username password]
|
[& {:keys [broker-uri username password]
|
||||||
:or {username nil
|
:or {username nil
|
||||||
password nil}}]
|
password nil}}]
|
||||||
(let [client-id (MqttClient/generateClientId)
|
(api/connect! :host broker-uri :username username :password password))
|
||||||
opts (doto (MqttConnectOptions.)
|
|
||||||
(.setCleanSession true)
|
|
||||||
(.setAutomaticReconnect true))]
|
|
||||||
(when username
|
|
||||||
(doto opts
|
|
||||||
(.setUserName username)
|
|
||||||
(.setPassword (char-array password))))
|
|
||||||
(doto (MqttClient. broker-uri client-id (MemoryPersistence.))
|
|
||||||
(.connect opts))))
|
|
||||||
|
|
||||||
(defn- retry-attempt
|
(defn- retry-attempt
|
||||||
"Attempts to execute function `f`. If `f` throws a RuntimeException, logs the exception and attempts to reconnect before retrying `f`."
|
"Attempts to execute function `f`. If `f` throws a RuntimeException, logs the exception and attempts to reconnect before retrying `f`."
|
||||||
@@ -138,20 +127,12 @@
|
|||||||
msg
|
msg
|
||||||
nil)))
|
nil)))
|
||||||
|
|
||||||
(defn create-client
|
(defdeprecated create-client
|
||||||
"Creates a new MilquetoastClient instance with the provided MQTT client and options."
|
|
||||||
[broker-uri username password & {:keys [verbose]
|
[broker-uri username password & {:keys [verbose]
|
||||||
:or {verbose false}}]
|
:or {verbose false}}]
|
||||||
(let [mqtt-client (create-mqtt-client! :broker-uri broker-uri
|
(api/connect! :host broker-uri :username username :password password :verbose verbose))
|
||||||
:username username
|
|
||||||
:password password)]
|
|
||||||
(MilquetoastClient. mqtt-client (atom []) verbose)))
|
|
||||||
|
|
||||||
(defn create-json-client
|
(defdeprecated create-json-client
|
||||||
"Creates a new MilquetoastJsonClient instance with the provided MQTT client."
|
|
||||||
[broker-uri username password & {:keys [verbose]
|
[broker-uri username password & {:keys [verbose]
|
||||||
:or {verbose false}}]
|
:or {verbose false}}]
|
||||||
(let [mqtt-client (create-mqtt-client! :broker-uri broker-uri
|
(api/connect-json! :host broker-uri :username username :password password :verbose verbose))
|
||||||
:username username
|
|
||||||
:password password)]
|
|
||||||
(MilquetoastJsonClient. mqtt-client (atom []) verbose)))
|
|
||||||
|
|||||||
Reference in New Issue
Block a user