1、代码重构,去掉mqtt-broke相关2、修复程序启动ekuiper创建失败bug。3、程序启动加入官方logo

master
winc-link 2024-06-23 16:58:17 +08:00
parent 356a65b552
commit 7c309cb904
14 changed files with 184 additions and 144 deletions

View File

@ -38,15 +38,17 @@ type MessageApp struct {
lc logger.LoggingClient lc logger.LoggingClient
dbClient interfaces.DBClient dbClient interfaces.DBClient
ekuiperMqttClient pkgMQTT.MQTTClient ekuiperMqttClient pkgMQTT.MQTTClient
ekuiperaddr string
} }
func NewMessageApp(dic *di.Container) *MessageApp { func NewMessageApp(dic *di.Container, ekuiperaddr string) *MessageApp {
lc := container.LoggingClientFrom(dic.Get) lc := container.LoggingClientFrom(dic.Get)
dbClient := coreContainer.DBClientFrom(dic.Get) dbClient := coreContainer.DBClientFrom(dic.Get)
msgApp := &MessageApp{ msgApp := &MessageApp{
dic: dic, dic: dic,
dbClient: dbClient, dbClient: dbClient,
lc: lc, lc: lc,
ekuiperaddr: ekuiperaddr,
} }
mqttClient := msgApp.connectMQTT() mqttClient := msgApp.connectMQTT()
msgApp.ekuiperMqttClient = mqttClient msgApp.ekuiperMqttClient = mqttClient
@ -59,7 +61,7 @@ func (tmq *MessageApp) initeKuiperStreams() {
r := make(map[string]string) r := make(map[string]string)
r["sql"] = "CREATE STREAM mqtt_stream () WITH (DATASOURCE=\"eventbus/in\", FORMAT=\"JSON\",SHARED = \"true\")" r["sql"] = "CREATE STREAM mqtt_stream () WITH (DATASOURCE=\"eventbus/in\", FORMAT=\"JSON\",SHARED = \"true\")"
b, _ := json.Marshal(r) b, _ := json.Marshal(r)
resp, err := req.Post("http://ekuiper:9081/streams", b) resp, err := req.Post(tmq.ekuiperaddr, b)
if err != nil { if err != nil {
tmq.lc.Errorf("init ekuiper stream failed error:%+v", err.Error()) tmq.lc.Errorf("init ekuiper stream failed error:%+v", err.Error())
return return
@ -87,8 +89,6 @@ func (tmq *MessageApp) initeKuiperStreams() {
tmq.lc.Infof("init ekuiper stream plug success") tmq.lc.Infof("init ekuiper stream plug success")
return return
} }
} else {
tmq.lc.Errorf("init ekuiper stream failed resp code:%+v", resp.StatusCode())
} }
} }

View File

@ -125,16 +125,19 @@ func (s *DriverDeviceServer) CreateDevice(ctx context.Context, request *device.C
response.BaseResponse.ErrorMessage = errWrapper.Message() response.BaseResponse.ErrorMessage = errWrapper.Message()
return response, nil return response, nil
} }
deviceInfo, _ := deviceItf.DeviceById(ctx, deviceId)
response.BaseResponse.Success = true response.BaseResponse.Success = true
response.Data = new(device.CreateDeviceRequestResponse_Data) response.Data = new(device.CreateDeviceRequestResponse_Data)
response.Data.Devices = new(device.Device) response.Data.Devices = new(device.Device)
response.Data.Devices.Id = deviceId response.Data.Devices.Id = deviceId
response.Data.Devices.Name = request.Device.Name response.Data.Devices.Name = request.Device.Name
response.Data.Devices.Description = request.Device.Description
response.Data.Devices.ProductId = request.Device.ProductId response.Data.Devices.ProductId = request.Device.ProductId
response.Data.Devices.DeviceSn = request.Device.DeviceSn
response.Data.Devices.External = request.Device.External
response.Data.Devices.Secret = deviceInfo.Secret
response.Data.Devices.Description = request.Device.Description
response.Data.Devices.Status = device.DeviceStatus_OffLine response.Data.Devices.Status = device.DeviceStatus_OffLine
response.Data.Devices.Platform = drivercommon.IotPlatform_LocalIot response.Data.Devices.Platform = drivercommon.IotPlatform_LocalIot
return response, nil return response, nil
} }

View File

