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, and a deleted queue name cannot be reused for 3 days.
-
Method Summary
Modifier and TypeMethodDescriptionorg.apache.flink.api.connector.sink2.Sink<T>build()Builds the sink.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.taskIdExtractor(TaskIdExtractor<? super T> taskIdExtractor) Opts into named tasks, deduplicating records by the extracted key.writerOptions(CloudTasksWriterOptions writerOptions) Sets the writer tuning options (the in-flight cap and the two retry budgets).
-
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
Opts into named tasks, deduplicating records by the extracted key. Optional; without it the sink creates unnamed tasks and a record replayed after a failure calls the endpoint twice.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, so design against the shorter one.
- Parameters:
taskIdExtractor- the deduplication-key extractor- Returns:
- this builder
-
writerOptions
Sets the writer tuning options (the in-flight cap and the two retry budgets). 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 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
-
build
Builds the sink.- Returns:
- the sink
-