feat kafka 改版 1
This commit is contained in:
@@ -2,6 +2,7 @@ package kafka
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/IBM/sarama"
|
||||
"go.opentelemetry.io/otel"
|
||||
otelcodes "go.opentelemetry.io/otel/codes"
|
||||
@@ -14,10 +15,11 @@ func NewProducer() *Producer {
|
||||
type Producer struct {
|
||||
}
|
||||
|
||||
func (c *Producer) Produce(ctx context.Context, topic, value string) {
|
||||
func (c *Producer) Produce(ctx context.Context, data Topic) {
|
||||
marshal, _ := json.Marshal(data)
|
||||
msg := &sarama.ProducerMessage{
|
||||
Topic: topic,
|
||||
Value: sarama.StringEncoder(value),
|
||||
Topic: data.Name(),
|
||||
Value: sarama.ByteEncoder(marshal),
|
||||
Headers: NewCarrier().Inject(ctx),
|
||||
}
|
||||
client.producer.Input() <- msg
|
||||
|
||||
Reference in New Issue
Block a user