Class PubSubStartPosition
- All Implemented Interfaces:
Serializable
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:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic PubSubStartPositionStarts wherever the subscription already is, without seeking.static PubSubStartPositionStarts from the oldest message the subscription still retains.booleanstatic PubSubStartPositionfromTimestamp(Instant timestamp) Starts from the given instant.getMode()Returns which starting point this position names — the mode half of the mode-plus-timestamp pairof(Mode, Instant)accepts.Returns the instant to start from, ornullfor every mode butPubSubStartPosition.Mode.TIMESTAMP.inthashCode()static PubSubStartPositionlatest()Starts from messages published after the job starts, discarding the existing backlog.static PubSubStartPositionof(PubSubStartPosition.Mode mode, Instant timestamp) Builds a start position from a mode and an optional timestamp, the form aConfigOptionpair produces.booleanReturns whether reaching this position requires seeking the subscription.toString()
-
Method Details
-
continueFromSubscription
Starts wherever the subscription already is, without seeking. The default. -
earliestRetained
Starts from the oldest message the subscription still retains. -
latest
Starts from messages published after the job starts, discarding the existing backlog. -
fromTimestamp
Starts from the given instant.- Parameters:
timestamp- the publish time to start from- Returns:
- the start position
-
of
Builds a start position from a mode and an optional timestamp, the form aConfigOptionpair produces. The static factories are the friendlier API for the DataStream builder.- Parameters:
mode- the modetimestamp- the instant, required forPubSubStartPosition.Mode.TIMESTAMPand rejected for the others- Returns:
- the start position
-
getMode
Returns which starting point this position names — the mode half of the mode-plus-timestamp pairof(Mode, Instant)accepts. -
getTimestamp
Returns the instant to start from, ornullfor every mode butPubSubStartPosition.Mode.TIMESTAMP. -
requiresSeek
public boolean requiresSeek()Returns whether reaching this position requires seeking the subscription. -
equals
-
hashCode
public int hashCode() -
toString
-