Skip to content

Commit

Permalink
feat: allow endpoint override on Publisher/Subscriber (#5915)
Browse files Browse the repository at this point in the history
  • Loading branch information
chingor13 authored Jul 30, 2019
1 parent 64efb93 commit 5872cbd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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)
.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

0 comments on commit 5872cbd

Please sign in to comment.