Skip to content

Commit

Permalink
feat(mqtt): add option to set :clean-start
Browse files Browse the repository at this point in the history
  • Loading branch information
thalesmg committed Oct 23, 2024
1 parent 22cabd2 commit fdb1a8b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions config.example.edn
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -24,4 +25,5 @@
:port 1883
:clientid "chan2"
:topic "t/sf/2"
:qos 1}}]}
:qos 1
:clean-start false}}]}
5 changes: 3 additions & 2 deletions src/emqx/adapter.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/emqx/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down

0 comments on commit fdb1a8b

Please sign in to comment.