Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ private Publisher(Builder builder) throws IOException {
PublisherStubSettings.newBuilder()
.setCredentialsProvider(builder.credentialsProvider)
.setExecutorProvider(FixedExecutorProvider.create(executor))
.setTransportChannelProvider(builder.channelProvider);
.setTransportChannelProvider(builder.channelProvider)

Choose a reason for hiding this comment

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

Before the existence of setEndpoint, one would create a custom TransportChannelProvider and set the endpoint in there. If one does that and calls setEndpoint, which one will win?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the TransportChannelProvider#needsEndpoint(), then the value configured with setEndpoint() will take effect via TransportChannelProvider#withEndpoint(String). So a custom TransportChannelProvider that specifies an endpoint would not be overwritten.

See https://github.com/googleapis/gax-java/blob/fd5740a2726d0ab3f3124351ed0384911fa8f5c2/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java#L154-L156

.setEndpoint(builder.endpoint);
stubSettings
.publishSettings()
.setRetryableCodes(
Expand Down Expand Up @@ -588,6 +589,7 @@ public static final class Builder {
.build();

String topicName;
private String endpoint = PublisherStubSettings.getDefaultEndpoint();

// Batching options
BatchingSettings batchingSettings = DEFAULT_BATCHING_SETTINGS;
Expand Down Expand Up @@ -714,6 +716,12 @@ public Builder setTransform(ApiFunction<PubsubMessage, PubsubMessage> messageTra
return this;
}

/** Gives the ability to override the gRPC endpoint. */
public Builder setEndpoint(String endpoint) {
this.endpoint = endpoint;
return this;
}

public Publisher build() throws IOException {
return new Publisher(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ private Subscriber(Builder builder) {
.setCredentialsProvider(builder.credentialsProvider)
.setTransportChannelProvider(channelProvider)
.setHeaderProvider(builder.headerProvider)
.setEndpoint(builder.endpoint)
.applyToAllUnaryMethods(
new ApiFunction<UnaryCallSettings.Builder<?, ?>, Void>() {
@Override
Expand Down Expand Up @@ -414,6 +415,7 @@ public static final class Builder {
SubscriptionAdminSettings.defaultCredentialsProviderBuilder().build();
private Optional<ApiClock> clock = Optional.absent();
private int parallelPullCount = 1;
private String endpoint = SubscriberStubSettings.getDefaultEndpoint();

Builder(String subscriptionName, MessageReceiver receiver) {
this.subscriptionName = subscriptionName;
Expand Down Expand Up @@ -524,6 +526,12 @@ public Builder setParallelPullCount(int parallelPullCount) {
return this;
}

/** Gives the ability to override the gRPC endpoint. */
public Builder setEndpoint(String endpoint) {
this.endpoint = endpoint;
return this;
}

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