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

This commit is contained in:
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

@ -29,7 +29,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"time" "time"
pkgMQTT "github.com/winc-link/hummingbird/internal/tools/mqttclient" pkgMQTT "github.com/winc-link/hummingbird/internal/tools/mqttclient"
) )
@ -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,12 +61,12 @@ 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
} }
if resp.StatusCode() == 201 { if resp.StatusCode() == 201 {
body, err := resp.Body() body, err := resp.Body()
if err != nil { if err != nil {
@ -82,13 +84,11 @@ func (tmq *MessageApp) initeKuiperStreams() {
tmq.lc.Errorf("init ekuiper stream failed error:%+v", err.Error()) tmq.lc.Errorf("init ekuiper stream failed error:%+v", err.Error())
return return
} }
if strings.Contains(string(body), "already exists") { if strings.Contains(string(body), "already exists") {
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())
} }
} }
@ -102,7 +102,7 @@ func (tmq *MessageApp) DeviceStatusToMessageBus(ctx context.Context, deviceId, d
} }
b, _ := json.Marshal(messageBus) b, _ := json.Marshal(messageBus)
tmq.pushMsgToMessageBus(b) tmq.pushMsgToMessageBus(b)
} }
func (tmq *MessageApp) ThingModelMsgReport(ctx context.Context, msg dtos.ThingModelMessage) (*drivercommon.CommonResponse, error) { func (tmq *MessageApp) ThingModelMsgReport(ctx context.Context, msg dtos.ThingModelMessage) (*drivercommon.CommonResponse, error) {
tmq.pushMsgToMessageBus(msg.TransformMessageBus()) tmq.pushMsgToMessageBus(msg.TransformMessageBus())

View File

@ -52,7 +52,7 @@ func (s *DriverDeviceServer) GetDeviceConnectStatus(ctx context.Context, request
func (s *DriverDeviceServer) QueryDeviceList(ctx context.Context, request *device.QueryDeviceListRequest) (*device.QueryDeviceListResponse, error) { func (s *DriverDeviceServer) QueryDeviceList(ctx context.Context, request *device.QueryDeviceListRequest) (*device.QueryDeviceListResponse, error) {
deviceItf := container.DeviceItfFrom(s.dic.Get) deviceItf := container.DeviceItfFrom(s.dic.Get)
var platform string var platform string
if request.BaseRequest.UseCloudPlatform { if request.BaseRequest.UseCloudPlatform {
platform = string(constants.TransformEdgePlatformToDbPlatform(request.BaseRequest.GetCloudInstanceInfo().GetIotPlatform())) platform = string(constants.TransformEdgePlatformToDbPlatform(request.BaseRequest.GetCloudInstanceInfo().GetIotPlatform()))
@ -81,7 +81,7 @@ func (s *DriverDeviceServer) QueryDeviceList(ctx context.Context, request *devic
func (s *DriverDeviceServer) QueryDeviceById(ctx context.Context, request *device.QueryDeviceByIdRequest) (*device.QueryDeviceByIdResponse, error) { func (s *DriverDeviceServer) QueryDeviceById(ctx context.Context, request *device.QueryDeviceByIdRequest) (*device.QueryDeviceByIdResponse, error) {
deviceItf := container.DeviceItfFrom(s.dic.Get) deviceItf := container.DeviceItfFrom(s.dic.Get)
deviceInfo, err := deviceItf.DeviceModelById(ctx, request.Id) deviceInfo, err := deviceItf.DeviceModelById(ctx, request.Id)
response := new(device.QueryDeviceByIdResponse) response := new(device.QueryDeviceByIdResponse)
response.BaseResponse = new(drivercommon.CommonResponse) response.BaseResponse = new(drivercommon.CommonResponse)
@ -110,13 +110,13 @@ 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
} }
var insertDevice dtos.DeviceAddRequest var insertDevice dtos.DeviceAddRequest
insertDevice.ProductId = productInfo.Id insertDevice.ProductId = productInfo.Id
insertDevice.Platform = constants.IotPlatform_LocalIot insertDevice.Platform = constants.IotPlatform_LocalIot
insertDevice.Name = request.Device.Name insertDevice.Name = request.Device.Name
insertDevice.DriverInstanceId = request.BaseRequest.GetDriverInstanceId() insertDevice.DriverInstanceId = request.BaseRequest.GetDriverInstanceId()
deviceId, err := deviceItf.AddDevice(ctx, insertDevice) deviceId, err := deviceItf.AddDevice(ctx, insertDevice)
if err != nil { if err != nil {
errWrapper := errort.NewCommonEdgeXWrapper(err) errWrapper := errort.NewCommonEdgeXWrapper(err)
@ -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

@ -78,39 +78,39 @@ func NewBootstrap(router *gin.Engine) *Bootstrap {
} }
func (b *Bootstrap) BootstrapHandler(ctx context.Context, wg *sync.WaitGroup, _ startup.Timer, dic *di.Container) bool { func (b *Bootstrap) BootstrapHandler(ctx context.Context, wg *sync.WaitGroup, _ startup.Timer, dic *di.Container) bool {
configuration := container.ConfigurationFrom(dic.Get) configuration := container.ConfigurationFrom(dic.Get)
lc := pkgContainer.LoggingClientFrom(dic.Get) lc := pkgContainer.LoggingClientFrom(dic.Get)
if !b.initClient(ctx, wg, dic, configuration, lc) { if !b.initClient(ctx, wg, dic, configuration, lc) {
return false return false
} }
// rpc 服务 // rpc 服务
if ok := initRPCServer(ctx, wg, dic); !ok { if ok := initRPCServer(ctx, wg, dic); !ok {
return false return false
} }
lc.Infof("init rpc server") lc.Infof("init rpc server")
// http 路由 // http 路由
route.LoadRestRoutes(b.router, dic) route.LoadRestRoutes(b.router, dic)
// 业务逻辑 // 业务逻辑
application.InitSchedule(dic, lc) application.InitSchedule(dic, lc)
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
<-ctx.Done() <-ctx.Done()
crontab.Stop() crontab.Stop()
}() }()
return true return true
} }
func (b *Bootstrap) initClient(ctx context.Context, wg *sync.WaitGroup, dic *di.Container, configuration *config.ConfigurationStruct, lc logger.LoggingClient) bool { func (b *Bootstrap) initClient(ctx context.Context, wg *sync.WaitGroup, dic *di.Container, configuration *config.ConfigurationStruct, lc logger.LoggingClient) bool {
appMode, err := dmi.New(dic, ctx, wg, dtos.DriverConfigManage{ appMode, err := dmi.New(dic, ctx, wg, dtos.DriverConfigManage{
DockerManageConfig: dtos.DockerManageConfig{ DockerManageConfig: dtos.DockerManageConfig{
ContainerConfigPath: configuration.DockerManage.ContainerConfigPath, ContainerConfigPath: configuration.DockerManage.ContainerConfigPath,
@ -124,7 +124,7 @@ func (b *Bootstrap) initClient(ctx context.Context, wg *sync.WaitGroup, dic *di.
lc.Error("create driver model interface error %v", err) lc.Error("create driver model interface error %v", err)
return false return false
} }
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
interfaces.DriverModelInterfaceName: func(get di.Get) interface{} { interfaces.DriverModelInterfaceName: func(get di.Get) interface{} {
return appMode return appMode
@ -136,147 +136,147 @@ func (b *Bootstrap) initClient(ctx context.Context, wg *sync.WaitGroup, dic *di.
return homePageApp return homePageApp
}, },
}) })
languageApp := languagesdkapp.NewLanguageSDKApp(ctx, dic) languageApp := languagesdkapp.NewLanguageSDKApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.LanguageSDKAppName: func(get di.Get) interface{} { container.LanguageSDKAppName: func(get di.Get) interface{} {
return languageApp return languageApp
}, },
}) })
monitorApp := monitor.NewMonitor(ctx, dic) monitorApp := monitor.NewMonitor(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.MonitorAppName: func(get di.Get) interface{} { container.MonitorAppName: func(get di.Get) interface{} {
return monitorApp return monitorApp
}, },
}) })
streamClient := streamclient.NewStreamClient(lc) streamClient := streamclient.NewStreamClient(lc)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
pkgContainer.StreamClientName: func(get di.Get) interface{} { pkgContainer.StreamClientName: func(get di.Get) interface{} {
return streamClient return streamClient
}, },
}) })
driverApp := driverapp.NewDriverApp(ctx, dic) driverApp := driverapp.NewDriverApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.DriverAppName: func(get di.Get) interface{} { container.DriverAppName: func(get di.Get) interface{} {
return driverApp return driverApp
}, },
}) })
driverServiceApp := driverserviceapp.NewDriverServiceApp(ctx, dic) driverServiceApp := driverserviceapp.NewDriverServiceApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.DriverServiceAppName: func(get di.Get) interface{} { container.DriverServiceAppName: func(get di.Get) interface{} {
return driverServiceApp return driverServiceApp
}, },
}) })
productApp := productapp.NewProductApp(ctx, dic) productApp := productapp.NewProductApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.ProductAppName: func(get di.Get) interface{} { container.ProductAppName: func(get di.Get) interface{} {
return productApp return productApp
}, },
}) })
thingModelApp := thingmodelapp.NewThingModelApp(ctx, dic) thingModelApp := thingmodelapp.NewThingModelApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.ThingModelAppName: func(get di.Get) interface{} { container.ThingModelAppName: func(get di.Get) interface{} {
return thingModelApp return thingModelApp
}, },
}) })
deviceApp := deviceapp.NewDeviceApp(ctx, dic) deviceApp := deviceapp.NewDeviceApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.DeviceItfName: func(get di.Get) interface{} { container.DeviceItfName: func(get di.Get) interface{} {
return deviceApp return deviceApp
}, },
}) })
alertCentreApp := alertcentreapp.NewAlertCentreApp(ctx, dic) alertCentreApp := alertcentreapp.NewAlertCentreApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.AlertRuleAppName: func(get di.Get) interface{} { container.AlertRuleAppName: func(get di.Get) interface{} {
return alertCentreApp return alertCentreApp
}, },
}) })
ruleEngineApp := ruleengine.NewRuleEngineApp(ctx, dic) ruleEngineApp := ruleengine.NewRuleEngineApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.RuleEngineAppName: func(get di.Get) interface{} { container.RuleEngineAppName: func(get di.Get) interface{} {
return ruleEngineApp return ruleEngineApp
}, },
}) })
sceneApp := scene.NewSceneApp(ctx, dic) sceneApp := scene.NewSceneApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.SceneAppName: func(get di.Get) interface{} { container.SceneAppName: func(get di.Get) interface{} {
return sceneApp return sceneApp
}, },
}) })
conJobApp := timerapp.NewCronTimer(ctx, jobrunner.NewJobRunFunc(dic), dic) conJobApp := timerapp.NewCronTimer(ctx, jobrunner.NewJobRunFunc(dic), dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.ConJobAppName: func(get di.Get) interface{} { container.ConJobAppName: func(get di.Get) interface{} {
return conJobApp return conJobApp
}, },
}) })
dataResourceApp := dataresource.NewDataResourceApp(ctx, dic) dataResourceApp := dataresource.NewDataResourceApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.DataResourceName: func(get di.Get) interface{} { container.DataResourceName: func(get di.Get) interface{} {
return dataResourceApp return dataResourceApp
}, },
}) })
cosApp := cos.NewCos("", "", "") cosApp := cos.NewCos("", "", "")
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.CosAppName: func(get di.Get) interface{} { container.CosAppName: func(get di.Get) interface{} {
return cosApp return cosApp
}, },
}) })
categoryTemplateApp := categorytemplate.NewCategoryTemplateApp(ctx, dic) categoryTemplateApp := categorytemplate.NewCategoryTemplateApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.CategoryTemplateAppName: func(get di.Get) interface{} { container.CategoryTemplateAppName: func(get di.Get) interface{} {
return categoryTemplateApp return categoryTemplateApp
}, },
}) })
unitTemplateApp := unittemplate.NewUnitTemplateApp(ctx, dic) unitTemplateApp := unittemplate.NewUnitTemplateApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.UnitTemplateAppName: func(get di.Get) interface{} { container.UnitTemplateAppName: func(get di.Get) interface{} {
return unitTemplateApp return unitTemplateApp
}, },
}) })
docsApp := docapp.NewDocsApp(ctx, dic) docsApp := docapp.NewDocsApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.DocsAppName: func(get di.Get) interface{} { container.DocsAppName: func(get di.Get) interface{} {
return docsApp return docsApp
}, },
}) })
quickNavigationApp := quicknavigationapp.NewQuickNavigationApp(ctx, dic) quickNavigationApp := quicknavigationapp.NewQuickNavigationApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.QuickNavigationAppName: func(get di.Get) interface{} { container.QuickNavigationAppName: func(get di.Get) interface{} {
return quickNavigationApp return quickNavigationApp
}, },
}) })
thingModelTemplateApp := thingmodeltemplate.NewThingModelTemplateApp(ctx, dic) thingModelTemplateApp := thingmodeltemplate.NewThingModelTemplateApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.ThingModelTemplateAppName: func(get di.Get) interface{} { container.ThingModelTemplateAppName: func(get di.Get) interface{} {
return thingModelTemplateApp return thingModelTemplateApp
}, },
}) })
hpcloudServiceApp := hpcloudclient.NewHpcloud(lc) hpcloudServiceApp := hpcloudclient.NewHpcloud(lc)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.HpcServiceAppName: func(get di.Get) interface{} { container.HpcServiceAppName: func(get di.Get) interface{} {
return hpcloudServiceApp return hpcloudServiceApp
}, },
}) })
smsServiceApp := sms.NewSmsClient(lc, "", smsServiceApp := sms.NewSmsClient(lc, "",
"", "") "", "")
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
@ -284,21 +284,21 @@ func (b *Bootstrap) initClient(ctx context.Context, wg *sync.WaitGroup, dic *di.
return smsServiceApp return smsServiceApp
}, },
}) })
limitMethodApp := application.NewLimitMethodConf(*configuration) limitMethodApp := application.NewLimitMethodConf(*configuration)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
pkgContainer.LimitMethodConfName: func(get di.Get) interface{} { pkgContainer.LimitMethodConfName: func(get di.Get) interface{} {
return limitMethodApp return limitMethodApp
}, },
}) })
ekuiperApp := ekuiperclient.New(configuration.Clients["Ekuiper"].Address(), lc) ekuiperApp := ekuiperclient.New(configuration.Clients["Ekuiper"].Address(), lc)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.EkuiperAppName: func(get di.Get) interface{} { container.EkuiperAppName: func(get di.Get) interface{} {
return ekuiperApp return ekuiperApp
}, },
}) })
//agentApp := agentclient.New(configuration.Clients["Agent"].Address()) //agentApp := agentclient.New(configuration.Clients["Agent"].Address())
//dic.Update(di.ServiceConstructorMap{ //dic.Update(di.ServiceConstructorMap{
// container.AgentClientName: func(get di.Get) interface{} { // container.AgentClientName: func(get di.Get) interface{} {
@ -312,28 +312,28 @@ func (b *Bootstrap) initClient(ctx context.Context, wg *sync.WaitGroup, dic *di.
// return cacheClient // return cacheClient
// }, // },
//}) //})
persistItf := persistence.NewPersistApp(dic) persistItf := persistence.NewPersistApp(dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.PersistItfName: func(get di.Get) interface{} { container.PersistItfName: func(get di.Get) interface{} {
return persistItf return persistItf
}, },
}) })
userItf := userapp.New(dic) userItf := userapp.New(dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.UserItfName: func(get di.Get) interface{} { container.UserItfName: func(get di.Get) interface{} {
return userItf return userItf
}, },
}) })
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
}, },
}) })
messageStoreItf := messagestore.NewMessageStore(dic) messageStoreItf := messagestore.NewMessageStore(dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.MessageStoreItfName: func(get di.Get) interface{} { container.MessageStoreItfName: func(get di.Get) interface{} {

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"
@ -10,7 +12,7 @@ import (
"strconv" "strconv"
"sync" "sync"
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -38,12 +40,12 @@ func NewWebBootstrap() *WebBootstrap {
func (b *WebBootstrap) BootstrapHandler(ctx context.Context, wg *sync.WaitGroup, _ startup.Timer, dic *di.Container) bool { func (b *WebBootstrap) BootstrapHandler(ctx context.Context, wg *sync.WaitGroup, _ startup.Timer, dic *di.Container) bool {
configuration := container.ConfigurationFrom(dic.Get) configuration := container.ConfigurationFrom(dic.Get)
lc := pkgContainer.LoggingClientFrom(dic.Get) lc := pkgContainer.LoggingClientFrom(dic.Get)
lc.Infof("start WebBootstrap BootstrapHandler in...") lc.Infof("start WebBootstrap BootstrapHandler in...")
//pwd, _ := os.Getwd() //pwd, _ := os.Getwd()
LoadWebProxyRoutes(b.router, WebBuildPath, dic) LoadWebProxyRoutes(b.router, WebBuildPath, dic)
if configuration.WebServer.Host == "" || configuration.WebServer.Port == 0 { if configuration.WebServer.Host == "" || configuration.WebServer.Port == 0 {
lc.Errorf("WebServer Host is null OR port is 0") lc.Errorf("WebServer Host is null OR port is 0")
return false return false
@ -57,25 +59,33 @@ func (b *WebBootstrap) BootstrapHandler(ctx context.Context, wg *sync.WaitGroup,
WriteTimeout: timeout, WriteTimeout: timeout,
ReadTimeout: timeout, ReadTimeout: timeout,
} }
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
<-ctx.Done() <-ctx.Done()
lc.Info("WebProxy server shutting down") lc.Info("WebProxy server shutting down")
_ = server.Shutdown(context.Background()) _ = server.Shutdown(context.Background())
lc.Info("WebProxy server shut down") lc.Info("WebProxy server shut down")
}() }()
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() {
defer func() { defer func() {
wg.Done() wg.Done()
}() }()
err := server.ListenAndServe() err := server.ListenAndServe()
if err != nil { if err != nil {
lc.Errorf("WebProxy server failed: %v", err) lc.Errorf("WebProxy server failed: %v", err)
@ -85,6 +95,11 @@ func (b *WebBootstrap) BootstrapHandler(ctx context.Context, wg *sync.WaitGroup,
lc.Info("WebProxy server stopped") lc.Info("WebProxy server stopped")
} }
}() }()
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