Create a Custom Connector Pipeline
On this page
SingleStore Connector Pipelines use Kafka Connect Source Connector libraries to read data from external sources.
-
Ensure that the prerequisites are met.
SingleStore recommends having hands-on experience building custom connectors.
Existing third-party connector examples for reference:
Prerequisites
-
An active SingleStore Self-Managed cluster and access to every host where the connector will run.
-
Install Java 25 on each host that runs SingleStore.
Set the Java path using the java_engine variable in each node'spath memsql.file:cnf java_path = '<path/to/java-binary>'
Create a Custom Kafka Connect Source Connector
SingleStore Pipelines support Kafka Connect API version 3.
To implement a connector, extend the following two core classes: SourceConnector and SourceTask.
SourceConnector Class
The SourceConnector task provides metadata, validates configuration properties, and generates the necessary task configurations to instantiate SourceTask.SourceConnector as a short-lived class that retrieves the task and then stops.SourceConnector methods:
|
Method |
Description |
|---|---|
|
|
Returns the class of your |
|
|
Handles initialization logic, such as storing and validating connector properties. |
|
|
Defines supported configuration settings. |
|
|
Builds configurations for each task instance. |
|
|
Handles cleanup and deinitialization. |
Properties passed to the start() method are derived directly from the configuration and credentials specified in the CREATE PIPELINE command.tasks. configuration parameter to change this limit.
SingleStore Connector Pipelines do not support dynamic connectors that monitor external systems or perform reconfigurations.
SourceTask Class
The SourceTask class reads data subsets from the source system and translates them into SourceRecord objects.SourceTask methods:
|
Method |
Description |
|---|---|
|
|
Initializes the task, parses configurations, and performs setup. |
|
|
Fetches new data records from the source system. |
|
|
Closes active connections and cleans up resources. |
Optional methods to implement:
|
Method |
Description |
|---|---|
|
|
Acknowledges successful ingestion of a specific record. |
|
|
Acknowledges successful ingestion of the latest record batch. |
Remarks
-
Include a
sourcePartitionand asourceOffsetin every record returned bypoll(). -
Each
sourcePartitionmust identify a unique data stream.Two stream tasks must not emit records with the same sourcePartition. -
The
sourceOffsetidentifies the record position in a data stream.SingleStore stores the latest successfully processed sourceOffsetfor eachsourcePartition. -
Use the
OffsetStorageReaderto retrieve saved offsets and resume processing from the last successfully processed position:context.offsetStorageReader().offset(partition)
SingleStore invokes poll() on all SourceTask instances during batch processing and waits for every task to complete.poll() call starts from the previous offset for each partition.poll() calls) succeed, SingleStore writes the batch to the database in a single transaction.
Because a long-running poll() call blocks the entire batch while waiting for data, avoid blocking inside poll().
Register the Connector
Add a ServiceLoader manifest file to the project resources directory at META-INF/services/org..
Add the fully qualified SourceConnector class name on a single line.
com.example.FileStreamSourceConnectorThe manifest allows SingleStore to identify the connector by its short class name, FileStreamSourceConnector, instead of a fully-qualified class name (for example, com.).
Package the connector as an uber-JAR to avoid dependency conflicts with Java libraries used by SingleStore Connector Pipelines.
Test the Custom Connector Locally
Before deploying the custom connector to SingleStore, test it using a local Kafka and Kafka Connect environment.
Configure SingleStore to Use the Custom Connector
To deploy the custom Kafka Connect Source Connector to the SingleStore cluster:
-
Copy the connector JAR to the following directory on each host:
<singlestore-installation-dir>/extractors/lib-extractor-connect/ -
Verify that the JAR is readable by the SingleStore process.
-
Run the following command to enable custom connector pipelines:
SET GLOBAL experimental_features_config = 'connector_pipelines_enabled=true';
Create the Pipeline
Create a pipeline using the following command/syntax:
CREATE INFERRED PIPELINE `<pipeline_name>`AS LOAD DATA CONNECTOR '<connector_class>'CONFIG '{ <connector_configurations> }'CREDENTIALS '{ <connector_credentials> }';
The CREATE INFERRED PIPELINE . statement starts the connector and retrieves a sample batch to infer the target schema.
CREATE INFERRED PIPELINE `file_events`AS LOAD DATA CONNECTOR 'FileStreamSourceConnector'CONFIG '{"file": "/tmp/events.json","topic": "events","tasks.max": "1"}'CREDENTIALS '{}';
SingleStore recommends validating the pipeline configuration with the following two workflows:
-
Check the schema inference: Run the
CREATE INFERRED PIPELINEcommand to create the pipeline and then run theSHOW CREATE TABLEcommand to verify the schema of the inferred table.For example: CREATE INFERRED PIPELINE `testEx`AS LOAD DATA CONNECTOR 'FileStreamSourceConnector'CONFIG '{ "output.source.partition": "true", "output.source.offset": "true" }'CREDENTIALS '{}';SHOW CREATE TABLE testEx; -
Examine record serialization and optional metadata: Create a table with a structure that can store the records and then create a pipeline that writes the records and optional metadata to the table.
For example: CREATE TABLE `<table_name>` (`data` JSON NOT NULL);CREATE INFERRED PIPELINE `<pipeline_name>`AS LOAD DATA CONNECTOR '<connector_class>'CONFIG '{"output.key": "true","output.value": "true","output.timestamp": "true","output.headers": "true","output.topic": "true","output.source.partition": "true","output.source.offset": "true",<connector_configurations>}'CREDENTIALS '{<connector_credentials>}'INTO TABLE `<table_name>` FORMAT JSON (`data` <- %);START PIPELINE `<pipeline_name>`;Inspect the resulting records to understand data serialization and determine how to define custom column mappings and
SETclauses.
Troubleshoot Custom Connector Pipelines
Enable pipeline extractor debug logging:
SET GLOBAL pipelines_extractor_debug_logging = ON;
Inspect Pipeline Status
Run the SHOW PIPELINES command to view the pipeline status.
SHOW PIPELINES;
Monitor Batch Processing
Query the PIPELINES_SOURCE_ and SOURCE_ columns.
SELECT * FROM information_schema.PIPELINES_BATCHESWHERE PIPELINE_NAME = '<pipeline_name>';
Inspect Source Offsets
Query the PIPELINES_
SELECT * FROM information_schema.PIPELINES_SOURCE_OFFSETSWHERE PIPELINE_NAME = '<pipeline_name>';
Reset Pipeline Offsets
Run the ALTER PIPELINE .
ALTER PIPELINE '<pipeline_name>'SET OFFSETS {EARLIEST | LATEST | <json_source_partition_offset>};
Query Pipeline Errors
Query the PIPELINES_
SELECT * FROM information_schema.PIPELINES_ERRORSWHERE PIPELINE_NAME = '<pipeline_name>';
Related Topics
Last modified: