Class SubscriptionCreateOptions.Builder
java.lang.Object
io.github.flink.gcp.connector.pubsub.source.SubscriptionCreateOptions.Builder
- Enclosing class:
- SubscriptionCreateOptions
Builder for
SubscriptionCreateOptions.-
Method Summary
Modifier and TypeMethodDescriptionackDeadline(Duration ackDeadline) Sets how long a consumer has to acknowledge a message before Pub/Sub redelivers it.build()Builds the options.deadLetterPolicy(TopicDestination deadLetterTopic, int maxDeliveryAttempts) Forwards a message to the given topic once it has been deliveredmaxDeliveryAttemptstimes without being acknowledged.enableMessageOrdering(boolean enableMessageOrdering) Creates the subscription with ordering-key ordering enabled.expirationTtl(Duration expirationTtl) Sets how long the subscription may sit inactive before Pub/Sub deletes it.Sets a filter expression, so Pub/Sub delivers only matching messages and acknowledges the rest on the subscription's behalf.messageRetention(Duration messageRetention) Sets how long unacknowledged messages are retained.Creates the subscription so that it never expires, however long it sits inactive.retainAckedMessages(boolean retainAckedMessages) Retains messages after they are acknowledged, so a backwards seek can replay them.topic(TopicDestination topic) Sets the topic the subscription is created against.
-
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
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
Creates the subscription with ordering-key ordering enabled. Required byOrderingMode.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
Sets how long unacknowledged messages are retained. Defaults to the Pub/Sub default (7 days). Together withretainAckedMessages(boolean)this bounds how far back a backwardsPubSubStartPositioncan reach.- Parameters:
messageRetention- the retention duration- Returns:
- this builder
-
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
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 previousneverExpire().- Parameters:
expirationTtl- the inactivity TTL- Returns:
- this builder
-
neverExpire
Creates the subscription so that it never expires, however long it sits inactive. Clears any previousexpirationTtl(Duration).- Returns:
- this builder
-
deadLetterPolicy
public SubscriptionCreateOptions.Builder deadLetterPolicy(TopicDestination deadLetterTopic, int maxDeliveryAttempts) Forwards a message to the given topic once it has been deliveredmaxDeliveryAttemptstimes 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 tomaxDeliveryAttempts- delivery attempts before forwarding (Pub/Sub accepts 5 to 100)- Returns:
- this builder
-
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
Builds the options.- Returns:
- the options
-