wagslane / go-rabbitmq

A wrapper of streadway/amqp that provides reconnection logic and sane defaults
https://blog.boot.dev/golang/connecting-to-rabbitmq-in-golang-easy/
MIT License
768 stars 125 forks source link

NewPublisher how set to confirm mode #116

Closed felixhuettner closed 1 year ago

felixhuettner commented 1 year ago

Hi everyone,

we where trying to use a Publisher with publish confirmations. For this to work the channel needs to be set to confirm mode.

From the publisher this is only available using startPublishHandler which is implicitly called in NotifyPublish.

We are therefor using publisher.NotifyPublish(func(_ rabbitmq.Confirmation) {}) to put the channel to confirm mode.

Would it be possible to add this setting as a publisher option?

wagslane commented 1 year ago

I'm not quite following - you want publish confirmations but you don't want to handle them?

felixhuettner commented 1 year ago

We handle them now using PublishWithDeferredConfirmWithContext and then calling WaitContext on the confirmation

wagslane commented 1 year ago

I think the cases where you'd want to set confirm mode, but don't want a handler to deal with those confirmations should be rare... I'm curious, why not just handle the confirmations as they come back across the channel?

felixhuettner commented 1 year ago

We are publishing the rabbitmq messages during a database transaction. And we only want to commit the transaction once we are completely certain that the message has been published. Therefor we use PublishWithDeferredConfirmWithContext and then block until the confirmation is received.

And this is a lot simpler with WaitContext than by using a custom handler

wagslane commented 1 year ago

Ah! I see. Yeah if you guys want to open a PR for a publishing option that simply sets confirm mode I'm open to it. Under the hood I think it should just set the handler to an empty handler.