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.
85 lines
2.8 KiB
85 lines
2.8 KiB
4 years ago
|
package logic
|
||
|
|
||
|
import (
|
||
3 years ago
|
"Open_IM/pkg/common/config"
|
||
3 years ago
|
"Open_IM/pkg/common/constant"
|
||
3 years ago
|
"Open_IM/pkg/common/kafka"
|
||
2 years ago
|
promePkg "Open_IM/pkg/common/prometheus"
|
||
3 years ago
|
"Open_IM/pkg/statistics"
|
||
3 years ago
|
"fmt"
|
||
3 years ago
|
"sync"
|
||
4 years ago
|
)
|
||
|
|
||
3 years ago
|
const OnlineTopicBusy = 1
|
||
|
const OnlineTopicVacancy = 0
|
||
3 years ago
|
const Msg = 2
|
||
3 years ago
|
const ConsumerMsgs = 3
|
||
3 years ago
|
const AggregationMessages = 4
|
||
3 years ago
|
const MongoMessages = 5
|
||
3 years ago
|
const ChannelNum = 100
|
||
3 years ago
|
|
||
4 years ago
|
var (
|
||
3 years ago
|
persistentCH PersistentConsumerHandler
|
||
2 years ago
|
historyCH OnlineHistoryRedisConsumerHandler
|
||
|
historyMongoCH OnlineHistoryMongoConsumerHandler
|
||
2 years ago
|
modifyCH ModifyMsgConsumerHandler
|
||
3 years ago
|
producer *kafka.Producer
|
||
2 years ago
|
producerToModify *kafka.Producer
|
||
2 years ago
|
producerToMongo *kafka.Producer
|
||
3 years ago
|
cmdCh chan Cmd2Value
|
||
3 years ago
|
onlineTopicStatus int
|
||
3 years ago
|
w *sync.Mutex
|
||
|
singleMsgSuccessCount uint64
|
||
|
groupMsgCount uint64
|
||
|
singleMsgFailedCount uint64
|
||
3 years ago
|
|
||
|
singleMsgSuccessCountMutex sync.Mutex
|
||
4 years ago
|
)
|
||
|
|
||
|
func Init() {
|
||
3 years ago
|
cmdCh = make(chan Cmd2Value, 10000)
|
||
3 years ago
|
w = new(sync.Mutex)
|
||
2 years ago
|
if config.Config.Prometheus.Enable {
|
||
|
initPrometheus()
|
||
|
}
|
||
2 years ago
|
persistentCH.Init() // ws2mschat save mysql
|
||
|
historyCH.Init(cmdCh) //
|
||
2 years ago
|
historyMongoCH.Init()
|
||
2 years ago
|
modifyCH.Init()
|
||
3 years ago
|
onlineTopicStatus = OnlineTopicVacancy
|
||
3 years ago
|
//offlineHistoryCH.Init(cmdCh)
|
||
3 years ago
|
statistics.NewStatistics(&singleMsgSuccessCount, config.Config.ModuleName.MsgTransferName, fmt.Sprintf("%d second singleMsgCount insert to mongo", constant.StatisticsTimeInterval), constant.StatisticsTimeInterval)
|
||
|
statistics.NewStatistics(&groupMsgCount, config.Config.ModuleName.MsgTransferName, fmt.Sprintf("%d second groupMsgCount insert to mongo", constant.StatisticsTimeInterval), constant.StatisticsTimeInterval)
|
||
4 years ago
|
producer = kafka.NewKafkaProducer(config.Config.Kafka.Ms2pschat.Addr, config.Config.Kafka.Ms2pschat.Topic)
|
||
2 years ago
|
producerToModify = kafka.NewKafkaProducer(config.Config.Kafka.MsgToModify.Addr, config.Config.Kafka.MsgToModify.Topic)
|
||
2 years ago
|
producerToMongo = kafka.NewKafkaProducer(config.Config.Kafka.MsgToMongo.Addr, config.Config.Kafka.MsgToMongo.Topic)
|
||
4 years ago
|
}
|
||
2 years ago
|
func Run(promethuesPort int) {
|
||
4 years ago
|
//register mysqlConsumerHandler to
|
||
3 years ago
|
if config.Config.ChatPersistenceMysql {
|
||
|
go persistentCH.persistentConsumerGroup.RegisterHandleAndConsumer(&persistentCH)
|
||
|
} else {
|
||
|
fmt.Println("not start mysql consumer")
|
||
|
}
|
||
4 years ago
|
go historyCH.historyConsumerGroup.RegisterHandleAndConsumer(&historyCH)
|
||
2 years ago
|
go historyMongoCH.historyConsumerGroup.RegisterHandleAndConsumer(&historyMongoCH)
|
||
2 years ago
|
go modifyCH.modifyMsgConsumerGroup.RegisterHandleAndConsumer(&modifyCH)
|
||
3 years ago
|
//go offlineHistoryCH.historyConsumerGroup.RegisterHandleAndConsumer(&offlineHistoryCH)
|
||
2 years ago
|
go func() {
|
||
|
err := promePkg.StartPromeSrv(promethuesPort)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
}()
|
||
3 years ago
|
}
|
||
3 years ago
|
func SetOnlineTopicStatus(status int) {
|
||
3 years ago
|
w.Lock()
|
||
|
defer w.Unlock()
|
||
|
onlineTopicStatus = status
|
||
|
}
|
||
3 years ago
|
func GetOnlineTopicStatus() int {
|
||
3 years ago
|
w.Lock()
|
||
|
defer w.Unlock()
|
||
|
return onlineTopicStatus
|
||
4 years ago
|
}
|