Google Cloud Storage Sink Connector for Confluent Cloud

Note

If you are installing the connector locally for Confluent Platform, see Google Cloud Storage Sink Connector for Confluent Platform.

The Kafka Connect Google Cloud Storage (GCS) connector, currently available as a sink, allows you to export data from Apache Kafka® topics to GCS objects in various formats. Additionally, for certain data layouts, the GCS connector exports data by guaranteeing exactly-once delivery semantics to consumers of the GCS objects it produces.

The GCS connector is the counterpart of the S3 cloud storage sink connector in Google Cloud.

Features

The Confluent Cloud Google Cloud Storage (GCS) sink connector provides the following features:

  • Exactly Once Delivery: Records that are exported using a deterministic partitioner are delivered with exactly-once semantics regardless of the eventual consistency of GCS.
  • Data Format with or without Schema: Out of the box, the connector supports writing data to GCS in Avro, JSON, and Bytes. Schema validation is disabled for JSON.
  • Schema Evolution: schema.compatibility is set to NONE.
  • Partitioner: The connector supports the TimeBasedPartitioner class based on the Kafka class TimeStamp. Time-based partitioning options are daily or hourly.
  • Flush size: flush.size defaults to 1000. For example, if you use the default setting of 1000 and your topic has six partitions, files start to be created in the storage bucket after more than 1000 records exist in each partition. Note that the default value of 1000 can be increased if needed.

Refer to Cloud connector limitations for additional information.

Quick Start

Use this quick start to get up and running with the Confluent Cloud GCS sink connector. The quick start provides the basics of selecting the connector and configuring it to stream events to a GCS bucket using either the Confluent Cloud GUI or the Confluent Cloud CLI.

Prerequisites
  • Authorized access to a Confluent Cloud cluster on GCP.

  • The Confluent Cloud CLI installed and configured for the cluster. See Install and Configure the Confluent Cloud CLI.

  • A GCP GCS bucket in the same region as your Confluent Cloud cluster.

  • A GCP service account. You download service account credentials as a JSON file. These credentials are used when setting up the connector configuration.

    Important

    Your GCP service account role must have permission to create new objects in the GCS bucket. For example, the Storage Admin role can be selected for this purpose. If you are concerned about security and do not want to use the Storage Admin role, only use the storage.objects.get and storage.objects.create roles. Also, note that the Storage Object Admin role does not work for this purpose.

  • Either one of the following to use for the Kafka cluster credentials fields:

    • A Confluent Cloud API key and secret. After you have created your cluster, go to Cluster settings > API access > Create Key.
    • A Confluent Cloud service account.

See also

For an example that shows fully-managed Confluent Cloud connectors in action with Confluent Cloud KSQL, see the Cloud ETL demo. The demo also shows how to use Confluent Cloud CLI to manage your resources in Confluent Cloud.

Using the Confluent Cloud GUI

Complete the following steps to set up and run the connector using the Confluent Cloud GUI.

Step 1: Launch your Confluent Cloud cluster.

See the Confluent Cloud Quick Start for installation instructions.

Step 2: Add a connector.

Click Connectors > Add connector.

Add a connector

Step 3: Select your connector.

Click the Google Cloud Storage Sink connector icon.

Step 4: Enter the connector details.

Note

  • Make sure you have all your prerequisites completed.
  • An asterisk (*) designates a required entry.

Complete the following and click Continue.

  1. Enter a Connector Name.

  2. Enter your Kafka Cluster credentials. The credentials are either the API key and secret or the service account API key and secret.

  3. Enter one or more Topic names. Separate multiple topic names with a comma.

    Enter the connector details

Step 5: Enter the destination details.

Complete the following and click Continue.

Important

Your GCP credentials and bucket name are validated here. Make sure you enter these correctly.

  1. Upload the JSON file you downloaded earlier. The downloaded JSON file contains your GCP service account credentials.

  2. Enter the GCS bucket name.

  3. Select the message format.

  4. Select the Time interval that sets how you want your messages grouped in the GCS bucket. For example, if you select Hourly, messages are grouped into folders for each hour data is streamed to the bucket.

  5. Enter the Flush size. This value defaults to 1000. For example, if you use the default setting of 1000 and your topic has six partitions, files start to be created in the storage bucket after more than 1000 records exist in each partition. Note that the default value of 1000 can be increased if needed.

  6. Enter the number of tasks in use by the connector. Do not enter a value that exceeds the Max number displayed.

    Add the bucket destination

Configuration properties that are not shown in the Confluent Cloud UI use the default values. For default values and property definitions, see GCS Sink Connector Configuration Properties.

Step 6: Launch the connector.

Verify the following and click Launch.

  • Make sure your data is going to the correct bucket.

  • Check that the last directory in the path shown is using the Time Interval you entered earlier.

    Launch the connector

Step 7: Check the connector status.

The status for the connector should go from Provisioning to Running.

Check the connector status

Step 8: Check the GCS bucket.

  1. Go to the the bucket Objects page for your GCS bucket.

  2. Open your topic folder and each subsequent folder until you see your messages displayed.

    Check the storage bucket

For additional information about the GCS connector, see Google Cloud Storage Sink Connector for Confluent Platform. Note that not all Confluent Platform GCS connector features are provided in the Confluent Cloud GCS connector.

Using the Confluent Cloud CLI

Complete the following steps to set up and run the connector using the Confluent Cloud CLI.

Note

Make sure you have all your prerequisites completed.

