Skip to content
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

Implement support for the push model in the pubsub extension #776

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jfbenckhuijsen
Copy link
Contributor

This PR adds support for the push model for PubSub. The current version only supports the pull model, where the application needs a constantly running application thread which monitors the pubsub infrastructure for new messages and dispatches them accordingly. This works fine for hosted applications, but not for applications running on e.g. Cloud Run. The push model, which this PR supports. fixes that as in this model, a HTTP call is made by the PubSub broker to the application to deliver the messages.

This PR changes the object returned by the Subscriber methods in QuarkusPubSub to use the interface instead of the actual Subscriber class implementation. This has the added benefit of being able to switch automatically between the push and pull model without any code changes (only a property needs to be changed). Especially when testing, this is convenient as running a push model from a test is not fully supported by the current emulators. Using this setup, the user of the extension can use a pull model when running tests, and a push model when running in production without code changes.

Note that this change is of course backwards incompatible. However:

  1. The API exposed by the interface is 95% equivalent to the interface exposed by the class
  2. The lacking methods in the interface have a low probability to be used in the client code
  3. The change is a fairly small one when using concrete types in the client code and a recompile when using the var keyword
    Given the above the ease of testing was valued over the downside of a backwards incompatible change.

The PR adds a programmatic reactive route which is used to listen for new messages. Authentication is implemented using a RouteFilter as per the recommended practices in the Google PubSub documentation.

Two new dependencies are introduced in the PR to support this model: quarkus-reactive-routes and google-api-client. These dependencies are not needed in the pull scenario. I decided against marking these dependencies are optional (and letting the user include them in case the push model is used), because:

  • Use a "it just works" approach when using extensions without the hassle of including extra dependencies based on yes/no enabling the push model. To me, this is especially important as given the above testing approach, the user won't see these missing dependencies when using the pull model for testing.
  • Assuming REST services are often created using this extension, quarkus-reactive-routes (or part of the dependency tree) will probably already be on the classpath
  • google-api-client will probably already be on the class path when interacting with other google services

@jfbenckhuijsen jfbenckhuijsen marked this pull request as ready for review February 21, 2025 16:17
@jfbenckhuijsen jfbenckhuijsen requested a review from a team as a code owner February 21, 2025 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant