-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use context for Publish methods #96
Conversation
Thank you, this is a non-trivial contribution! |
It introduce some breaking change on methods arguments by adding context and enforce an non-nil context on Publish methods. I enforce it because someone should never use a nil context and I feel it should failed early on that.
Even so, I understand that it could be better to support it if you feel it is needed. We could change it to support nil context by creating a background context in DeferredConfirmation in case of nil or an other solution is only require it when needed in case of ch.confirming == true. |
We can bump minor or even major version to accommodate this change if it is accepted. |
Changing the API out of the blue is not nice. I suggest to rename the context based Publish and leave the old one in place. Not every one wants to change their application (time, money, you name it). A little sense of stability would be nice. |
I agree that those changes are not nice. However, a major version, according to semver, reflect a breaking change in the API. I am in favour of introducing this change in a major.
The API has been stable almost since its inception in |
I could do a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sapk thank you for your work on this. A suggestion for you, @Gsantomaggio, @Zerpet and others (cc @fho) to consider, that may direct users of this library to use it correctly:
- Do not change the API for
Publish
. If the user callsPublish
with confirmations enabled on a channel, an error will be returned to indicate thatPublishWithDeferredConfirm
must be used. - If the user calls
PublishWithDeferredConfirm
when confirmations are not enabled, an error would be returned stating that confirmations must be enabled on the channel.
Or, add a new API keeping the existing one to preserve backwards-compatibility 🤷♂️
Thoughts?
I updated the PR to be backward compatible and rollback client test changes to validate working with previous Publish methods without context. With |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to change the API instead of introducing WithContext methods + deprecating the old ones.
It's a minor change and not much effort to adapt code when upgrading to new major amqp091-go release
@fho we will do that for version 2.0 |
This change removes embedded context.Context (which is generally an antipattern) from DeferredConfirmation. Instead, we use a simple channel to wait for ack/nack status. This approach is more flexible since it can be combined with timers, tickers, other contexts and channels in general using select{} statements and there is no overhead from context cancellation setup. Note that rabbitmq#96 introduced a behavior where Wait would unblock and return false once the context passed to Publish expires. This commit reverts this (arguably breaking) behavior in favor of WaitContext function.
Implement #92
This currently require context to be always cancelled (like net/http query) to not have stuck goroutine.I am considering switching from waitgroup to the context of query for the sync pattern of DeferredConfirmation. This could lead to no leaking goroutine.The latest implementation replace waitgroup of deferred with context so that we don't need goroutine to monitor context.