1 Star 0 Fork 27

大树伦/wmq-go

forked from 狂奔的蜗牛./wmq-go 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
wmq.go 1.88 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"time"
logger "github.com/snail007/mini-logger"
"fmt"
"os"
)
const (
poolInitialCap = 5
poolMaxCap = 300
poolChannelInitialCap = 10
poolChannelMaxCap = 1000
)
var (
uri = ""
mqHeartbeat = time.Second * 2
mqConnectionAndDeadlineTimeout = time.Second * 4
mqConnectionFailRetrySleep = time.Second * 3
messageDataFilePath = ""
messages = []message{}
)
func panicHandler(output string) {
fmt.Println("called" + output)
}
func main() {
ctx := log.With(logger.Fields{"func": "main"})
ctx.Info("WMQ Service Started")
initConsumerManager()
if err := initMessages(); err != nil {
ctx.With(logger.Fields{"call": "initMessages()"}).Fatalln("%s", err)
}
if !cfg.GetBool("api-disable") {
//init api service
go serveAPI(cfg.GetString("listen.api"), cfg.GetString("api.token"))
}
//init publish service
go servePublish(cfg.GetString("listen.publish"))
select {}
}
func init() {
fmt.Println(poster())
var err error
err = initConfig()
if err != nil {
fmt.Printf("%s", err)
os.Exit(0)
}
initLog()
ctx := log.With(logger.Fields{"func": "init"})
vhost := cfg.GetString("rabbitmq.vhost")
if vhost != "/" {
vhost = "/" + vhost
}
uri = fmt.Sprintf("amqp://%s:%s@%s:%d%s",
cfg.GetString("rabbitmq.username"),
cfg.GetString("rabbitmq.password"),
cfg.GetString("rabbitmq.host"),
cfg.GetInt("rabbitmq.port"),
vhost)
messageDataFilePath = cfg.GetString("consume.DataFile")
messages, err = loadMessagesFromFile(messageDataFilePath)
if err != nil {
ctx.Safe().Fatalf("load message data form file fail [%s],%s", messageDataFilePath, err)
}
if err = initPool(); err != nil {
ctx.Safe().Fatalf("init connection to rabbitmq fail : %s", err)
}
if err = initChannelPool(); err != nil {
ctx.Safe().Fatalf("init Channel Pool fail : %s", err)
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/alalun/wmq-go.git
git@gitee.com:alalun/wmq-go.git
alalun
wmq-go
wmq-go
master

搜索帮助