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
feat(pubsub): Allow Message and PublishResult to be used outside the package #3200
Conversation
tmdiep
commented
Nov 12, 2020
- Refactored ack/nack handling to an ackHandler interface. Added NewMessage() for external packages to create messages with a custom ack handler.
- Refactored usage inside the pubsub package.
- Added NewPublishResult() to expose set() as a func. Users will not be able to inadvertently call this to set a publish result before it is ready.
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.
LGTM, thanks!
For context, this PR was opened after discussing the best way to maintain compatibility with the new Pub/Sub Lite Go library. Prior to this change, ack/nacks are not exposed which meant that any code outside this package wouldn't be able to reuse |
|
||
// NewMessage creates a message with a custom ack/nack handler, which should not | ||
// be nil. | ||
func NewMessage(ackh ackHandler) *Message { |
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.
This is a poor API. It'll look weird in package docs since ackHandler
is unexported.
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 don't see why ackHandler
can't be exported. Maybe that should be the quick fix?
We also technically haven't cut a release for this commit, so I think we can still make some changes as a last-ditch effort if this doesn't sit well with you.
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.
The package docs looking strange is a good point. I've opened #3216.
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.
If there's a desire to reuse code across the pubsub
and pubsublite
packages, it would probably be better for there to be an internal/pubsub
package that both use, either using type aliases or merely having shallow types that forward to the internal/pubsub
versions of types.
@dsymonds Thanks for the comments. No disagreement from me about the drawbacks of this API. For context, we wanted to use |
I wasn't privvy to any of the lengthy discussions about options (is there a doc anywhere?), but are you saying you want the Keeping the As an alternative: if there's an |
Another alternative: move |
Some users wanted to verify whether ack/nack were called in their unit tests (#2920). AckHandler was intended to make this easier for them (as a side-effect). @hongalex who has more context on this aspect. |
Thanks for forwarding me the extra discussion. FWIW, if the long term plan is for FWIW, checking for Ack/Nack per #2920 is not a good reason either. As @tbpg pointed out there, there are better approaches (whether pstest, or defining ones own trivial interface) for testing. |
About half of folks were original proponents of Option 2 (myself included) and had the same thoughts. We ultimately agreed with Option 2 extension, to move the Option 1 "pubsub shim" to a subpackage, so that we could reserve the Both Option 1 and Option 2 extension required some internal
I was almost going to say this sounds fine. But |
A few comments back I suggested moving the implementation parts that needed to be shared into an If you move it to |
Sorry, I meant "internal fields" rather than "internal implementation details" (corrected). For example, we needed to access
@hongalex for preferences. Hmm, I remember being told that users still use anything in internal/ directories (if so, being able to replace the ack handler of a message would not be ideal). But I probably misunderstood. |
I don't remember the context of this. I think we discussed that if pubsub and pubsublite are separate modules in the same directory structure, both could import internal from As for preferences, I'm fine with anything that minimizes confusion with existing users and is consistent with how we maintain the pubsub/lite relationship in other languages. I'm in favor of exposing |
There's already quite a bit of stuff under |
Thanks both. To wrap up this discussion, we'll expose |
+1 to all of @dsymonds comments in this thread.
An Yes, the impact is contained to those two modules. But, we're talking about the exported API of the two modules. So, users outside of cloud.google.com/go will use them. |