github.com/angryronald/go-kit@v0.0.0-20240505173814-ff2bd9c79dbf/publisher/kafka/publisher.service.go (about) 1 package kafka 2 3 import ( 4 "context" 5 6 "gocloud.dev/pubsub" 7 8 "github.com/angryronald/go-kit/constant" 9 "github.com/angryronald/go-kit/publisher" 10 ) 11 12 type RabbitmqPublisher struct { 13 pubsubTopics map[string]*pubsub.Topic 14 } 15 16 func (p *RabbitmqPublisher) Publish(ctx context.Context, topic string, idempotentId string, event []byte) error { 17 if p.pubsubTopics[topic] == nil { 18 return constant.ErrNotImplemented 19 } 20 21 return p.pubsubTopics[topic].Send(ctx, &pubsub.Message{ 22 Body: event, 23 Metadata: map[string]string{ 24 constant.EVENT_IDEMPOTENT_ID: idempotentId, 25 }, 26 }) 27 } 28 29 func NewPublisher(pubsubTopics map[string]*pubsub.Topic) publisher.Publisher { 30 return &RabbitmqPublisher{ 31 pubsubTopics: pubsubTopics, 32 } 33 }