Files
eagle/pkg/queue/kafka/config.go
Richard fb1b10bcf5 chore: improve kafka component (#180)
* feat: improve kafka component

* chore: revert test password

* docs: add changelog

* chore: upgrade sarama to IBM/sarama
2025-04-12 17:33:05 +08:00

64 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package kafka
import (
"sync"
cfg "github.com/go-eagle/eagle/pkg/config"
)
var (
loadOnce sync.Once
closeOnce sync.Once
conf map[string]*Conf
)
type Conf struct {
Version string `yaml:"Version"`
RequiredAcks int `yaml:"RequiredAcks"`
Topic string `yaml:"Topic"`
ConsumeTopic []string `yaml:"VonsumeTopic"`
Brokers []string `yaml:"Brokers"`
GroupID string `yaml:"GroupID"`
// partitioner typeoptional: "random", "roundrobin", "hash"
Partitioner string `yaml:"Partitioner"`
}
// loadConf load config
func loadConf() (ret map[string]*Conf, err error) {
v, err := cfg.LoadWithType("kafka", "yaml")
if err != nil {
return nil, err
}
c := make(map[string]*Conf, 0)
err = v.Unmarshal(&c)
if err != nil {
return nil, err
}
conf = c
return c, nil
}
func GetConfig() map[string]*Conf {
return conf
}
func Load() {
loadOnce.Do(func() {
conf, err := loadConf()
if err != nil {
panic(err)
}
DefaultManager = NewManager(conf)
})
}
func Close() {
closeOnce.Do(func() {
_ = DefaultManager.Close()
})
}