From fdb1a8bc24de904dd7c2afc28c3c3f86957e2809 Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Wed, 23 Oct 2024 15:42:07 -0300 Subject: [PATCH] feat(mqtt): add option to set `:clean-start` --- config.example.edn | 6 ++++-- src/emqx/adapter.clj | 5 +++-- src/emqx/config.clj | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/config.example.edn b/config.example.edn index 9679fff..ec2c855 100644 --- a/config.example.edn +++ b/config.example.edn @@ -14,7 +14,8 @@ :port 1883 :clientid "chan1" :topic "t/sf/1" - :qos 1}} + :qos 1 + :clean-start false}} {:chan-name "my_channel2" :database "TESTDATABASE" :schema "PUBLIC" @@ -24,4 +25,5 @@ :port 1883 :clientid "chan2" :topic "t/sf/2" - :qos 1}}]} + :qos 1 + :clean-start false}}]} diff --git a/src/emqx/adapter.clj b/src/emqx/adapter.clj index abe1d4a..b1821cf 100644 --- a/src/emqx/adapter.clj +++ b/src/emqx/adapter.clj @@ -4,14 +4,15 @@ [cheshire.core :as json])) (defn mqtt-client-config - [{:keys [:host :port :clientid :topic :qos :username :password]}] + [{:keys [:host :port :clientid :topic :qos :clean-start :username :password]}] {:uri (str "tcp://" host ":" port) :clientid clientid :topic topic :qos qos :opts (cond-> {:auto-reconnect true} username (assoc :username username) - password (assoc :password password))}) + password (assoc :password password) + (boolean? clean-start) (assoc :clean-session clean-start))}) (defn channel-data-in "Parses the incoming payload and expects it to be a JSON encoded object" diff --git a/src/emqx/config.clj b/src/emqx/config.clj index 29ecd48..670d83c 100644 --- a/src/emqx/config.clj +++ b/src/emqx/config.clj @@ -20,6 +20,7 @@ :clientid s/Str :topic s/Str :qos (s/enum 0 1 2) + (s/optional-key :clean-start) s/Bool (s/optional-key :username) s/Str (s/optional-key :password) s/Str})