optimization: change the configuration file from being read globally … (#1935)
* optimization: change the configuration file from being read globally to being read independently. * optimization: change the configuration file from being read globally to being read independently. * optimization: change the configuration file from being read globally to being read independently. * optimization: config file changed to dependency injection. * fix: replace global config with dependency injection * fix: replace global config with dependency injection * fix: import the enough param * fix: import the enough param * fix: import the enough param * fix: fix the component check of path * fix: fix the kafka of tls is nil problem * fix: fix the TLS.CACrt is nil error * fix: fix the valiable shadows problem * fix: fix the comflect * optimization: message remove options. * fix: fix the param pass error * fix: find error * fix: find error * fix: find eror * fix: find error * fix: find error * fix: del the undifined func * fix: find error * fix: fix the error * fix: pass config * fix: find error * fix: find error * fix: find error * fix: find error * fix: find error * fix: fix the config * fix: fix the error * fix: fix the config pass error * fix: fix the eror * fix: fix the error * fix: fix the error * fix: fix the error * fix: find error * fix: fix the error * fix: fix the config * fix: add return err * fix: fix the err2 * fix: err * fix: fix the func * fix: del the chinese comment * fix: fix the func * fix: fix the gateway_test logic * fix: s3 * test * test * fix: not found --------- Co-authored-by: luhaoling <2198702716@qq.com> Co-authored-by: withchao <993506633@qq.com>
This commit is contained in:
@@ -17,6 +17,8 @@ package kafka
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
|
||||
"github.com/IBM/sarama"
|
||||
"github.com/OpenIMSDK/tools/errs"
|
||||
)
|
||||
@@ -29,22 +31,31 @@ type Consumer struct {
|
||||
Consumer sarama.Consumer
|
||||
}
|
||||
|
||||
func NewKafkaConsumer(addr []string, topic string, kafkaConfig *sarama.Config) (*Consumer, error) {
|
||||
p := Consumer{
|
||||
Topic: topic,
|
||||
addr: addr,
|
||||
func NewKafkaConsumer(addr []string, topic string, config *config.GlobalConfig) (*Consumer,error) {
|
||||
p := Consumer{}
|
||||
p.Topic = topic
|
||||
p.addr = addr
|
||||
consumerConfig := sarama.NewConfig()
|
||||
if config.Kafka.Username != "" && config.Kafka.Password != "" {
|
||||
consumerConfig.Net.SASL.Enable = true
|
||||
consumerConfig.Net.SASL.User = config.Kafka.Username
|
||||
consumerConfig.Net.SASL.Password = config.Kafka.Password
|
||||
}
|
||||
|
||||
if kafkaConfig.Net.SASL.User != "" && kafkaConfig.Net.SASL.Password != "" {
|
||||
kafkaConfig.Net.SASL.Enable = true
|
||||
var tlsConfig *TLSConfig
|
||||
if config.Kafka.TLS != nil {
|
||||
tlsConfig = &TLSConfig{
|
||||
CACrt: config.Kafka.TLS.CACrt,
|
||||
ClientCrt: config.Kafka.TLS.ClientCrt,
|
||||
ClientKey: config.Kafka.TLS.ClientKey,
|
||||
ClientKeyPwd: config.Kafka.TLS.ClientKeyPwd,
|
||||
InsecureSkipVerify: false,
|
||||
}
|
||||
}
|
||||
|
||||
err := SetupTLSConfig(kafkaConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
err:=SetupTLSConfig(consumerConfig, tlsConfig)
|
||||
if err!=nil{
|
||||
return nil,err
|
||||
}
|
||||
|
||||
consumer, err := sarama.NewConsumer(p.addr, kafkaConfig)
|
||||
consumer, err := sarama.NewConsumer(p.addr, consumerConfig)
|
||||
if err != nil {
|
||||
return nil, errs.Wrap(err, "NewKafkaConsumer: creating consumer failed")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user