Skip to content

Commit

Permalink
fix: Allow overriding the publisher in PartitionCountWatchingPublishe…
Browse files Browse the repository at this point in the history
…rSettings (#1342)
  • Loading branch information
dpcollins-google authored Feb 21, 2023
1 parent f906d32 commit 0c01d49
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ If you are using Maven, add this to your pom.xml file:
If you are using Gradle without BOM, add this to your dependencies:

```Groovy
implementation 'com.google.cloud:google-cloud-pubsublite:1.10.0'
implementation 'com.google.cloud:google-cloud-pubsublite:1.11.0'
```

If you are using SBT, add this to your dependencies:

```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-pubsublite" % "1.10.0"
libraryDependencies += "com.google.cloud" % "google-cloud-pubsublite" % "1.11.0"
```

## Authentication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.cloud.pubsublite.internal.AlarmFactory;
import com.google.cloud.pubsublite.internal.DefaultRoutingPolicy;
import com.google.cloud.pubsublite.internal.Publisher;
import com.google.cloud.pubsublite.internal.RoutingPolicy;
import java.time.Duration;

@AutoValue
Expand All @@ -37,9 +38,12 @@ public abstract class PartitionCountWatchingPublisherSettings {
// Optional parameters
abstract Duration configPollPeriod();

abstract RoutingPolicy.Factory routingPolicyFactory();

public static Builder newBuilder() {
return new AutoValue_PartitionCountWatchingPublisherSettings.Builder()
.setConfigPollPeriod(Duration.ofMinutes(1));
.setConfigPollPeriod(Duration.ofMinutes(1))
.setRoutingPolicyFactory(DefaultRoutingPolicy::new);
}

@AutoValue.Builder
Expand All @@ -54,13 +58,15 @@ public abstract static class Builder {
// Optional parameters.
public abstract Builder setConfigPollPeriod(Duration period);

public abstract Builder setRoutingPolicyFactory(RoutingPolicy.Factory factory);

public abstract PartitionCountWatchingPublisherSettings build();
}

public Publisher<MessageMetadata> instantiate() throws ApiException {
return new PartitionCountWatchingPublisher(
publisherFactory(),
DefaultRoutingPolicy::new,
routingPolicyFactory(),
new PartitionCountWatcherImpl.Factory(
topic(), adminClient(), AlarmFactory.create(configPollPeriod())));
}
Expand Down

0 comments on commit 0c01d49

Please sign in to comment.