fix 依赖库, 如果连接报错,就会拒绝服务的问题

This commit is contained in:
wangjian 2023-04-05 21:01:46 +08:00
parent efe86e04d2
commit cfff372541
3 changed files with 34 additions and 22 deletions

View File

@ -10,11 +10,13 @@ import (
"syscall"
"git.hpds.cc/pavement/hpds_node"
discover "hpds_mq/internal/discover/consul"
)
const (
AppLogPrefix = "\033[33m[hpds-mq:app]\033[0m "
)
var (
consulConfigs chan *discover.ConsulConfig
ConfigFileFlag string = "./config/config.yml"
ConsulAddress string = "http://localhost:8500"
NodeName string = "main-node"
@ -23,7 +25,7 @@ var (
func must(err error) {
if err != nil {
fmt.Fprint(os.Stderr, err)
_, _ = fmt.Fprint(os.Stderr, err)
os.Exit(1)
}
}
@ -82,11 +84,13 @@ func NewStartCmd() *cobra.Command {
mq, err := hpds_node.NewMq(configFileFlag)
must(err)
mq.InitOptions(hpds_node.WithAuth("token", cfg.Token))
defer mq.Close()
defer func() {
_ = mq.Close()
}()
if len(cfg.CascadeNode) > 0 {
for i := 0; i < len(cfg.CascadeNode); i++ {
mq.AddDownstreamMq(hpds_node.NewDownstreamMq(
_ = mq.AddDownstreamMq(hpds_node.NewDownstreamMq(
cfg.CascadeNode[i].Name,
hpds_node.WithMqAddr(fmt.Sprintf("%s:%d", cfg.CascadeNode[i].Host, cfg.CascadeNode[i].Port)),
hpds_node.WithCredential(fmt.Sprintf("token:%s", cfg.CascadeNode[i].Token)),
@ -94,11 +98,12 @@ func NewStartCmd() *cobra.Command {
}
}
// start mq service
log.Printf("Server has started!, pid: %d", os.Getpid())
log.Infof("%s Server has started!, pid: %d", os.Getpid())
go func() {
err = mq.ListenAndServe()
if err != nil {
panic(err)
log.Errorf("%s %s error %s", AppLogPrefix, cfg.Name, err.Error())
os.Exit(-1)
}
}()
select {}

View File

@ -16,6 +16,8 @@ functions:
- name: task-request
- name: task-response
- name: task-execute
- name: dataset-request
- name: capture-agent
logging:
path: ./logs
prefix: mq-node

35
go.mod
View File

@ -3,8 +3,8 @@ module hpds_mq
go 1.19
require (
git.hpds.cc/Component/network v0.0.0-20230402152327-d10a80765e7c
git.hpds.cc/pavement/hpds_node v0.0.0-20230402152619-41414aafa930
git.hpds.cc/Component/network v0.0.0-20230405125523-abb93c020ff5
git.hpds.cc/pavement/hpds_node v0.0.0-20230405125907-be7c3e11c61e
github.com/hashicorp/consul/api v1.15.3
github.com/spf13/cobra v1.6.0
github.com/spf13/viper v1.13.0
@ -27,6 +27,7 @@ require (
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/googleapis/gax-go/v2 v2.4.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.2.0 // indirect
@ -37,10 +38,7 @@ require (
github.com/hashicorp/serf v0.9.7 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/lucas-clemente/quic-go v0.29.1 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/marten-seemann/qtls-go1-18 v0.1.2 // indirect
github.com/marten-seemann/qtls-go1-19 v0.1.0 // indirect
github.com/matoous/go-nanoid/v2 v2.0.0 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
@ -48,11 +46,13 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/onsi/ginkgo v1.16.4 // indirect
github.com/onsi/ginkgo/v2 v2.2.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/quic-go/qtls-go1-19 v0.2.1 // indirect
github.com/quic-go/qtls-go1-20 v0.1.1 // indirect
github.com/quic-go/quic-go v0.33.0 // indirect
github.com/sagikazarmark/crypt v0.6.0 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
@ -67,14 +67,14 @@ require (
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.23.0 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect
golang.org/x/crypto v0.4.0 // indirect
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect
golang.org/x/mod v0.6.0 // indirect
golang.org/x/net v0.4.0 // indirect
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.10 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
golang.org/x/tools v0.2.0 // indirect
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect
google.golang.org/api v0.81.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
@ -83,6 +83,11 @@ require (
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
//
//replace (
// git.hpds.cc/Component/network => ../network
// git.hpds.cc/pavement/hpds_node => ../hpds_node
//)