Skip to content

feat(pubsub): add simple Publisher builder#4343

Merged
suzmue merged 5 commits intogoogleapis:mainfrom
suzmue:feat/pubsub-unified-publisher-builder
Jan 28, 2026
Merged

feat(pubsub): add simple Publisher builder#4343
suzmue merged 5 commits intogoogleapis:mainfrom
suzmue:feat/pubsub-unified-publisher-builder

Conversation

@suzmue
Copy link
Copy Markdown
Collaborator

@suzmue suzmue commented Jan 23, 2026

Add a new builder that can configure both the client settings and the batching settings for the Publisher and updated the examples to use the new builder.

This change also refactors the BasePublisherBuilder to be its own type to allow for more visibility for testing.

The doc comments and examples are copied from the ClientBuilder and the PublisherPartialBuilder. The only client configuration that is not included is the polling configuration since this isn't relevant.

For #4282

@product-auto-label product-auto-label bot added the api: pubsub Issues related to the Pub/Sub API. label Jan 23, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.02%. Comparing base (85c9137) to head (6d5f3b1).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4343      +/-   ##
==========================================
+ Coverage   94.98%   95.02%   +0.04%     
==========================================
  Files         193      194       +1     
  Lines        7294     7359      +65     
==========================================
+ Hits         6928     6993      +65     
  Misses        366      366              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@suzmue suzmue force-pushed the feat/pubsub-unified-publisher-builder branch from 7efb993 to b2cd951 Compare January 23, 2026 17:43
@suzmue suzmue marked this pull request as ready for review January 23, 2026 18:24
@suzmue suzmue requested a review from a team January 23, 2026 18:24
Copy link
Copy Markdown
Member

@dbolduc dbolduc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fix the examples to use the right client?

And can you also do a pass on the coverage for some of the new options? #4343 (comment)

The nits around wording are not a blocker for me approving

@suzmue suzmue force-pushed the feat/pubsub-unified-publisher-builder branch from b2cd951 to 400c9fd Compare January 28, 2026 01:08
Copy link
Copy Markdown
Collaborator Author

@suzmue suzmue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to refactor to test the Client setters effectively, since I can't inspect anything in the ClientBuilder

@dbolduc
Copy link
Copy Markdown
Member

dbolduc commented Jan 28, 2026

Need to refactor to test the Client setters effectively, since I can't inspect anything in the ClientBuilder

Ah. I thought for like ~10 mins and didn't come up with a simple, obvious refactor.

Maybe write your own BasePublisherBuilder instead of using the gax::client_builder::ClientBuilder? You'd be duping all of the setters, but you at least get to see inside of them. 🤷

https://github.com/suzmue/google-cloud-rust/blob/400c9fd37310ebfa30802a02035b5ba32fef8c64/src/pubsub/src/subscriber/client_builder.rs#L32

@suzmue suzmue force-pushed the feat/pubsub-unified-publisher-builder branch from 8c7618c to c2e8673 Compare January 28, 2026 20:37
@suzmue
Copy link
Copy Markdown
Collaborator Author

suzmue commented Jan 28, 2026

Need to refactor to test the Client setters effectively, since I can't inspect anything in the ClientBuilder

Ah. I thought for like ~10 mins and didn't come up with a simple, obvious refactor.

Maybe write your own BasePublisherBuilder instead of using the gax::client_builder::ClientBuilder? You'd be duping all of the setters, but you at least get to see inside of them. 🤷

https://github.com/suzmue/google-cloud-rust/blob/400c9fd37310ebfa30802a02035b5ba32fef8c64/src/pubsub/src/subscriber/client_builder.rs#L32

Doing this made me sad, but also its a lot better to be able to verify the configs match so this is an improvement. TY for pushing for this

Copy link
Copy Markdown
Member

@dbolduc dbolduc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits to consider in a follow up.

TY for pushing for this

Hopefully I was not too pushy. FTR, I would have approved a PR without coverage if there was a plan to add coverage later.

}
}
}
pub use super::client_builder::ClientBuilder as BasePublisherBuilder;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: seems less confusing to name the internal class BasePublisherBuilder

/// Publishers are created via a [`BasePublisher`][crate::client::BasePublisher].
/// A builder for a `Publisher`.
#[derive(Clone, Debug)]
pub struct PublisherBuilder {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

organization nit: does this belong in client_builder.rs now?

Or maybe it would be clearest with:

  • publisher_builder.rs
  • base_publisher_builder.rs

@suzmue suzmue merged commit 3b2e87e into googleapis:main Jan 28, 2026
31 checks passed
@suzmue suzmue deleted the feat/pubsub-unified-publisher-builder branch January 28, 2026 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: pubsub Issues related to the Pub/Sub API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants