seaweedfs/weed/notification/configuration.go

44 lines
994 B
Go
Raw Normal View History

2018-09-16 16:18:30 +08:00
package notification
2018-08-13 16:20:49 +08:00
import (
"github.com/chrislusf/seaweedfs/weed/glog"
2018-09-16 16:37:35 +08:00
"github.com/chrislusf/seaweedfs/weed/util"
"github.com/golang/protobuf/proto"
2018-09-21 16:56:43 +08:00
"github.com/spf13/viper"
2018-08-13 16:20:49 +08:00
)
2018-09-16 16:37:35 +08:00
type MessageQueue interface {
// GetName gets the name to locate the configuration in filer.toml file
GetName() string
// Initialize initializes the file store
Initialize(configuration util.Configuration) error
SendMessage(key string, message proto.Message) error
}
2018-08-13 16:20:49 +08:00
var (
MessageQueues []MessageQueue
Queue MessageQueue
)
func LoadConfiguration(config *viper.Viper) {
2018-08-13 16:20:49 +08:00
2018-08-23 14:54:00 +08:00
if config == nil {
return
}
2018-08-13 16:20:49 +08:00
for _, store := range MessageQueues {
if config.GetBool(store.GetName() + ".enabled") {
viperSub := config.Sub(store.GetName())
2018-08-13 16:20:49 +08:00
if err := store.Initialize(viperSub); err != nil {
glog.Fatalf("Failed to initialize store for %s: %+v",
store.GetName(), err)
}
Queue = store
glog.V(0).Infof("Configure notification message queue for %s", store.GetName())
2018-08-13 16:20:49 +08:00
return
}
}
}