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

feat: Add universe domain support for Java #1904

Merged
merged 11 commits into from
Feb 28, 2024
Prev Previous commit
Next Next commit
feat: Add setUniverseDomain option for Publisher and Subscriber
  • Loading branch information
michaelpri10 committed Feb 9, 2024
commit 0af60d75449d06a0af276578a07d246e62570e46
Expand Up @@ -185,6 +185,7 @@ private Publisher(Builder builder) throws IOException {
.setExecutorProvider(FixedExecutorProvider.create(executor))
.setTransportChannelProvider(builder.channelProvider)
.setEndpoint(builder.endpoint)
.setUniverseDomain(builder.universeDomain)
.setHeaderProvider(builder.headerProvider);
stubSettings
.publishSettings()
Expand Down Expand Up @@ -718,6 +719,7 @@ public static final class Builder {

String topicName;
private String endpoint = PublisherStubSettings.getDefaultEndpoint();
Copy link
Member

Choose a reason for hiding this comment

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

Is this still being used somewhere? I think it's autogenerated so it can't be removed IIRC

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This line was added when endpoint overriding was enabled for the Publisher/Subscriber here. If a user sets the endpoint when building the Publisher, we propagate that to the PublisherStubSettings builder, which is autogenerated. Otherwise, PublisherStubSettings uses the getDefaultEndpoint() method.

Copy link
Contributor

@lqiu96 lqiu96 Feb 14, 2024

Choose a reason for hiding this comment

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

To add a bit more context from the GAPICs perspective. Gax-Java now will resolve the endpoint automatically so there is no need to set a default endpoint. One of the parameters that we take into consideration is the user set endpoint which is configured from the Builder's setEndpoint(). All these factors (i.e. mtls, user set endpoint, user set universe domain, and more) will be considered when creating the final endpoint to be used.

The reason why we're suggesting to not pass the getDefaultEndpoint to Gax is that Gax-Java won't be able to determine if the endpoint passed in is a user configuration or not. The new endpoint logic has user configuration override everything so it will always default to pubsub.googleapis.com if it is passed in.

private String universeDomain = null;

// Batching options
BatchingSettings batchingSettings = DEFAULT_BATCHING_SETTINGS;
Expand Down Expand Up @@ -857,6 +859,12 @@ public Builder setEndpoint(String endpoint) {
return this;
}

/** Gives the ability to override the universe domain. */
public Builder setUniverseDomain(String universeDomain) {
this.universeDomain = universeDomain;
return this;
}

/** Gives the ability to enable transport compression. */
public Builder setEnableCompression(boolean enableCompression) {
this.enableCompression = enableCompression;
Expand Down
Expand Up @@ -192,6 +192,7 @@ private Subscriber(Builder builder) {
.setTransportChannelProvider(channelProvider)
.setHeaderProvider(builder.headerProvider)
.setEndpoint(builder.endpoint)
.setUniverseDomain(builder.universeDomain)
.build();
// TODO(pongad): what about internal header??
} catch (Exception e) {
Expand Down Expand Up @@ -492,6 +493,7 @@ public static final class Builder {
private Optional<ApiClock> clock = Optional.absent();
private int parallelPullCount = 1;
private String endpoint = SubscriberStubSettings.getDefaultEndpoint();
private String universeDomain = null;

Builder(String subscription, MessageReceiver receiver) {
this.subscription = subscription;
Expand Down Expand Up @@ -670,6 +672,12 @@ public Builder setEndpoint(String endpoint) {
return this;
}

/** Gives the ability to override the universe domain. */
public Builder setUniverseDomain(String universeDomain) {
this.universeDomain = universeDomain;
return this;
}

/** Gives the ability to set a custom clock. */
Builder setClock(ApiClock clock) {
this.clock = Optional.of(clock);
Expand Down