Create a Custom Connector Pipeline

SingleStore Connector Pipelines use Kafka Connect Source Connector libraries to read data from external sources. While SingleStore does not run Kafka or Kafka Connect, you can build SingleStore pipelines using custom Kafka Connect Source Connectors libraries. Perform the following tasks:

  1. Ensure that the prerequisites are met.

  2. Create a Custom Kafka Connect Source Connector.

  3. Register the connector.

  4. Configure SingleStore to use the custom connector.

  5. Create the pipeline.

SingleStore recommends having hands-on experience building custom connectors. For more information, refer to the Connector Development Guide.

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_path engine variable in each node's memsql.cnf file:

    java_path = '<path/to/java-binary>'

Create a Custom Kafka Connect Source Connector

SingleStore Pipelines support Kafka Connect API version 3.9.1 and Log4j/SLF4J version 2.25.5.

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. SingleStore uses SourceConnector as a short-lived class that retrieves the task and then stops. Implement the following SourceConnector methods:

Method

Description

Class<? extends Task> taskClass()

Returns the class of your SourceTask implementation.

void start(Map<String, String> props)

Handles initialization logic, such as storing and validating connector properties.

ConfigDef config()

Defines supported configuration settings.

List<Map<String, String>> taskConfigs(int maxTasks)

Builds configurations for each task instance.

void stop()

Handles cleanup and deinitialization.

Properties passed to the start() method are derived directly from the configuration and credentials specified in the CREATE PIPELINE command. By default, SingleStore instantiates four tasks. Use the tasks.max 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. Implement the following SourceTask methods:

Method

Description

void start(Map<String, String> props)

Initializes the task, parses configurations, and performs setup.

List<SourceRecord> poll()

Fetches new data records from the source system.

void stop()

Closes active connections and cleans up resources.

Optional methods to implement:

Method

Description

void commitRecord(SourceRecord record, RecordMetadata metadata)

Acknowledges successful ingestion of a specific record.

void commit()

Acknowledges successful ingestion of the latest record batch.

Remarks

  • Include a sourcePartition and a sourceOffset in every record returned by poll().

  • Each sourcePartition must identify a unique data stream. Two stream tasks must not emit records with the same sourcePartition.

  • The sourceOffset identifies the record position in a data stream. SingleStore stores the latest successfully processed sourceOffset for each sourcePartition.

  • Use the OffsetStorageReader to 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. If a task fails, the batch fails, and the next poll() call starts from the previous offset for each partition. After all tasks (poll() calls) succeed, SingleStore writes the batch to the database in a single transaction. Once the transaction succeeds, offsets are updated and tasks are committed.

Because a long-running poll() call blocks the entire batch while waiting for data, avoid blocking inside poll(). Return an empty list when no records are available.

Register the Connector

Add a ServiceLoader manifest file to the project resources directory at META-INF/services/org.apache.kafka.connect.source.SourceConnector.

Add the fully qualified SourceConnector class name on a single line. For example:

com.example.FileStreamSourceConnector

The manifest allows SingleStore to identify the connector by its short class name, FileStreamSourceConnector, instead of a fully-qualified class name (for example, com.example.FileStreamSourceConnector).

Package the connector as an uber-JAR to avoid dependency conflicts with Java libraries used by SingleStore Connector Pipelines. For Maven projects, use the Maven Shade Plugin. For Gradle projects, use the Gradle Shadow Plugin.

Test the Custom Connector Locally

Before deploying the custom connector to SingleStore, test it using a local Kafka and Kafka Connect environment. The Kafka ecosystem provides debugging tutorials and observability examples for local environments. Refer to Kafka Quickstart for setup instructions and Kafka Connect User Guide for connector configuration details.

Configure SingleStore to Use the Custom Connector

To deploy the custom Kafka Connect Source Connector to the SingleStore cluster:

  1. Copy the connector JAR to the following directory on each host:

    <singlestore-installation-dir>/extractors/lib-extractor-connect/
  2. Verify that the JAR is readable by the SingleStore process.

  3. 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 ... AS LOAD DATA CONNECTOR statement starts the connector and retrieves a sample batch to infer the target schema. SingleStore uses the inferred structure to create the destination table and then drops the sample records without updating offsets. For example:

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 PIPELINE command to create the pipeline and then run the SHOW CREATE TABLE command 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 SET clauses.

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_BATCHES information schema view to monitor batch processing and track offset movement using the SOURCE_OFFSETS_POLLED and SOURCE_OFFSETS_NEW columns.

SELECT * FROM information_schema.PIPELINES_BATCHES
WHERE PIPELINE_NAME = '<pipeline_name>';

Inspect Source Offsets

Query the PIPELINES_SOURCE_OFFSETS information schema view to inspect offset information for each pipeline task and batch.

SELECT * FROM information_schema.PIPELINES_SOURCE_OFFSETS
WHERE PIPELINE_NAME = '<pipeline_name>';

Reset Pipeline Offsets

Run the ALTER PIPELINE ... SET OFFSETS command to reset pipeline offsets to resume processing from a previously processed position.

ALTER PIPELINE '<pipeline_name>'
SET OFFSETS {EARLIEST | LATEST | <json_source_partition_offset>};

Query Pipeline Errors

Query the PIPELINES_ERRORS information schema view to view the pipeline errors.

SELECT * FROM information_schema.PIPELINES_ERRORS
WHERE PIPELINE_NAME = '<pipeline_name>';

Last modified:

Was this article helpful?

Verification instructions

Note: You must install cosign to verify the authenticity of the SingleStore file.

Use the following steps to verify the authenticity of singlestoredb-server, singlestoredb-toolbox, singlestoredb-studio, and singlestore-client SingleStore files that have been downloaded.

You may perform the following steps on any computer that can run cosign, such as the main deployment host of the cluster.

  1. (Optional) Run the following command to view the associated signature files.

    curl undefined
  2. Download the signature file from the SingleStore release server.

    • Option 1: Click the Download Signature button next to the SingleStore file.

    • Option 2: Copy and paste the following URL into the address bar of your browser and save the signature file.

    • Option 3: Run the following command to download the signature file.

      curl -O undefined
  3. After the signature file has been downloaded, run the following command to verify the authenticity of the SingleStore file.

    echo -n undefined |
    cosign verify-blob --certificate-oidc-issuer https://oidc.eks.us-east-1.amazonaws.com/id/CCDCDBA1379A5596AB5B2E46DCA385BC \
    --certificate-identity https://kubernetes.io/namespaces/freya-production/serviceaccounts/job-worker \
    --bundle undefined \
    --new-bundle-format -
    Verified OK

Try Out This Notebook to See What’s Possible in SingleStore

Get access to other groundbreaking datasets and engage with our community for expert advice.