Class CloudTasksSinkBuilder<T>
- Type Parameters:
T- type of the records written by the sink
CloudTasksSink.builder().
Required settings: a serialization schema and a destination. The destination is set through
either queue(QueueDestination) (fixed queue) or destinationResolver(DestinationResolver) (per-record dynamic destinations); the two override
each other and the last call wins.
The queue itself is never created by the sink and must exist: an auto-created queue would carry Cloud Tasks' default rate limits, silently discarding the pacing that is the reason to use the service. A deleted queue name can also remain temporarily unavailable for reuse.
-
Method Summary
Modifier and TypeMethodDescriptionorg.apache.flink.api.connector.sink2.Sink<T>build()Builds the sink.deliveryGuarantee(CloudTasksDeliveryGuarantee deliveryGuarantee) Selects eager creation or checkpointed named creation within the documented recovery window.destinationResolver(DestinationResolver<? super T> destinationResolver) Resolves the destination queue per record (dynamic destinations).emulatorEndpoint(String emulatorEndpoint) Points the sink at a Cloud Tasks emulator instead of the production service.failedTaskHandler(FailureHandler<? super FailedTask> failedTaskHandler) Sets the policy for a task that terminally fails — fail the job (the default), drop it, or send it to a dead-letter queue.queue(QueueDestination queue) Creates every task in the given fixed queue.serializer(CloudTasksSerializationSchema<? super T> serializer) Sets the record serialization schema.serviceAccountKeyFile(String serviceAccountKeyFile) Authenticates the sink with the service-account JSON key at the given path instead of application-default credentials.stagedOptions(CloudTasksStagedOptions stagedOptions) Sets staging and recovery options; requiresCloudTasksDeliveryGuarantee.EXACTLY_ONCE.taskIdExtractor(TaskIdExtractor<? super T> taskIdExtractor) Deduplicates records by the extracted key.writerOptions(CloudTasksWriterOptions writerOptions) Sets the in-flight cap and the two retry budgets for the writer or staged committer.
-
Method Details
-
queue
Creates every task in the given fixed queue. Overrides any previously set queue or resolver.- Parameters:
queue- the destination queue- Returns:
- this builder
-
destinationResolver
public CloudTasksSinkBuilder<T> destinationResolver(DestinationResolver<? super T> destinationResolver) Resolves the destination queue per record (dynamic destinations). Overrides any previously set queue or resolver.- Parameters:
destinationResolver- the resolver- Returns:
- this builder
-
serializer
Sets the record serialization schema. Required; a schema returningnullskips the record rather than failing it.- Parameters:
serializer- the serialization schema- Returns:
- this builder
-
taskIdExtractor
Deduplicates records by the extracted key. Optional; without it the default at-least-once mode creates unnamed tasks, while exactly-once mode persists a fresh random identity for every accepted record. Recovery in exactly-once mode reuses the saved identity.The sink hashes the key with SHA-256 before using it as the task id, and a repeated create for a key Cloud Tasks still remembers counts as success. Naming is off by default because Google documents the duplicate-name lookup as significantly increasing create latency, and because the window in which a key is remembered is bounded — its own documentation gives both "up to 24 hours" and "~1 hour" for it. Neither estimate establishes a precise minimum retention period for a correctness deadline. The sink does not verify queue retention or enforce a bounded recovery protocol.
- Parameters:
taskIdExtractor- the deduplication-key extractor- Returns:
- this builder
-
writerOptions
Sets the in-flight cap and the two retry budgets for the writer or staged committer. Optional; defaults toCloudTasksWriterOptions.defaults().- Parameters:
writerOptions- the options- Returns:
- this builder
-
failedTaskHandler
public CloudTasksSinkBuilder<T> failedTaskHandler(FailureHandler<? super FailedTask> failedTaskHandler) Sets the policy for a task that terminally fails — fail the job (the default), drop it, or send it to a dead-letter queue. Only data-shaped failures reach it: a record the serializer rejects, a task id extractor that throws, and a creation the service rejects withINVALID_ARGUMENT. Everything else keeps failing the job, including an exhausted retry budget andPERMISSION_DENIED— see the connector documentation for the full routing table.The parameter is contravariant, so a handler written against the shared
FailedElementcontract serves every connector in this repository without a cast.- Parameters:
failedTaskHandler- the handler- Returns:
- this builder
-
serviceAccountKeyFile
Authenticates the sink with the service-account JSON key at the given path instead of application-default credentials. The file is read on each TaskManager when its writer or committer is created, so the same path must be readable by every TaskManager that can run this sink. Optional; when unset the sink 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 sink at a Cloud Tasks emulator instead of the production service. The connection to the givenhost:portuses a plaintext channel with no credentials, so this must only ever be used against an emulator. Optional; when unset the sink connects to Cloud Tasks 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
-
deliveryGuarantee
Selects eager creation or checkpointed named creation within the documented recovery window.- Parameters:
deliveryGuarantee- the task-creation mode- Returns:
- this builder
-
stagedOptions
Sets staging and recovery options; requiresCloudTasksDeliveryGuarantee.EXACTLY_ONCE.- Parameters:
stagedOptions- the staging and recovery options- Returns:
- this builder
-
build
Builds the sink.- Returns:
- the sink
-