Skip to content

Commit

Permalink
fix: Add admin client in producer settings (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpcollins-google committed Mar 1, 2021
1 parent c6efa5e commit c1cf1d1
Showing 1 changed file with 7 additions and 6 deletions.
Expand Up @@ -48,10 +48,16 @@ public abstract static class Builder {
public abstract ProducerSettings build();
}

private AdminClient newAdminClient() {
return AdminClient.create(
AdminClientSettings.newBuilder().setRegion(topicPath().location().region()).build());
}

public Producer<byte[], byte[]> instantiate() throws ApiException {
PartitionCountWatchingPublisherSettings publisherSettings =
PartitionCountWatchingPublisherSettings.newBuilder()
.setTopic(topicPath())
.setAdminClient(newAdminClient())
.setPublisherFactory(
partition -> {
try {
Expand All @@ -72,12 +78,7 @@ public Producer<byte[], byte[]> instantiate() throws ApiException {
}
})
.build();
SharedBehavior shared =
new SharedBehavior(
AdminClient.create(
AdminClientSettings.newBuilder()
.setRegion(topicPath().location().region())
.build()));
SharedBehavior shared = new SharedBehavior(newAdminClient());
return new PubsubLiteProducer(publisherSettings.instantiate(), shared, topicPath());
}
}

0 comments on commit c1cf1d1

Please sign in to comment.