Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GCPPubSub refactor to support new streaming client API
Google have recently made some breaking changes to their Pub/Sub client API to support new high performance streaming methods. https://groups.google.com/forum/#!topic/google-api-go-announce/aaqRDIQ3rvU/discussion https://groups.google.com/forum/#!topic/google-api-go-announce/8pt6oetAdKc/discussion The main change is the new methods don't easily support blocking operations, nor one message at a time use cases. This is being discussed: googleapis/google-cloud-go#566 This change attempts to use the new API but in a blocking method indirectly discussed: googleapis/google-cloud-go#569 Since finishing and testing this method, which was successful, it appears Google is discussing this use case further internally, so this may not be the final solution, but gets us through for the moment. If we're required to stop using the Pub/Sub client, and instead use the APIv1 client, the issue does contain a gist of how it could work, but it hasn't been tested in various failure modes, as it's a lower level API - but I'm confident it just requires more testing and likely no more changes. Further, these changes did necessitate some refectoring on the internal APIs, this was mostly opportunistic but made the changes simpler. This refactors were essentially use a channel to push messages onto the queue, previously this was an interface called Queuer. Also, previously new jobs to be executed were sent on a channel, instead each type of queuer should take a callback, and execute that callback with the job as the only parameter. A callback was chosen instead of another channel, as I wanted to ensure only one message was consumed at a time, so the new APIs Receive method has only one instance running, and calls the callback, blocking until finished. When using a syncronous channel the Receive method became asyncronous because it would unblock as soon as the message on the channel was received, allowing the Receiver callback to fetch another message - but then block as there was be no other listener on the channel. GCPPubSubQueue was tested to ensure only one message is removed from the queue at any time, allowing other instances to consume the remaining messages, and on shutdown the executing job is allowed to finish in full before the process exits.
- Loading branch information
1 parent
a88607a
commit 4ec1438
Showing
9 changed files
with
203 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.