Class PubSubSourceBuilder<T>
- Type Parameters:
T- type of the records produced by the source
PubSubSource.builder().
Required settings: at least one subscription and a deserialization schema.
-
Method Summary
Modifier and TypeMethodDescriptionorg.apache.flink.api.connector.source.Source<T,SubscriptionSplit, PubSubEnumeratorState> build()Builds the source.deserializationFailurePolicy(DeserializationFailurePolicy deserializationFailurePolicy) Sets what the source does with a message the deserialization schema cannot convert.deserializer(PubSubDeserializationSchema<T> deserializer) Sets the record deserializer.emulatorEndpoint(String emulatorEndpoint) Points the source at a Pub/Sub emulator instead of the production service.orderingMode(OrderingMode orderingMode) Sets whether the source preserves ordering-key delivery order.serviceAccountKeyFile(String serviceAccountKeyFile) Authenticates the source with the service-account JSON key at the given path instead of application-default credentials.startPosition(PubSubStartPosition startPosition) Sets where the source starts consuming.subscriberOptions(PubSubSubscriberOptions subscriberOptions) Sets the subscriber tuning options: SDK flow control, the streaming-pull connection count and the acknowledgement-deadline extension settings, plus the source's drain size, subscriber shutdown budget and first-checkpoint watchdog.subscription(SubscriptionDestination subscription) Adds a subscription to consume.subscription(SubscriptionDestination subscription, SubscriptionCreateOptions createOptions) Adds a subscription to consume, creating it with the given settings if it does not exist.subscriptions(SubscriptionDestination... subscriptions) Adds subscriptions to consume.subscriptions(Collection<SubscriptionDestination> subscriptions) Adds subscriptions to consume.
-
Method Details
-
subscription
Adds a subscription to consume. Calling this several times, or combining it withsubscriptions(SubscriptionDestination...), consumes every added subscription in one source.The subscription must already exist. Use
subscription(SubscriptionDestination, SubscriptionCreateOptions)to have the source create it when it does not.- Parameters:
subscription- the subscription- Returns:
- this builder
-
subscription
public PubSubSourceBuilder<T> subscription(SubscriptionDestination subscription, SubscriptionCreateOptions createOptions) Adds a subscription to consume, creating it with the given settings if it does not exist.Passing options is what authorises creating this subscription; a subscription added without them must already exist. The options are per subscription because they carry the topic binding, and two subscriptions of one topic each receive a complete copy of its stream — so sharing one options object would silently duplicate every message.
An existing subscription is left exactly as it is: these settings are not applied to it.
- Parameters:
subscription- the subscriptioncreateOptions- the settings to create it with if it is absent- Returns:
- this builder
-
subscriptions
Adds subscriptions to consume.- Parameters:
subscriptions- the subscriptions- Returns:
- this builder
-
subscriptions
Adds subscriptions to consume.- Parameters:
subscriptions- the subscriptions- Returns:
- this builder
-
deserializer
Sets the record deserializer. Required; one message may produce any number of records, including none, which drops the message while still acknowledging it with the checkpoint that covers it.- Parameters:
deserializer- the deserialization schema- Returns:
- this builder
-
orderingMode
Sets whether the source preserves ordering-key delivery order. Defaults toOrderingMode.NONE.OrderingMode.PER_KEYassigns each subscription to exactly one reader subtask, so source parallelism beyond the subscription count leaves subtasks idle. See the enum for the full guarantee and its cost.- Parameters:
orderingMode- the ordering mode- Returns:
- this builder
-
subscriberOptions
Sets the subscriber tuning options: SDK flow control, the streaming-pull connection count and the acknowledgement-deadline extension settings, plus the source's drain size, subscriber shutdown budget and first-checkpoint watchdog. Optional; every knob left unset keeps the SDK's (or the source's) default.- Parameters:
subscriberOptions- the subscriber options- Returns:
- this builder
-
deserializationFailurePolicy
public PubSubSourceBuilder<T> deserializationFailurePolicy(DeserializationFailurePolicy deserializationFailurePolicy) Sets what the source does with a message the deserialization schema cannot convert. Defaults toDeserializationFailurePolicy.FAIL.- Parameters:
deserializationFailurePolicy- the failure policy- Returns:
- this builder
-
startPosition
Sets where the source starts consuming. Defaults toPubSubStartPosition.continueFromSubscription(), which starts wherever the subscriptions already are.Every other position seeks, which rewrites state shared by every consumer of the subscription — including other jobs. The seek runs once, at the first start of a job, and never on a restore. See
PubSubStartPositionfor the full semantics.- Parameters:
startPosition- where to start consuming- Returns:
- this builder
-
serviceAccountKeyFile
Authenticates the source with the service-account JSON key at the given path instead of application-default credentials. The file is read on the JobManager for subscription administration and on each TaskManager that creates a reader, so the same path must be readable by every JobManager and TaskManager that can run this source. Optional; when unset the source uses application-default credentials.Service-account keys are long-lived secrets. Prefer an attached service account or Workload Identity where the deployment supports one. This setting cannot be combined with
emulatorEndpoint(String), whose plaintext channel deliberately carries no credentials.- Parameters:
serviceAccountKeyFile- the service-account JSON key-file path- Returns:
- this builder
-
emulatorEndpoint
Points the source at a Pub/Sub emulator instead of the production service. Subscribers connect to the givenhost:portover a plaintext channel with no credentials, so this must only ever be used against an emulator (for example a testcontainersPubSubEmulatorContainer). Optional; when unset the source connects to Pub/Sub with application-default credentials.The value is parsed here, so a malformed
host:portis rejected on the client instead of surfacing as a connection failure once the job has been deployed.- Parameters:
emulatorEndpoint- the emulator endpoint ashost:port- Returns:
- this builder
- Throws:
IllegalArgumentException- if the endpoint is nothost:portwith a port in 1..65535
-
build
public org.apache.flink.api.connector.source.Source<T,SubscriptionSplit, build()PubSubEnumeratorState> Builds the source.The returned source implements
LineageVertexProvider. It reports each configured subscription aspubsub/subscription:project:subscription, with the source's unboundedness and agcpphysical-resource facet. It does not look up backing topics or infer them from subscription-creation settings. Inspection performs no authentication, client creation, RPC, or deserialization.Flink 2.2 and 2.3 extract this metadata natively. Flink 1.20 supports direct inspection through the interface, without automatic FLIP-314 listener delivery.
- Returns:
- the source
-