add pulsar client

This commit is contained in:
w1ndyb0y
2021-02-01 15:35:13 +08:00
parent 9a14fb2cef
commit 3ad4c76acd
8 changed files with 246 additions and 5 deletions
+15
View File
@@ -42,6 +42,13 @@ var (
socketAddress string
pulsarUrl string
topic string
name string
tcp bool
pulsar bool
// rootCmd represents the base command when called without any subcommands
rootCmd = &cobra.Command{
Use: "tele-recv",
@@ -109,6 +116,14 @@ func initConfig() {
dbFile = viper.GetString("sqlite.file")
dbInit = viper.GetBool("sqlite.init")
socketAddress = viper.GetString("socket.address")
pulsarUrl = viper.GetString("pulsar.url")
topic = viper.GetString("pulsar.topic")
name = viper.GetString("pulsar.name")
tcp = viper.GetBool("telegram.tcp")
utils.Tcp = tcp
pulsar = viper.GetBool("telegram.pulsar")
utils.Pulsar = pulsar
}
}
+9 -2
View File
@@ -72,7 +72,12 @@ func start() {
sig := <-sigs
logger.Info("got ", zap.Any("signal", sig))
utils.ServerRunning = false
utils.StopSocketServer()
if tcp {
utils.StopSocketServer()
}
if pulsar {
utils.ClosePulsar()
}
done <- true
}()
@@ -81,7 +86,9 @@ func start() {
// above sending a value on `done`) and then exit.
logger.Info("awaiting signal")
_ = utils.InitDb(dbFile, dbInit)
go utils.Listen(socketAddress)
if tcp {
go utils.Listen(socketAddress)
}
for utils.ServerRunning {
if !utils.IsPortOpen() {
logger.Info("try to open port")