houseofcat / turbocookedrabbit

A user friendly RabbitMQ library written in Golang.
MIT License
107 stars 20 forks source link

How to Ensure Publish #3

Closed prom3t3us closed 4 years ago

prom3t3us commented 4 years ago

Hello,

Can you please explain me how to be sure that a message published to an exchange is effectively delivered, as far I can understand looking at your code, there is no implementation of Channel.NotifyReturn listener.

I'm having some trouble for example in my case I'm trying to publish to a non existent exchange but also if I' ve subscribed to all notifications chan (service, channel) I'm not getting back any error from the library, but the server effectively and as per protocol raise the error.

Maybe I'm missing something, please can You help me understanding better this very nice library

Thanks in advance

houseofcat commented 4 years ago

You brought up a good point that I struggled with design wise. Let me get a stopping point in my work to have a look at revisiting auto-stitching up NotifyReturn.

I think I have a similar mechanism in place that handles all errors, not just return publish failures... and I had to pick one or the other due to duplication.

houseofcat commented 4 years ago

Okay so client side Channels are re-usable but often volatile.

If you are using my ChannelPool and you want to listen to the Returns, you would subscribe to the ChannelHost Returns() feature before using the Channel. I think I didn't stress getting this feature as we dispose of Channels on every error but you are welcome to use it, the functionality is there.

It's a amqp channel implementation, so this will allow you to access the internal return mechanism of the channel. In streadway, I think Returns are only given when there is a publish issue but you are also using Immediate / NoWait (bypassing internal outbound queuing).

Otherwise, subscribe to my Publisher's notification channel for all Success/Failure publishes. There are examples of this inside of Consumer/Publisher tests if you need to see how to use Notifications(), Returns() would work the same but at an individual Channel level.

houseofcat commented 3 years ago

As of version 2.0.2+, publishing has been re-hardened with Confirmations inside AutoPublisher and provided new Publisher methods allowing PublishWithConfirmation.