Important
Helios features are now enabled during weekly update windows and are no longer directly tied to SingleStore engine releases. Refer to the release notes to view the latest features available in your Helios cluster.
Load Data from Google Cloud Pub/Sub Using a Connector Pipeline
On this page
This guide walks through creating a Connector Pipeline that ingests messages from a Google Cloud Pub/Sub subscription into SingleStore.
Prerequisites
To complete this guide, your environment must meet the following prerequisites:
-
Google Cloud account with permission to create Pub/Sub topics, subscriptions, and service accounts in a GCP project.
-
Connector Pipelines enabled (experimental feature).
Part 1: Enable Connector Pipelines
Enable the feature with the following command:
SET GLOBAL experimental_features_config = "connector_pipelines_enabled=true";
This setting must be configured before creating Connector Pipelines.
Verify the setting:
SHOW VARIABLES LIKE 'experimental_features_config';
Part 2: Set Up a Google Cloud Pub/Sub Subscription
Create a Pub/Sub Topic and Subscription
-
Log into the Google Cloud Console.
-
Select the project you want to use, or create a new one.
-
In the navigation menu, select Pub/Sub > Topics.
-
Select Create topic.
-
Enter a topic ID (for example,
singlestore-events). -
Leave Add a default subscription enabled so a subscription is created automatically.
Alternatively, disable it and create a subscription manually in the next step. -
Select Create.
If you created the subscription manually:
-
Navigate to Pub/Sub > Subscriptions.
-
Select Create subscription.
-
Enter a subscription ID (for example,
singlestore-events-sub). -
Select the topic you created in the previous step.
-
Set Delivery type to Pull (the connector uses pull delivery).
-
Set the Acknowledgement deadline and Message retention duration to match your workload.
Longer retention lets you re-process messages if the pipeline is stopped. -
Select Create.
Record the following values as they are required when creating the pipeline:
-
GCP project ID (for example,
my-gcp-project) -
Subscription ID (for example,
singlestore-events-sub)
Generate GCP Credentials
The Pub/Sub connector authenticates using a Google Cloud service account key.
Required IAM Roles
Grant the following predefined role to the service account:
-
roles/pubsub.: Read messages from Pub/Sub subscriptions.subscriber
For finer-grained control, you can grant the individual permissions instead:
-
pubsub.subscriptions. consume -
pubsub.subscriptions. get
Create a Service Account
-
In the Google Cloud Console navigation menu, select IAM & Admin > Service Accounts.
-
Select Create service account.
-
Enter a service account name (for example,
singlestore-pubsub-reader) and select Create and continue. -
In Grant this service account access to project, select the role Pub/Sub Subscriber.
-
Select Continue, then Done.
Grant the Service Account Access to the Subscription
If your organization uses subscription-level IAM (rather than project-level), grant the service account the Pub/Sub Subscriber role directly on the subscription:
-
Navigate to Pub/Sub > Subscriptions and select the subscription.
-
Open the Permissions panel.
-
Select Add principal.
-
Enter the service account's email address.
-
Assign the role Pub/Sub Subscriber.
-
Select Save.
Create a Service Account Key
-
In IAM & Admin > Service Accounts, select the service account you created.
-
Open the Keys tab.
-
Select Add key > Create new key.
-
Select JSON as the key type.
-
Select Create.
The JSON key file is downloaded to your machine.
Save the JSON key file securely.
You will paste the contents of this JSON file into the pipeline's CREDENTIALS clause.
Part 3: Create a SingleStore Database and Pub/Sub Pipeline
Create the Database
CREATE DATABASE pubsub_data;USE pubsub_data;
Deploy the Kafka Connect Connector
The Google Cloud Pub/Sub source connector (CloudPubSubSourceConnector) is prepackaged with SingleStore clusters.
Create the Pub/Sub Pipeline
Ensure you have the following information:
-
GCP project ID
-
Subscription ID
-
Service account key JSON
CREATE INFERRED PIPELINE pubsub_pipelineAS LOAD DATA KAFKACONNECT 'CloudPubSubSourceConnector'CONFIG '{"kafka.topic": "pubsub-topic","cps.project": "my-gcp-project","cps.subscription": "singlestore-events-sub","tasks.max": "1"}'CREDENTIALS '{"gcp.credentials.json": "<paste-service-account-key-json>"}'FORMAT JSON;
Important configuration notes:
-
CloudPubSubSourceConnector: Short name forcom..google. pubsub. kafka. source. CloudPubSubSourceConnector You can also use the full class name. -
kafka.: A logical identifier for the data source.topic It does not require an actual Kafka topic and is not related to your Pub/Sub topic name. -
cps.: The GCP project ID that contains the Pub/Sub subscription.project -
cps.: The Pub/Sub subscription ID (not the full resource path).subscription -
tasks.: Must bemax 1.Parallel extraction is not supported at the pipeline level. To scale Pub/Sub ingest, scale on the Pub/Sub side. -
Credentials placement: The service account key JSON must go in the
CREDENTIALSparameter under the keygcp..credentials. json Placing it in CONFIGexposes the key inSHOW CREATE PIPELINE. -
Format: Default is
FORMAT JSON.FORMAT AVROis also supported.
Optional CONFIG parameters
|
Field |
Description |
Default |
|---|---|---|
|
|
Pub/Sub endpoint to use. |
|
|
|
Set to |
|
|
|
Maximum number of messages returned per pull. |
|
|
|
Pub/Sub message attribute to use as the record key. |
(none) |
|
|
Pub/Sub message attribute to use as the record timestamp. |
(none) |
Static Schema Table
When the inferred pipeline is created, SingleStore automatically generates a table matching the connector's output schema.FORMAT JSON mode without an output-mode field, the inferred table has this shape:
CREATE TABLE `pubsub_pipeline` (`value` JSON,`timestamp` BIGINT(20) DEFAULT NULL,`topic` LONGTEXT COLLATE utf8mb4_bin NOT NULL,SORT KEY `__UNORDERED` (),SHARD KEY ());
The table contains three columns:
-
value: The full connector record (JSON). -
timestamp: The record timestamp in milliseconds since epoch (BIGINT). -
topic: The internal topic identifier (TEXT).
This static schema lets SingleStore ingest data from various sources without predefined table schemas.output. (single-value output mode) or map fields explicitly.
Start the Pipeline
Start in the Foreground
To test the pipeline and load existing messages, run:
START PIPELINE pubsub_pipeline FOREGROUND;This command runs synchronously and returns when the current batch of messages has been loaded.
Note
Because the Kafka Connect API does not signal when a source is fully drained, START PIPELINE . for a Pub/Sub pipeline may continue polling after all currently available messages have been processed.LIMIT clause on START PIPELINE FOREGROUND.
Start in the Background
For continuous streaming, run the following command:
START PIPELINE pubsub_pipeline;
This command runs the pipeline in the background, continuously pulling messages from the subscription.
Verify Pipeline Status
SHOW PIPELINES;
Returns the pipeline name and state.
The following is the detailed query:
SELECTPIPELINE_NAME,STATE,CONFIG_JSONFROM information_schema.PIPELINESWHERE PIPELINE_NAME = 'pubsub_pipeline';
Google Cloud Pub/Sub offsets appear in PIPELINES_ with KEY set to NULL and VALUE containing the Pub/Sub subscription path mapped to the last acknowledged position.
Last modified: