mirror of
https://gitee.com/winc-link/hummingbird.git
synced 2025-04-20 00:12:43 +00:00
1、代码重构,去掉mqtt-broke相关2、修复程序启动ekuiper创建失败bug。3、程序启动加入官方logo
This commit is contained in:
parent
356a65b552
commit
7c309cb904
@ -38,15 +38,17 @@ type MessageApp struct {
|
||||
lc logger.LoggingClient
|
||||
dbClient interfaces.DBClient
|
||||
ekuiperMqttClient pkgMQTT.MQTTClient
|
||||
ekuiperaddr string
|
||||
}
|
||||
|
||||
func NewMessageApp(dic *di.Container) *MessageApp {
|
||||
func NewMessageApp(dic *di.Container, ekuiperaddr string) *MessageApp {
|
||||
lc := container.LoggingClientFrom(dic.Get)
|
||||
dbClient := coreContainer.DBClientFrom(dic.Get)
|
||||
msgApp := &MessageApp{
|
||||
dic: dic,
|
||||
dbClient: dbClient,
|
||||
lc: lc,
|
||||
ekuiperaddr: ekuiperaddr,
|
||||
}
|
||||
mqttClient := msgApp.connectMQTT()
|
||||
msgApp.ekuiperMqttClient = mqttClient
|
||||
@ -59,7 +61,7 @@ func (tmq *MessageApp) initeKuiperStreams() {
|
||||
r := make(map[string]string)
|
||||
r["sql"] = "CREATE STREAM mqtt_stream () WITH (DATASOURCE=\"eventbus/in\", FORMAT=\"JSON\",SHARED = \"true\")"
|
||||
b, _ := json.Marshal(r)
|
||||
resp, err := req.Post("http://ekuiper:9081/streams", b)
|
||||
resp, err := req.Post(tmq.ekuiperaddr, b)
|
||||
if err != nil {
|
||||
tmq.lc.Errorf("init ekuiper stream failed error:%+v", err.Error())
|
||||
return
|
||||
@ -87,8 +89,6 @@ func (tmq *MessageApp) initeKuiperStreams() {
|
||||
tmq.lc.Infof("init ekuiper stream plug success")
|
||||
return
|
||||
}
|
||||
} else {
|
||||
tmq.lc.Errorf("init ekuiper stream failed resp code:%+v", resp.StatusCode())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,16 +125,19 @@ func (s *DriverDeviceServer) CreateDevice(ctx context.Context, request *device.C
|
||||
response.BaseResponse.ErrorMessage = errWrapper.Message()
|
||||
return response, nil
|
||||
}
|
||||
deviceInfo, _ := deviceItf.DeviceById(ctx, deviceId)
|
||||
response.BaseResponse.Success = true
|
||||
response.Data = new(device.CreateDeviceRequestResponse_Data)
|
||||
response.Data.Devices = new(device.Device)
|
||||
response.Data.Devices.Id = deviceId
|
||||
response.Data.Devices.Name = request.Device.Name
|
||||
response.Data.Devices.Description = request.Device.Description
|
||||
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.Platform = drivercommon.IotPlatform_LocalIot
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
||||
|
@ -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{
|
||||
container.MessageItfName: func(get di.Get) interface{} {
|
||||
return messageItf
|
||||
|
@ -2,7 +2,9 @@ package route
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"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"
|
||||
"github.com/winc-link/hummingbird/internal/pkg/di"
|
||||
"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 + ")")
|
||||
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)
|
||||
go func() {
|
||||
@ -88,3 +98,8 @@ func (b *WebBootstrap) BootstrapHandler(ctx context.Context, wg *sync.WaitGroup,
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func tip() {
|
||||
usageStr := `欢迎使用 ` + color.Green(`Hummingbird物联网平台(社区版) `+"版本:v1.0")
|
||||
fmt.Printf("%s \n\n", usageStr)
|
||||
}
|
||||
|
56
internal/pkg/color/textcolor.go
Normal file
56
internal/pkg/color/textcolor.go
Normal 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 "
|
@ -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"}
|
||||
}
|
BIN
manifest/docker/db-data/core-data/core.db
Normal file
BIN
manifest/docker/db-data/core-data/core.db
Normal file
Binary file not shown.
1
manifest/docker/db-data/leveldb-core-data/CURRENT
Normal file
1
manifest/docker/db-data/leveldb-core-data/CURRENT
Normal file
@ -0,0 +1 @@
|
||||
MANIFEST-000007
|
1
manifest/docker/db-data/leveldb-core-data/CURRENT.bak
Normal file
1
manifest/docker/db-data/leveldb-core-data/CURRENT.bak
Normal file
@ -0,0 +1 @@
|
||||
MANIFEST-000005
|
0
manifest/docker/db-data/leveldb-core-data/LOCK
Normal file
0
manifest/docker/db-data/leveldb-core-data/LOCK
Normal file
39
manifest/docker/db-data/leveldb-core-data/LOG
Normal file
39
manifest/docker/db-data/leveldb-core-data/LOG
Normal 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
|
BIN
manifest/docker/db-data/leveldb-core-data/MANIFEST-000007
Normal file
BIN
manifest/docker/db-data/leveldb-core-data/MANIFEST-000007
Normal file
Binary file not shown.
@ -5,20 +5,16 @@ networks:
|
||||
driver: bridge
|
||||
services:
|
||||
mqtt-broker:
|
||||
image: emqx/nanomq:0.21
|
||||
image: registry.cn-shanghai.aliyuncs.com/winc-link/mqtt-broker:2.6
|
||||
container_name: mqtt-broker
|
||||
hostname: mqtt-broker
|
||||
restart: always
|
||||
volumes:
|
||||
- ./logs:/data/logs
|
||||
- ./conf/nanomq.conf:/etc/nanomq.conf
|
||||
ports:
|
||||
- "127.0.0.1:1883:1883"
|
||||
- "58090:58090"
|
||||
networks:
|
||||
- hummingbird
|
||||
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:
|
||||
- "127.0.0.1:9081:9081"
|
||||
container_name: ekuiper
|
||||
|
Loading…
x
Reference in New Issue
Block a user