topicPathOverride();
+
public static Builder newBuilder() {
return (new AutoValue_ConsumerSettings.Builder()).setAutocommit(false);
}
@@ -68,22 +71,46 @@ public static Builder newBuilder() {
@AutoValue.Builder
public abstract static class Builder {
// Required parameters.
+ /**
+ * The subscription path to use. Only the topic corresponding to this subscription can be
+ * subscribed to.
+ */
public abstract Builder setSubscriptionPath(SubscriptionPath path);
+ /** The per-partition flow control settings. */
public abstract Builder setPerPartitionFlowControlSettings(FlowControlSettings settings);
// Optional parameters.
+ /** The autocommit mode. */
public abstract Builder setAutocommit(boolean autocommit);
+ /**
+ * An override for the TopicPath used by this consumer.
+ *
+ * When this is set, the topic path of the subscription will not be fetched: instead, the
+ * topic used in methods will be compared with the provided TopicPath object.
+ *
+ *
This is useful if you do not have the pubsublite.subscriptions.get permission for the
+ * subscription.
+ */
+ public abstract Builder setTopicPathOverride(TopicPath topicPath);
+
public abstract ConsumerSettings build();
}
public Consumer instantiate() throws ApiException {
- CloudRegion region = subscriptionPath().location().extractRegion();
- try (AdminClient adminClient =
- AdminClient.create(AdminClientSettings.newBuilder().setRegion(region).build())) {
- Subscription subscription = adminClient.getSubscription(subscriptionPath()).get();
- TopicPath topic = TopicPath.parse(subscription.getTopic());
+ try {
+ CloudRegion region = subscriptionPath().location().extractRegion();
+ TopicPath topic;
+ if (topicPathOverride().isPresent()) {
+ topic = topicPathOverride().get();
+ } else {
+ try (AdminClient adminClient =
+ AdminClient.create(AdminClientSettings.newBuilder().setRegion(region).build())) {
+ Subscription subscription = adminClient.getSubscription(subscriptionPath()).get();
+ topic = TopicPath.parse(subscription.getTopic());
+ }
+ }
AssignerFactory assignerFactory =
receiver -> {
try {