liveBook · Manning

Sink connector

As explained in Kafka Streams in Action, Second Edition

SinkConnector is the Kafka Connect connector type that generates tasks for exporting data from Kafka to an external system.

A sink connector exports event records from Kafka topics to an external system. It is the outbound half of Kafka Connect: source connectors bring data into Kafka, while sink connectors deliver it to targets such as Elasticsearch, Google BigQuery, or Redis. Multiple sink connectors can independently export the same topic, allowing other systems to receive existing application data without changing the original application. section 5.1

A connector does not move each record itself. A SinkConnector creates task configurations, and SinkTask instances perform the data movement. Connect starts and distributes those tasks across workers in distributed mode; each task runs in its own thread. The connector chooses how many tasks to create, up to tasks.max, so that setting is a limit rather than a guarantee. section 5.3

Figure 5.4 Connect in distributed mode; tasks get spread around to other connector instances.
figure

Use the distributed-mode diagram to distinguish the connector’s control role from task instances that Connect spreads across workers for throughput and continued processing after worker failure. section 5.3

Run an available connector as a configured plugin rather than application code. Install its files on the Connect cluster and submit JSON configuration through the Connect REST API. A sink configuration identifies the connector class, target connection details, topic to read, converters, and task limit. Connector-specific settings define how records are written to the target. section 5.1 section 5.5

Index student information in Elasticsearch

Configure an Elasticsearch sink connector to read the postgres_orientation_students topic and write records to Elasticsearch. The configuration uses one task, a JSON value converter with schemas disabled, and settings controlling schema and key handling. Because external writes can fail, configure error tolerance and a dead-letter-queue topic; use replication factor 1 for that DLQ in a single-node Docker cluster. section 5.5 section 5.5

Shape records at the connector boundary when the required change is lightweight:

  • Apply Single Message Transforms after conversion on the outbound sink path. section 5.4
  • Chain transforms in declared order to create a key from user_name, extract that field, and mask an ssn value. section 5.4
  • Use SMTs only for one-record changes; use Kafka Streams or ksqlDB instead for joins, aggregations, or other complex processing. section 5.4

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Explains connector-to-task responsibilities, distributed execution, REST configuration, transforms, and error settings without implementing a custom connector.
Examples
Configures an Elasticsearch destination for orientation-student records and chains ValueToKey, ExtractField, and MaskField transforms.
What it assumes
Assumes familiarity with schemas and Schema Registry while explaining Kafka Connect connectors, tasks, workers, and converters.
What you can do after
Operate/configure it through the Connect REST API to export a topic, transform records, and route failed writes to a dead-letter queue.
How it connects
Connects SinkConnector to SinkTask, Kafka Connect workers, converters, Single Message Transforms, dead-letter queues, Kafka Streams, and ksqlDB.

Also explained in

Compare how 3 books explain sink connector →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kafka Streams in Action, Second Edition. The section links point to the parts of the book it draws on.