Skip to content

Commit

Permalink
Router: publish messages in bulk (#513)
Browse files Browse the repository at this point in the history
Currently, the router will publish produced messaged by calling Publish individually, even though the bulk API exists.

This change works the same, although it can be handy for some custom implementations when you want to treat the produced messages as a group. For some implementations, it could also slightly improve publish performance.
  • Loading branch information
m110 authored Nov 2, 2024
1 parent d6b5dc2 commit e6daa87
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions message/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,15 +825,12 @@ func (h *handler) publishProducedMessages(producedMessages Messages, msgFields w
"publish_topic": h.publishTopic,
}))

for _, msg := range producedMessages {
if err := h.publisher.Publish(h.publishTopic, msg); err != nil {
// todo - how to deal with it better/transactional/retry?
h.logger.Error("Cannot publish message", err, msgFields.Add(watermill.LogFields{
"not_sent_message": fmt.Sprintf("%#v", producedMessages),
}))

return err
}
if err := h.publisher.Publish(h.publishTopic, producedMessages...); err != nil {
h.logger.Error("Cannot publish messages", err, msgFields.Add(watermill.LogFields{
"not_sent_message": fmt.Sprintf("%#v", producedMessages),
}))

return err
}

return nil
Expand Down

0 comments on commit e6daa87

Please sign in to comment.