mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-07 18:45:58 +08:00
add mysql
This commit is contained in:
@@ -158,6 +158,8 @@ type config struct {
|
||||
Etcd struct {
|
||||
EtcdSchema string `yaml:"etcdSchema"`
|
||||
EtcdAddr []string `yaml:"etcdAddr"`
|
||||
UserName string `yaml:"userName"`
|
||||
Password string `yaml:"password"`
|
||||
}
|
||||
Log struct {
|
||||
StorageLocation string `yaml:"storageLocation"`
|
||||
@@ -219,6 +221,8 @@ type config struct {
|
||||
}
|
||||
|
||||
Kafka struct {
|
||||
UserName string `yaml:"userName"`
|
||||
Password string `yaml:"password"`
|
||||
Ws2mschat struct {
|
||||
Addr []string `yaml:"addr"`
|
||||
Topic string `yaml:"topic"`
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package kafka
|
||||
|
||||
import (
|
||||
"github.com/Shopify/sarama"
|
||||
"Open_IM/pkg/common/config"
|
||||
"sync"
|
||||
|
||||
"github.com/Shopify/sarama"
|
||||
)
|
||||
|
||||
type Consumer struct {
|
||||
@@ -17,8 +19,13 @@ func NewKafkaConsumer(addr []string, topic string) *Consumer {
|
||||
p := Consumer{}
|
||||
p.Topic = topic
|
||||
p.addr = addr
|
||||
|
||||
consumer, err := sarama.NewConsumer(p.addr, nil)
|
||||
consumerConfig := sarama.NewConfig()
|
||||
if config.Config.Kafka.UserName != "" && config.Config.Kafka.Password != "" {
|
||||
consumerConfig.Net.SASL.Enable = true
|
||||
consumerConfig.Net.SASL.User = config.Config.Kafka.UserName
|
||||
consumerConfig.Net.SASL.Password = config.Config.Kafka.Password
|
||||
}
|
||||
consumer, err := sarama.NewConsumer(p.addr, consumerConfig)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
return nil
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package kafka
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
log "Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
"errors"
|
||||
@@ -25,7 +26,11 @@ func NewKafkaProducer(addr []string, topic string) *Producer {
|
||||
p.config.Producer.Return.Errors = true
|
||||
p.config.Producer.RequiredAcks = sarama.WaitForAll //Set producer Message Reply level 0 1 all
|
||||
p.config.Producer.Partitioner = sarama.NewHashPartitioner //Set the hash-key automatic hash partition. When sending a message, you must specify the key value of the message. If there is no key, the partition will be selected randomly
|
||||
|
||||
if config.Config.Kafka.UserName != "" && config.Config.Kafka.Password != "" {
|
||||
p.config.Net.SASL.Enable = true
|
||||
p.config.Net.SASL.User = config.Config.Kafka.UserName
|
||||
p.config.Net.SASL.Password = config.Config.Kafka.Password
|
||||
}
|
||||
p.addr = addr
|
||||
p.topic = topic
|
||||
|
||||
|
||||
Reference in New Issue
Block a user