You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.2 KiB
57 lines
1.2 KiB
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"goInOut/config"
|
|
"goInOut/consumers"
|
|
"io"
|
|
"log"
|
|
"os"
|
|
"time"
|
|
|
|
"gopkg.in/natefinch/lumberjack.v2"
|
|
)
|
|
|
|
func init() {
|
|
multiWriter := io.MultiWriter(os.Stdout, &lumberjack.Logger{
|
|
Filename: "./logs/logInfo.log",
|
|
MaxSize: 10, // megabytes
|
|
MaxBackups: 100,
|
|
MaxAge: 30, //days
|
|
//Compress: true,
|
|
})
|
|
log.SetFlags(log.LstdFlags | log.Lshortfile | log.Lmicroseconds)
|
|
log.SetOutput(multiWriter)
|
|
log.Println("=================log start=================")
|
|
}
|
|
|
|
func main() {
|
|
|
|
log.Println("进程启动")
|
|
|
|
//初始化读取配置
|
|
myConfigs := config.LoadConfig() //数据存储
|
|
for consumerName, consumerConfig := range myConfigs {
|
|
log.Printf("consumer [%s]", consumerName)
|
|
consumer := consumers.GetConsumer(consumerName)
|
|
if consumer == nil {
|
|
log.Printf("无匹配的consumer [%s] 请检查", consumerName)
|
|
continue
|
|
}
|
|
|
|
err := consumer.Initial(consumerConfig)
|
|
if err != nil {
|
|
log.Panic(fmt.Sprintf("[%s]初始化失败:%s", consumerName, err.Error()))
|
|
}
|
|
|
|
// 在独立的 goroutine 中运行每个消费者,使它们可以并行执行
|
|
go func(name string, c consumers.IConsumer) {
|
|
log.Printf("启动消费者: %s", name)
|
|
c.Work()
|
|
}(consumerName, consumer)
|
|
}
|
|
|
|
for {
|
|
time.Sleep(time.Hour)
|
|
}
|
|
}
|
|
|