Class SubscriptionCreateOptions.Builder

java.lang.Object
io.github.flink.gcp.connector.pubsub.source.SubscriptionCreateOptions.Builder
Enclosing class:
SubscriptionCreateOptions

@Public public static final class SubscriptionCreateOptions.Builder extends Object
  • Method Details

    • topic

      Sets the topic the subscription is created against. Required — a subscription cannot exist without one. The topic may live in a different project from the subscription.
      Parameters:
      topic - the topic to bind
      Returns:
      this builder
    • ackDeadline

      public SubscriptionCreateOptions.Builder ackDeadline(Duration ackDeadline)
      Sets how long a consumer has to acknowledge a message before Pub/Sub redelivers it. Pub/Sub stores this in whole seconds, so the duration must be a whole number of seconds — a sub-second remainder would be silently dropped. Defaults to the Pub/Sub default (10 s).

      This is only the starting deadline. The client library extends it while a message is outstanding, up to PubSubSubscriberOptions.Builder.maxAckExtensionPeriod(Duration), which is what actually has to cover the source's checkpoint interval.

      Parameters:
      ackDeadline - the acknowledgement deadline
      Returns:
      this builder
    • enableMessageOrdering

      public SubscriptionCreateOptions.Builder enableMessageOrdering(boolean enableMessageOrdering)
      Creates the subscription with ordering-key ordering enabled. Required by OrderingMode.PER_KEY, which the source builder checks. Cannot be turned on later: a subscription's ordering setting is fixed at creation.
      Parameters:
      enableMessageOrdering - whether to preserve ordering-key order
      Returns:
      this builder
    • messageRetention

      public SubscriptionCreateOptions.Builder messageRetention(Duration messageRetention)
      Sets how long unacknowledged messages are retained. Defaults to the Pub/Sub default (7 days). Together with retainAckedMessages(boolean) this bounds how far back a backwards PubSubStartPosition can reach.
      Parameters:
      messageRetention - the retention duration
      Returns:
      this builder
    • retainAckedMessages

      public SubscriptionCreateOptions.Builder retainAckedMessages(boolean retainAckedMessages)
      Retains messages after they are acknowledged, so a backwards seek can replay them. Without this, a seek into the past only recovers messages that were never acknowledged.
      Parameters:
      retainAckedMessages - whether to retain acknowledged messages
      Returns:
      this builder
    • expirationTtl

      public SubscriptionCreateOptions.Builder expirationTtl(Duration expirationTtl)
      Sets how long the subscription may sit inactive before Pub/Sub deletes it. Defaults to the Pub/Sub default (31 days). A running job keeps its subscriptions active; this matters for one that is stopped for longer than the TTL. Clears any previous neverExpire().
      Parameters:
      expirationTtl - the inactivity TTL
      Returns:
      this builder
    • neverExpire

      public SubscriptionCreateOptions.Builder neverExpire()
      Creates the subscription so that it never expires, however long it sits inactive. Clears any previous expirationTtl(Duration).
      Returns:
      this builder
    • deadLetterPolicy

      public SubscriptionCreateOptions.Builder deadLetterPolicy(TopicDestination deadLetterTopic, int maxDeliveryAttempts)
      Forwards a message to the given topic once it has been delivered maxDeliveryAttempts times without being acknowledged.

      Dead-lettering counts deliveries, not causes. A redelivery after a job restart raises the same counter as one after a nack, so a low attempt limit on a job that restarts repeatedly dead-letters healthy messages.

      Pub/Sub also needs its own service account granted publish on the dead-letter topic and subscribe on this subscription; without those grants it silently keeps redelivering.

      Parameters:
      deadLetterTopic - the topic undeliverable messages are forwarded to
      maxDeliveryAttempts - delivery attempts before forwarding (Pub/Sub accepts 5 to 100)
      Returns:
      this builder
    • filter

      public SubscriptionCreateOptions.Builder filter(String filter)
      Sets a filter expression, so Pub/Sub delivers only matching messages and acknowledges the rest on the subscription's behalf. Fixed at creation: a subscription's filter cannot be changed later.
      Parameters:
      filter - the filter expression, in Pub/Sub's filtering syntax
      Returns:
      this builder
    • build

      public SubscriptionCreateOptions build()
      Builds the options.
      Returns:
      the options