2018-09-16 08:18:30 +00:00
|
|
|
package notification
|
2018-08-13 08:20:49 +00:00
|
|
|
|
|
|
|
import (
|
2018-09-16 08:37:35 +00:00
|
|
|
"github.com/golang/protobuf/proto"
|
2022-07-29 07:17:28 +00:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
2018-08-13 08:20:49 +00:00
|
|
|
)
|
|
|
|
|
2018-09-16 08:37:35 +00:00
|
|
|
type MessageQueue interface {
|
|
|
|
// GetName gets the name to locate the configuration in filer.toml file
|
|
|
|
GetName() string
|
|
|
|
// Initialize initializes the file store
|
2020-01-29 17:09:55 +00:00
|
|
|
Initialize(configuration util.Configuration, prefix string) error
|
2018-09-16 08:37:35 +00:00
|
|
|
SendMessage(key string, message proto.Message) error
|
|
|
|
}
|
|
|
|
|
2018-08-13 08:20:49 +00:00
|
|
|
var (
|
|
|
|
MessageQueues []MessageQueue
|
|
|
|
|
|
|
|
Queue MessageQueue
|
|
|
|
)
|
|
|
|
|
2021-01-12 10:28:13 +00:00
|
|
|
func LoadConfiguration(config *util.ViperProxy, prefix string) {
|
2018-08-13 08:20:49 +00:00
|
|
|
|
2018-08-23 06:54:00 +00:00
|
|
|
if config == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-12-06 08:44:41 +00:00
|
|
|
validateOneEnabledQueue(config)
|
2018-12-06 08:37:59 +00:00
|
|
|
|
|
|
|
for _, queue := range MessageQueues {
|
2020-01-29 17:09:55 +00:00
|
|
|
if config.GetBool(prefix + queue.GetName() + ".enabled") {
|
|
|
|
if err := queue.Initialize(config, prefix+queue.GetName()+"."); err != nil {
|
2018-12-06 07:24:25 +00:00
|
|
|
glog.Fatalf("Failed to initialize notification for %s: %+v",
|
2018-12-06 08:37:59 +00:00
|
|
|
queue.GetName(), err)
|
2018-08-13 08:20:49 +00:00
|
|
|
}
|
2018-12-06 08:37:59 +00:00
|
|
|
Queue = queue
|
|
|
|
glog.V(0).Infof("Configure notification message queue for %s", queue.GetName())
|
2018-08-13 08:20:49 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-12-06 08:44:41 +00:00
|
|
|
|
2021-01-12 10:28:13 +00:00
|
|
|
func validateOneEnabledQueue(config *util.ViperProxy) {
|
2018-12-06 08:44:41 +00:00
|
|
|
enabledQueue := ""
|
|
|
|
for _, queue := range MessageQueues {
|
|
|
|
if config.GetBool(queue.GetName() + ".enabled") {
|
|
|
|
if enabledQueue == "" {
|
|
|
|
enabledQueue = queue.GetName()
|
|
|
|
} else {
|
|
|
|
glog.Fatalf("Notification message queue is enabled for both %s and %s", enabledQueue, queue.GetName())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|