@ -327,7 +327,7 @@ func (b *Bootstrap) initClient(ctx context.Context, wg *sync.WaitGroup, dic *di.
}, },
}) })
messageItf := messageapp.NewMessageApp(dic) messageItf := messageapp.NewMessageApp(dic, configuration.Clients["Ekuiper"].Address())
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.MessageItfName: func(get di.Get) interface{} { container.MessageItfName: func(get di.Get) interface{} {
return messageItf return messageItf

View File

@ -2,7 +2,9 @@ package route
import ( import (
"context" "context"
"fmt"
"github.com/winc-link/hummingbird/internal/hummingbird/core/container" "github.com/winc-link/hummingbird/internal/hummingbird/core/container"
"github.com/winc-link/hummingbird/internal/pkg/color"
pkgContainer "github.com/winc-link/hummingbird/internal/pkg/container" pkgContainer "github.com/winc-link/hummingbird/internal/pkg/container"
"github.com/winc-link/hummingbird/internal/pkg/di" "github.com/winc-link/hummingbird/internal/pkg/di"
"github.com/winc-link/hummingbird/internal/pkg/startup" "github.com/winc-link/hummingbird/internal/pkg/startup"
@ -69,6 +71,14 @@ func (b *WebBootstrap) BootstrapHandler(ctx context.Context, wg *sync.WaitGroup,
}() }()
lc.Info("WebProxy server starting (" + addr + ")") lc.Info("WebProxy server starting (" + addr + ")")
fmt.Println(color.Red(string(color.LogoContent)))
tip()
fmt.Println(color.Green("Server run at:"))
fmt.Printf("- Web: http://localhost:%d/ \r\n", configuration.WebServer.Port)
fmt.Println(color.Green("Swagger run at:"))
fmt.Printf("- Local: http://localhost:%d/api/v1/swagger/index.html \r\n", configuration.Service.Port)
fmt.Printf("%s Enter Control + C Shutdown Server \r\n", time.Now().Format("2006-01-02 15:04:05"))
wg.Add(1) wg.Add(1)
go func() { go func() {
@ -88,3 +98,8 @@ func (b *WebBootstrap) BootstrapHandler(ctx context.Context, wg *sync.WaitGroup,
return true return true
} }
func tip() {
usageStr := `欢迎使用 ` + color.Green(`Hummingbird物联网平台社区版 `+"版本v1.0")
fmt.Printf("%s \n\n", usageStr)
}

View File

@ -0,0 +1,56 @@
package color
import (
"fmt"
)
const (
TextBlack = iota + 30
TextRed
TextGreen
TextYellow
TextBlue
TextMagenta
TextCyan
TextWhite
)
func Black(msg string) string {
return SetColor(msg, 0, 0, TextBlack)
}
func Red(msg string) string {
return SetColor(msg, 0, 0, TextRed)
}
func Green(msg string) string {
return SetColor(msg, 0, 0, TextGreen)
}
func Yellow(msg string) string {
return SetColor(msg, 0, 0, TextYellow)
}
func Blue(msg string) string {
return SetColor(msg, 0, 0, TextBlue)
}
func Magenta(msg string) string {
return SetColor(msg, 0, 0, TextMagenta)
}
func Cyan(msg string) string {
return SetColor(msg, 0, 0, TextCyan)
}
func White(msg string) string {
return SetColor(msg, 0, 0, TextWhite)
}
func SetColor(msg string, conf, bg, text int) string {
return fmt.Sprintf("%c[%d;%d;%dm%s%c[0m", 0x1B, conf, bg, text, msg, 0x1B)
}
var LogoContent = "\n ____ ____ _ __ _ __ \n|_ || _| (_) [ | (_) | ] \n | |__| | __ _ _ .--..--. _ .--..--. __ _ .--. .--./)| |.--. __ _ .--. .--.| | \n | __ | [ | | | [ `.-. .-. | [ `.-. .-. | [ | [ `.-. | / /'`\\;| '/'`\\ \\[ | [ `/'`\\]/ /'`\\' | \n _| | | |_ | \\_/ |, | | | | | | | | | | | | | | | | | | \\ \\._//| \\__/ | | | | | | \\__/ | \n|____||____|'.__.'_/[___||__||__][___||__||__][___][___||__].',__`[__;.__.' [___][___] '.__.;__] \n ( ( __)) \n"
var MQTTBrokerLogoContext = "\n ____ \n/ ___| _ _ ___ ___ ___ ___ ___ \n\\___ \\| | | |/ __/ __/ _ \\/ __/ __|\n ___) | |_| | (_| (_| __/\\__ \\__ \\\n|____/ \\__,_|\\___\\___\\___||___/___/\n "

View File

@ -1,71 +0,0 @@
# NanoMQ Configuration 0.18.0
# #============================================================
# # NanoMQ Broker
# #============================================================
mqtt {
property_size = 32
max_packet_size = 100KB
max_mqueue_len = 2048
retry_interval = 10s
keepalive_multiplier = 1.25
# Three of below, unsupported now
max_inflight_window = 2048
max_awaiting_rel = 10s
await_rel_timeout = 10s
}
listeners.tcp {
bind = "0.0.0.0:1883"
}
# listeners.ssl {
# bind = "0.0.0.0:8883"
# keyfile = "/etc/certs/key.pem"
# certfile = "/etc/certs/cert.pem"
# cacertfile = "/etc/certs/cacert.pem"
# verify_peer = false
# fail_if_no_peer_cert = false
# }
listeners.ws {
bind = "0.0.0.0:8083/mqtt"
}
http_server {
port = 8081
limit_conn = 2
username = admin
password = public
auth_type = basic
jwt {
public.keyfile = "/etc/certs/jwt/jwtRS256.key.pub"
}
}
log {
to = [file]
level = warn
dir = "/data/logs"
file = "nanomq.log"
rotation {
size = 10MB
count = 5
}
}
auth {
allow_anonymous = true
no_match = allow
deny_action = ignore
cache = {
max_size = 32
ttl = 1m
}
# password = {include "/etc/nanomq_pwd.conf"}
# acl = {include "/etc/nanomq_acl.conf"}
}

Binary file not shown.

View File

@ -0,0 +1 @@
MANIFEST-000007

View File

@ -0,0 +1 @@
MANIFEST-000005

View File

@ -0,0 +1,39 @@
=============== Jun 23, 2024 (UTC) ===============
07:28:50.576890 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
07:28:50.595517 db@open opening
07:28:50.601758 version@stat F·[] S·0B[] Sc·[]
07:28:50.606910 db@janitor F·2 G·0
07:28:50.608077 db@open done T·11.719649ms
07:28:52.124654 db@close closing
07:28:52.125660 db@close done T·1.005394ms
=============== Jun 23, 2024 (UTC) ===============
07:28:58.402544 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
07:28:58.415412 version@stat F·[] S·0B[] Sc·[]
07:28:58.416824 db@open opening
07:28:58.418046 journal@recovery F·1
07:28:58.419128 journal@recovery recovering @1
07:28:58.430863 version@stat F·[] S·0B[] Sc·[]
07:28:58.545419 db@janitor F·2 G·0
07:28:58.547729 db@open done T·129.962204ms
07:49:44.007188 db@close closing
07:49:44.008431 db@close done T·1.252401ms
=============== Jun 23, 2024 (UTC) ===============
07:52:54.060168 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
07:52:54.070750 version@stat F·[] S·0B[] Sc·[]
07:52:54.071563 db@open opening
07:52:54.072563 journal@recovery F·1
07:52:54.073517 journal@recovery recovering @2
07:52:54.080468 version@stat F·[] S·0B[] Sc·[]
07:52:54.117002 db@janitor F·2 G·0
07:52:54.117872 db@open done T·45.529864ms
07:52:54.740007 db@close closing
07:52:54.741617 db@close done T·1.607086ms
=============== Jun 23, 2024 (UTC) ===============
07:52:59.485349 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
07:52:59.496162 version@stat F·[] S·0B[] Sc·[]
07:52:59.497367 db@open opening
07:52:59.499105 journal@recovery F·1
07:52:59.500621 journal@recovery recovering @4
07:52:59.511912 version@stat F·[] S·0B[] Sc·[]
07:52:59.534086 db@janitor F·2 G·0
07:52:59.535315 db@open done T·36.592228ms

View File

@ -5,20 +5,16 @@ networks:
driver: bridge driver: bridge
services: services:
mqtt-broker: mqtt-broker:
image: emqx/nanomq:0.21 image: registry.cn-shanghai.aliyuncs.com/winc-link/mqtt-broker:2.6
container_name: mqtt-broker container_name: mqtt-broker
hostname: mqtt-broker hostname: mqtt-broker
restart: always restart: always
volumes:
- ./logs:/data/logs
- ./conf/nanomq.conf:/etc/nanomq.conf
ports: ports:
- "127.0.0.1:1883:1883" - "58090:58090"
networks: networks:
- hummingbird - hummingbird
ekuiper: ekuiper:
image: lfedge/ekuiper:1.10.0-slim image: registry.cn-shanghai.aliyuncs.com/winc-link/ekuiper:1.10.0-slim
#image: registry.cn-shanghai.aliyuncs.com/winc-link/ekuiper:1.10.0-slim
ports: ports:
- "127.0.0.1:9081:9081" - "127.0.0.1:9081:9081"
container_name: ekuiper container_name: ekuiper