-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from emqx/mqtt
feat: change app from http listener to mqtt client
- Loading branch information
Showing
15 changed files
with
287 additions
and
580 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
name: docker | ||
|
||
on: [push] | ||
on: | ||
push: | ||
tags: | ||
- "**" | ||
workflow_dispatch: {} | ||
|
||
jobs: | ||
docker: | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ pom.xml.asc | |
/profile.json | ||
/.lsp/ | ||
/config.edn | ||
.rebel_readline_history |
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,25 @@ | ||
(ns emqx.adapter | ||
(:require | ||
[cats.monad.either :refer [left right]] | ||
[schema.core :as s])) | ||
[cheshire.core :as json])) | ||
|
||
(s/defschema UpsertChannelWire | ||
{:chan-name s/Str | ||
:database s/Str | ||
:schema s/Str | ||
:table s/Str | ||
:on-error (s/enum :continue :abort)}) | ||
(defn mqtt-client-config | ||
[{:keys [:host :port :clientid :topic :qos :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))}) | ||
|
||
(defn upsert-channel-in | ||
[{:keys [:json-params :path-params]}] | ||
(let [{:keys [:chan-name]} path-params | ||
{:keys [:database :schema :table :on_error]} json-params | ||
on-error (keyword on_error) | ||
chan-params {:chan-name chan-name | ||
:database database | ||
:schema schema | ||
:table table | ||
:on-error on-error} | ||
errors (s/check UpsertChannelWire chan-params)] | ||
(if errors | ||
(left errors) | ||
(right chan-params)))) | ||
|
||
(s/defschema JsonVal | ||
(s/maybe | ||
(s/conditional | ||
string? s/Str | ||
number? s/Num | ||
boolean? s/Bool | ||
map? {s/Str (s/recursive #'JsonVal)} | ||
vector? [(s/recursive #'JsonVal)]))) | ||
|
||
(s/defschema InsertRowsWire | ||
;; TODO: should use more lax value types??? | ||
{:rows [(s/conditional | ||
(every-pred map? not-empty) {s/Str JsonVal})]}) | ||
|
||
(defn insert-rows-in | ||
[{:keys [:json-params]}] | ||
(let [rows (get json-params "rows") | ||
insert-rows-params {:rows rows} | ||
errors (s/check InsertRowsWire insert-rows-params)] | ||
(if errors | ||
(left errors) | ||
(right insert-rows-params)))) | ||
(defn channel-data-in | ||
"Parses the incoming payload and expects it to be a JSON encoded object" | ||
[^bytes payload] | ||
(try | ||
(let [decoded (json/parse-string (String. payload "UTF-8"))] | ||
(if (map? decoded) | ||
(right decoded) | ||
(left "bad input: should be a single JSON object"))) | ||
(catch Exception e | ||
(left (str "bad input: failure parsing json: " (.getMessage e)))))) |
This file contains 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
This file contains 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
Oops, something went wrong.