proto modify

This commit is contained in:
wangchuxiao
2023-03-02 12:00:31 +08:00
parent fc009c7c6c
commit d991947d4c
21 changed files with 344 additions and 3153 deletions
+5 -1
View File
@@ -3,7 +3,9 @@ package kafka
import (
"OpenIM/pkg/common/config"
log "OpenIM/pkg/common/log"
"OpenIM/pkg/common/tracelog"
"OpenIM/pkg/utils"
"context"
"errors"
"github.com/Shopify/sarama"
@@ -43,7 +45,8 @@ func NewKafkaProducer(addr []string, topic string) *Producer {
return &p
}
func (p *Producer) SendMessage(m proto.Message, key string, operationID string) (int32, int64, error) {
func (p *Producer) SendMessage(ctx context.Context, m proto.Message, key string) (int32, int64, error) {
operationID := tracelog.GetOperationID(ctx)
log.Info(operationID, "SendMessage", "key ", key, m.String(), p.producer)
kMsg := &sarama.ProducerMessage{}
kMsg.Topic = p.topic
@@ -63,6 +66,7 @@ func (p *Producer) SendMessage(m proto.Message, key string, operationID string)
log.Error(operationID, "kMsg.Key.Length() == 0 || kMsg.Value.Length() == 0 ", kMsg)
return -1, -1, errors.New("key or value == 0")
}
kMsg.Metadata = ctx
partition, offset, err := p.producer.SendMessage(kMsg)
log.Info(operationID, "ByteEncoder SendMessage end", "key ", kMsg.Key.Length(), kMsg.Value.Length(), p.producer)
if err == nil {