Step 1: List the available connectors.

Enter the following command to list available connectors:

ccloud connector-catalog list

Step 2: Show the required connector configuration properties.

Enter the following command to show the required connector properties:

ccloud connector-catalog describe <connector-catalog-name>

For example:

ccloud connector-catalog describe GcsSink

Example output:

Following are the required configs:
connector.class
kafka.api.key
kafka.api.secret
topics
data.format
gcs.credentials.config
gcs.bucket.name
time.interval
tasks.max

Configuration properties that are not listed use the default values. For default values and property definitions, see GCS Sink Connector Configuration Properties.

Step 3: Create the connector configuration file.

Create a JSON file that contains the connector configuration properties. The following example shows the required connector properties.

{
    "name" : "confluent-gcs-sink",
    "connector.class" : "GcsSink",
    "kafka.api.key" : "<my-kafka-api-keyk>",
    "kafka.api.secret" : "<my-kafka-api-secret>",
    "topics" : "pageviews",
    "data.format" : "AVRO",
    "gcs.credentials.config" : "omitted"
    "gcs.bucket.name" : "<my-gcs-bucket-name>",
    "time.interval" : "HOURLY",
    "tasks.max" : "1"
}

Note the following property definitions:

  • "name": Sets a name for your new connector.
  • "connector.class": Identifies the connector plugin name.
  • "topics": Identifies the topic name or a comma-separated list of topic names.
  • "data.format": Sets the message format. Valid entries are AVRO, JSON, or BYTES.
  • "gcs.credentials.config": This contains the contents of the downloaded JSON file. See Formatting GCS credentials for details about how to format and use the contents of the downloaded credentials file.
  • "time.interval": Sets how your messages are grouped in the S3 bucket. Valid entries are DAILY or HOURLY.

Configuration properties that are not listed use the default values. For default values and property definitions, see GCS Sink Connector Configuration Properties.

Formatting GCS credentials

The contents of the downloaded credentials file must be converted to string format before it can be used in the connector configuration.

  1. Convert the JSON file contents into string format. You can use an online converter tool to do this. For example: JSON to String Online Converter.

  2. Add \ before all \n entries in the Private Key section so that each section begins with \\n (see the highlighted lines below). The example below has been formatted so that the \\n entries are easier to see. Most of the credentials key has been omitted.

    Tip

    A script is available that converts the credentials to a string and also adds additional \ characters where needed. See Stringify GCP Credentials.

      {
          "name" : "confluent-gcs-sink",
          "connector.class" : "GcsSink",
          "kafka.api.key" : "<my-kafka-api-keyk>",
          "kafka.api.secret" : "<my-kafka-api-secret>",
          "topics" : "pageviews",
          "data.format" : "AVRO",
          "gcs.credentials.config" : "{\"type\":\"service_account\",\"project_id\":\"connect-
          1234567\",\"private_key_id\":\"omitted\",
          \"private_key\":\"-----BEGIN PRIVATE KEY-----
          \\nMIIEvAIBADANBgkqhkiG9w0BA
          \\n6MhBA9TIXB4dPiYYNOYwbfy0Lki8zGn7T6wovGS5pzsIh
          \\nOAQ8oRolFp\rdwc2cC5wyZ2+E+bhwn
          \\nPdCTW+oZoodY\\nOGB18cCKn5mJRzpiYsb5eGv2fN\/J
          \\n...rest of key omitted...
          \\n-----END PRIVATE KEY-----\\n\",
          \"client_email\":\"pub-sub@connect-123456789.iam.gserviceaccount.com\",
          \"client_id\":\"123456789\",\"auth_uri\":\"https:\/\/accounts.google.com\/o\/oauth2\/
          auth\",\"token_uri\":\"https:\/\/oauth2.googleapis.com\/
          token\",\"auth_provider_x509_cert_url\":\"https:\/\/
          www.googleapis.com\/oauth2\/v1\/
          certs\",\"client_x509_cert_url\":\"https:\/\/www.googleapis.com\/
          robot\/v1\/metadata\/x509\/pub-sub%40connect-
          123456789.iam.gserviceaccount.com\"}",
          "gcs.bucket.name" : "<my-gcs-bucket-name>",
          "time.interval" : "HOURLY",
          "tasks.max" : "1"
      }
    
  3. Add all the converted string content to the "gcs.credentials.config" section of your configuration file as shown in the example above.

Step 4: Load the configuration file and create the connector.

Enter the following command to load the configuration and start the connector:

ccloud connector create --config <file-name>.json

For example:

ccloud connector create --config gcs-sink-config.json

Example output:

Created connector confluent-gcs-sink jtt-ix4dl

Step 5: Check the connector status.

Enter the following command to check the connector status:

ccloud connector list

Example output:

ID          |       Name         | Status  | Type
+-----------+--------------------+---------+------+
jtt-ix4dl   | confluent-gcs-sink | RUNNING | sink

Step 6: Check the GCS bucket.

  1. Go to the the bucket Objects page for your GCS bucket.

  2. Open your topic folder and each subsequent folder until you see your messages displayed.

    ../../_images/ccloud-gcp-bucket-details.png

For additional information about the GCS connector see Google Cloud Storage Sink Connector for Confluent Platform. Note that not all Confluent Platform GCS connector features are provided in the Confluent Cloud GCS connector.

Next Steps

Try out a Confluent Cloud demo. Use the Confluent Cloud GCS sink connector and a GCS bucket to store data.