public abstract class SinkConnector extends Connector
Kafka Connect may discover implementations of this interface using the Java ServiceLoader
mechanism.
To support this, implementations of this interface should also contain a service provider configuration file in
META-INF/services/org.apache.kafka.connect.sink.SinkConnector
.
Modifier and Type | Field and Description |
---|---|
static String |
TOPICS_CONFIG
Configuration key for the list of input topics for this connector.
|
Constructor and Description |
---|
SinkConnector() |
Modifier and Type | Method and Description |
---|---|
boolean |
alterOffsets(Map<String,String> connectorConfig,
Map<TopicPartition,Long> offsets)
Invoked when users request to manually alter/reset the offsets for this connector via the Connect worker's REST
API.
|
protected SinkConnectorContext |
context()
Returns the context object used to interact with the Kafka Connect runtime.
|
config, initialize, initialize, reconfigure, start, stop, taskClass, taskConfigs, validate
public static final String TOPICS_CONFIG
Configuration key for the list of input topics for this connector.
Usually this setting is only relevant to the Kafka Connect framework, but is provided here for the convenience of Connector developers if they also need to know the set of topics.
protected SinkConnectorContext context()
Connector
public boolean alterOffsets(Map<String,String> connectorConfig, Map<TopicPartition,Long> offsets)
Connectors that neither manage offsets externally nor require custom offset validation need not implement this
method beyond simply returning true
.
User requests to alter/reset offsets will be handled by the Connect runtime and will be reflected in the offsets for this connector's consumer group.
Note that altering / resetting offsets is expected to be an idempotent operation and this method should be able to handle being called more than once with the same arguments (which could occur if a user retries the request due to a failure in altering the consumer group offsets, for example).
Similar to validate
, this method may be called by the runtime before the
start
method is invoked.
connectorConfig
- the configuration of the connectoroffsets
- a map from topic partition to offset, containing the offsets that the user has requested to
alter/reset. For any topic partitions whose offsets are being reset instead of altered, their
corresponding value in the map will be null
. This map may be empty, but never null. An
empty offsets map could indicate that the offsets were reset previously or that no offsets have
been committed yet.false
, and all other implementations (that do not unconditionally throw exceptions) should return
true
UnsupportedOperationException
- if it is impossible to alter/reset the offsets for this connectorConnectException
- if the offsets for this connector cannot be
reset for any other reason (for example, they have failed custom validation logic specific to this connector)