Class PubSubStartPosition

java.lang.Object
io.github.flink.gcp.connector.pubsub.source.PubSubStartPosition
All Implemented Interfaces:
Serializable

@Public public final class PubSubStartPosition extends Object implements Serializable
Where the source starts consuming a subscription.

A Pub/Sub subscription has no offset a reader can resume from: its position is server state, shared by every consumer. Anything other than continueFromSubscription() therefore works by seeking, which rewrites that shared state.

A seek affects every consumer of the subscription, including other jobs. Use a non-default start position only on a subscription the job owns.

The seek runs once, at the first start of a job, and never on a restore. The enumerator records that it ran in its checkpointed state, so a failover resumes rather than rewinding. A redeploy without a savepoint has no such state, so it seeks again — as does a job that crash-loops before its first checkpoint completes.

The shape here — a mode plus, for one mode, a timestamp — is what the Table API factory needs: it mirrors Kafka's scan.startup.mode and scan.startup.timestamp-millis pair, which of(Mode, Instant) accepts directly. The static factories are the DataStream API.

See Also:
  • Method Details

    • continueFromSubscription

      public static PubSubStartPosition continueFromSubscription()
      Starts wherever the subscription already is, without seeking. The default.
    • earliestRetained

      public static PubSubStartPosition earliestRetained()
      Starts from the oldest message the subscription still retains.
    • latest

      public static PubSubStartPosition latest()
      Starts from messages published after the job starts, discarding the existing backlog.
    • fromTimestamp

      public static PubSubStartPosition fromTimestamp(Instant timestamp)
      Starts from the given instant.
      Parameters:
      timestamp - the publish time to start from
      Returns:
      the start position
    • of

      public static PubSubStartPosition of(PubSubStartPosition.Mode mode, @Nullable Instant timestamp)
      Builds a start position from a mode and an optional timestamp, the form a ConfigOption pair produces. The static factories are the friendlier API for the DataStream builder.
      Parameters:
      mode - the mode
      timestamp - the instant, required for PubSubStartPosition.Mode.TIMESTAMP and rejected for the others
      Returns:
      the start position
    • getMode

      public PubSubStartPosition.Mode getMode()
      Returns which starting point this position names — the mode half of the mode-plus-timestamp pair of(Mode, Instant) accepts.
    • getTimestamp

      @Nullable public Instant getTimestamp()
      Returns the instant to start from, or null for every mode but PubSubStartPosition.Mode.TIMESTAMP.
    • requiresSeek

      public boolean requiresSeek()
      Returns whether reaching this position requires seeking the subscription.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object