github.com/angryronald/go-kit@v0.0.0-20240505173814-ff2bd9c79dbf/publisher/rabbitmq/publisher.service.go (about) 1 package rabbitmq 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 return p.pubsubTopics[topic].Send(ctx, &pubsub.Message{ 18 Body: event, 19 Metadata: map[string]string{ 20 constant.EVENT_IDEMPOTENT_ID: idempotentId, 21 }, 22 }) 23 } 24 25 func NewPublisher(pubsubTopics map[string]*pubsub.Topic) publisher.Publisher { 26 return &RabbitmqPublisher{ 27 pubsubTopics: pubsubTopics, 28 } 29 }