feat(middle-msg): update middle msg
This commit is contained in:
parent
e94a41ec73
commit
780cf7d276
|
@ -23,8 +23,14 @@ func SendMiddleMsg(
|
||||||
var eventName string
|
var eventName string
|
||||||
|
|
||||||
switch val.(type) {
|
switch val.(type) {
|
||||||
case LogContext:
|
case *LogContext:
|
||||||
eventName = EventNameLog
|
eventName = LogContextName
|
||||||
|
case *LruCleanContext:
|
||||||
|
eventName = LruCleanContextName
|
||||||
|
case *LruTTlContext:
|
||||||
|
eventName = LruTTlContextName
|
||||||
|
case *PulginsInfo:
|
||||||
|
eventName = PulginsInfoname
|
||||||
}
|
}
|
||||||
|
|
||||||
msgEvent := event.NewEvent(eventName)
|
msgEvent := event.NewEvent(eventName)
|
||||||
|
|
|
@ -3,7 +3,7 @@ package middlemsg
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
EventNameLog = "log-context"
|
LogContextName = "log-context"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LogContext struct {
|
type LogContext struct {
|
||||||
|
|
|
@ -4,14 +4,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// []pulginsINfo
|
|
||||||
// 1. Version
|
|
||||||
// 2. desc
|
|
||||||
// 3. Name
|
|
||||||
// 4. 运行状态
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
EventNamePlug = "plugins-info"
|
PulginsInfoname = "plugins-info-context"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PulginsInfo struct {
|
type PulginsInfo struct {
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
package middle
|
package middle
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
|
|
||||||
_ "gitee.com/timedb/wheatCache/conf"
|
_ "gitee.com/timedb/wheatCache/conf"
|
||||||
"gitee.com/timedb/wheatCache/pkg/event"
|
"gitee.com/timedb/wheatCache/pkg/event"
|
||||||
"gitee.com/timedb/wheatCache/pkg/logx"
|
|
||||||
middleMsg "gitee.com/timedb/wheatCache/pkg/middle-msg"
|
|
||||||
"gitee.com/timedb/wheatCache/plugins"
|
"gitee.com/timedb/wheatCache/plugins"
|
||||||
"gitee.com/timedb/wheatCache/plugins/config"
|
"gitee.com/timedb/wheatCache/plugins/config"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
@ -76,24 +72,3 @@ func loadConfigAndDefault() (int, int) {
|
||||||
}
|
}
|
||||||
return consumerCount, driverCount
|
return consumerCount, driverCount
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MiddleWare) startWork() {
|
|
||||||
|
|
||||||
for i := 0; i < m.consumerCount; i++ {
|
|
||||||
go func() {
|
|
||||||
ctx := context.Background()
|
|
||||||
for {
|
|
||||||
workEvent := m.eventConsumer.Receive(ctx)
|
|
||||||
plugs := m.plugins[workEvent.GetEventName()]
|
|
||||||
msg, ok := workEvent.GetValue(middleMsg.MiddleMsgKey)
|
|
||||||
if !ok {
|
|
||||||
logx.With(ctx, m.eventProduce).Error("get event value err,not key:%s", middleMsg.MiddleMsgKey)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for _, val := range plugs {
|
|
||||||
val.Exec(msg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package middle
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"gitee.com/timedb/wheatCache/pkg/logx"
|
||||||
|
middleMsg "gitee.com/timedb/wheatCache/pkg/middle-msg"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (m *MiddleWare) startWork() {
|
||||||
|
|
||||||
|
for i := 0; i < m.consumerCount; i++ {
|
||||||
|
go func() {
|
||||||
|
ctx := context.Background()
|
||||||
|
for {
|
||||||
|
workEvent := m.eventConsumer.Receive(ctx)
|
||||||
|
plugs := m.plugins[workEvent.GetEventName()]
|
||||||
|
msg, ok := workEvent.GetValue(middleMsg.MiddleMsgKey)
|
||||||
|
if !ok {
|
||||||
|
logx.With(ctx, m.eventProduce).Error("get event value err,not key:%s", middleMsg.MiddleMsgKey)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发送事件到 全部的 plugs 里
|
||||||
|
for _, val := range plugs {
|
||||||
|
_, err := val.Exec(msg)
|
||||||
|
if err != nil {
|
||||||
|
logx.With(ctx, m.eventProduce).Errorln(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue