diff --git a/backend/services/mtp/mqtt/.gitignore b/backend/services/mtp/mqtt/.gitignore index d07460d..cadd04c 100644 --- a/backend/services/mtp/mqtt/.gitignore +++ b/backend/services/mtp/mqtt/.gitignore @@ -1,4 +1,3 @@ -cmd/mqtt .DS_Store *.db auth.prod.json @@ -7,4 +6,5 @@ mochi *.pem *.crt *.key -*.local \ No newline at end of file +*.local +./mqtt \ No newline at end of file diff --git a/backend/services/mtp/mqtt/cmd/mqtt/auth.json b/backend/services/mtp/mqtt/cmd/mqtt/auth.json new file mode 100644 index 0000000..f05253a --- /dev/null +++ b/backend/services/mtp/mqtt/cmd/mqtt/auth.json @@ -0,0 +1,54 @@ +{ + "auth": [ + { + "username": "leandro", + "password": "leandro", + "allow": true + }, + { + "username": "steve", + "password": "steve", + "allow": true + }, + { + "username": "root", + "password": "root", + "allow": true + }, + { + "remote": "*", + "allow": false + }, + { + "remote": "*", + "allow": false + } + ], + "acl": [ + { + "remote": "*" + }, + { + "username": "leandro", + "filters": { + "oktopus/+/agent/+": 1, + "oktopus/+/controller/+": 2, + "oktopus/+/get/+": 2 + } + }, + { + "username": "steve", + "filters": { + "oktopus/+/agent/+": 1, + "oktopus/+/controller/+": 2, + "oktopus/+/get/+": 2 + } + }, + { + "username": "root", + "filters": { + "#": 3 + } + } + ] +} \ No newline at end of file diff --git a/backend/services/mtp/mqtt/cmd/mqtt/main.go b/backend/services/mtp/mqtt/cmd/mqtt/main.go new file mode 100644 index 0000000..b833a1e --- /dev/null +++ b/backend/services/mtp/mqtt/cmd/mqtt/main.go @@ -0,0 +1,35 @@ +package main + +import ( + "broker/internal/config" + "broker/internal/listeners" + "log" + "os" + "os/signal" + "syscall" +) + +func main() { + + done := make(chan os.Signal, 1) + + conf := config.NewConfig() + + signal.Notify(done, syscall.SIGINT, syscall.SIGTERM) + + go listeners.StartServers(conf) + + if conf.WsEnable { + log.Printf("websocket is running at port %s", conf.WsPort) + } + + if conf.HttpEnable { + log.Printf("http is running at port %s", conf.HttpPort) + } + + log.Printf("mqtt is running at port %s", conf.MqttPort) + + <-done + + log.Println("server is shutting down...") +} diff --git a/backend/services/mtp/mqtt/cmd/mqtt/run.sh b/backend/services/mtp/mqtt/cmd/mqtt/run.sh new file mode 100644 index 0000000..186907d --- /dev/null +++ b/backend/services/mtp/mqtt/cmd/mqtt/run.sh @@ -0,0 +1 @@ +go run . -path auth.json