Implementation:Apache Flink AsyncDynamicTableSinkBuilder
| Knowledge Sources | |
|---|---|
| Domains | Connectors, Table_API |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
An abstract builder class for constructing async dynamic table sinks with fluent configuration of async sink parameters.
Description
AsyncDynamicTableSinkBuilder is an abstract generic class in the flink-connector-base module that provides the builder pattern for constructing AsyncDynamicTableSink instances. It is parameterized by RequestEntryT (which must extend Serializable) and ConcreteBuilderT (a self-referencing type parameter for fluent method chaining). The class holds five private nullable fields corresponding to the async sink configuration parameters.
The builder provides five fluent setter methods: setMaxBatchSize(), setMaxInFlightRequests(), setMaxBufferedRequests(), setMaxBufferSizeInBytes(), and setMaxTimeInBufferMS(). Each setter returns the concrete builder type via an unchecked cast to ConcreteBuilderT, enabling type-safe method chaining. The class also provides protected getter methods for all five fields, allowing subclasses to access the configured values when implementing the abstract build() method.
Usage
Connector developers extend this class when building a Table API/SQL connector backed by AsyncSinkBase. The developer adds connector-specific setter methods and implements the build() method, which uses the protected getters to pass the async configuration values to the AsyncDynamicTableSink constructor. The builder is typically invoked from AsyncDynamicTableSinkFactory.createDynamicTableSink().
Code Reference
Source Location
- Repository: Apache_Flink
- File: flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/table/sink/AsyncDynamicTableSinkBuilder.java
- Lines: 1-121
Signature
@PublicEvolving
public abstract class AsyncDynamicTableSinkBuilder<
RequestEntryT extends Serializable,
ConcreteBuilderT extends AsyncDynamicTableSinkBuilder<?, ?>>
Import
import org.apache.flink.connector.base.table.sink.AsyncDynamicTableSinkBuilder;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| maxBatchSize | int | No | Maximum number of elements that may be passed in a list to be written downstream. |
| maxInFlightRequests | int | No | Maximum number of uncompleted calls to submitRequestEntries before blocking. |
| maxBufferedRequests | int | No | Maximum buffer length before writes block until elements are flushed. |
| maxBufferSizeInBytes | long | No | Buffer size threshold in bytes that triggers a flush. |
| maxTimeInBufferMS | long | No | Maximum time in milliseconds an element may remain in the buffer before flushing. |
Outputs
| Name | Type | Description |
|---|---|---|
| build() | AsyncDynamicTableSink<RequestEntryT> | Abstract method that constructs and returns the configured AsyncDynamicTableSink instance. |
Methods
Public Setters (Fluent API)
| Method | Parameter Type | Description |
|---|---|---|
| setMaxBatchSize(int) | int | Sets the maximum batch size; returns ConcreteBuilderT for chaining. |
| setMaxInFlightRequests(int) | int | Sets the maximum in-flight request count; returns ConcreteBuilderT for chaining. |
| setMaxBufferedRequests(int) | int | Sets the maximum buffered request count; returns ConcreteBuilderT for chaining. |
| setMaxBufferSizeInBytes(long) | long | Sets the buffer size threshold in bytes; returns ConcreteBuilderT for chaining. |
| setMaxTimeInBufferMS(long) | long | Sets the maximum buffer time in milliseconds; returns ConcreteBuilderT for chaining. |
Protected Getters
| Method | Return Type | Description |
|---|---|---|
| getMaxBatchSize() | Integer | Returns the configured max batch size, or null if not set. |
| getMaxInFlightRequests() | Integer | Returns the configured max in-flight requests, or null if not set. |
| getMaxBufferedRequests() | Integer | Returns the configured max buffered requests, or null if not set. |
| getMaxBufferSizeInBytes() | Long | Returns the configured max buffer size in bytes, or null if not set. |
| getMaxTimeInBufferMS() | Long | Returns the configured max time in buffer, or null if not set. |
Usage Examples
// Extending AsyncDynamicTableSinkBuilder for a custom connector
public class MyAsyncTableSinkBuilder
extends AsyncDynamicTableSinkBuilder<MyRequestEntry, MyAsyncTableSinkBuilder> {
private String endpoint;
private EncodingFormat<SerializationSchema<RowData>> encodingFormat;
private DataType physicalDataType;
public MyAsyncTableSinkBuilder setEndpoint(String endpoint) {
this.endpoint = endpoint;
return this;
}
public MyAsyncTableSinkBuilder setEncodingFormat(
EncodingFormat<SerializationSchema<RowData>> encodingFormat) {
this.encodingFormat = encodingFormat;
return this;
}
public MyAsyncTableSinkBuilder setPhysicalDataType(DataType physicalDataType) {
this.physicalDataType = physicalDataType;
return this;
}
@Override
public AsyncDynamicTableSink<MyRequestEntry> build() {
return new MyAsyncTableSink(
endpoint,
encodingFormat,
physicalDataType,
getMaxBatchSize(),
getMaxInFlightRequests(),
getMaxBufferedRequests(),
getMaxBufferSizeInBytes(),
getMaxTimeInBufferMS()
);
}
}
// Using the builder in a factory
MyAsyncTableSinkBuilder builder = new MyAsyncTableSinkBuilder()
.setEndpoint("https://my-service.example.com")
.setEncodingFormat(encodingFormat)
.setPhysicalDataType(physicalDataType)
.setMaxBatchSize(500)
.setMaxInFlightRequests(10)
.setMaxBufferSizeInBytes(5 * 1024 * 1024)
.setMaxTimeInBufferMS(5000);
AsyncDynamicTableSink<MyRequestEntry> sink = builder.build();
Related Pages
- Principle:Apache_Flink_Async_Sink_Framework
- Apache_Flink_AsyncDynamicTableSink - The table sink produced by this builder
- Apache_Flink_AsyncDynamicTableSinkFactory - Factory that uses this builder to create sinks
- Apache_Flink_AsyncSinkConnectorOptions - Configuration options applied via this builder