重要

このページの日本語コンテンツは古くなっている可能性があります。最新の英語版コンテンツをご覧になるには、こちらをクリックしてください。

Google Cloud Storage Source Connector for Confluent Cloud

注釈

If you are installing the connector locally for Confluent Platform, see Google Cloud Storage (GCS) Source Connector for Confluent Platform.

The managed Google Cloud Storage (GCS) Source connector can read data from any type of file naming convention listed under a GCS bucket (that is, the filenames in the bucket don’t have to be in a specific format). The connector can read file data in any of the supported formats (for example, JSON, Avro, and Byte Array).

Features

The GCS Source connector provides the following features:

  • At least once delivery: The connector guarantees that records are delivered at least once.
  • Supports multiple tasks: The connector supports running one or more tasks.

For more information and examples to use with the Confluent Cloud API for Connect, see the Confluent Cloud API for Connect section.

Refer to Confluent Cloud connector limitations for additional information.

IAM Policy for GCS

The following permissions are required for the GCS Source connector:

  • storage.buckets.get
  • storage.objects.get
  • storage.objects.list

For more information, see IAM permissions for Cloud Storage.

You may also grant a Service Account the following roles on the bucket:

  • Storage Object Viewer
  • Storage Legacy Bucket Reader

Quick Start

Use this quick start to get up and running with the Confluent Cloud GCS Source connector. The quick start provides the basics of selecting the connector and configuring it to get files from a GCS bucket.

Prerequisites
  • Kafka cluster credentials. The following lists the different ways you can provide credentials.
    • Enter an existing service account resource ID.
    • Create a Confluent Cloud service account for the connector. Make sure to review the ACL entries required in the service account documentation. Some connectors have specific ACL requirements.
    • Create a Confluent Cloud API key and secret. To create a key and secret, you can use confluent api-key create or you can autogenerate the API key and secret directly in the Cloud Console when setting up the connector.
  • Confluent Cloud Schema Registry must be enabled for your cluster, if you are using a messaging schema (like Apache Avro). See スキーマの操作.

Using the Confluent Cloud Console

Step 1: Launch your Confluent Cloud cluster.

See the Quick Start for Confluent Cloud for installation instructions.

Step 2: Add a connector.

In the left navigation menu, click Data integration, and then click Connectors. If you already have connectors in your cluster, click + Add connector.

Step 3: Select your connector.

Click the Google Cloud Storage Source connector card.

Google Cloud Storage Source Card

Step 4: Enter the connector details.

注釈

  • Be sure you have all your prerequisites completed.
  • An asterisk ( * ) designates a required entry.
  1. Select the way you want to provide Kafka Cluster credentials. You can choose one of the following options:
    • Global Access: Allows your connector to access everything you have access to. With global access, connector access will be linked to your account. This option is not recommended for production.
    • Granular access: Limits the access for your connector. You will be able to manage connector access through a service account. This option is recommended for production.
    • Use an existing API key: Allows you to enter an API key and secret part you have stored. You can enter an API key and secret (or generate these in the Cloud Console).
  2. Click Continue.

Step 5: Check the Kafka topic.

After the connector is running, verify that messages are populating your Kafka topic.

For more information and examples to use with the Confluent Cloud API for Connect, see the Confluent Cloud API for Connect section.

参考

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

../_images/topology.ja.png

Using the Confluent CLI

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

注釈

  • Make sure you have all your prerequisites completed.
  • The example commands use Confluent CLI version 2. For more information see, Confluent CLI v2.

Step 1: List the available connectors.

Enter the following command to list available connectors:

confluent connect plugin list

Step 2: Show the required connector configuration properties.

Enter the following command to show the required connector properties:

confluent connect plugin describe <connector-catalog-name>

For example:

confluent connect plugin describe GcsSource

Example output:

The following are required configs:
connector.class : GcsSource
name
topic.regex.list
kafka.api.key : ["kafka.api.key" is required when "kafka.auth.mode==KAFKA_API_KEY"]
kafka.api.secret : ["kafka.api.secret" is required when "kafka.auth.mode==KAFKA_API_KEY"]
gcs.credentials.json
gcs.bucket.name
input.data.format
output.data.format
tasks.max

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.

{
  "connector.class": "GcsSource",
  "name": "GcsSourceConnector_0",
  "topic.regex.list": "kafka-topic-for-json:*",
  "kafka.auth.mode": "SERVICE_ACCOUNT",
  "kafka.service.account.id": "<service-account-resource-ID>",
  "input.data.format": "JSON",
  "output.data.format": "JSON",
  "gcs.credentials.json": "",
  "gcs.bucket.name": "<bucket-name>",
  "tasks.max": "1",
}

Note the following required property definitions:

  • "connector.class": Identifies the connector plugin name.
  • "name": Sets a name for your new connector.
  • "topic.regex.list": A list of topics along with a regex expression of the files which are to be sent to that topic. In the example above, "kafka-topic-for-json:.*" sends all files to "kafka-topic-for-json". The expression "special-topic:.*\.json+*"" sends only files ending with ".json" to "special-topic". The connector ignores (doesn't source) other files not matching any patterns. The connector sends files that match multiple mappings to the first topic in the list that maps the file.
  • "kafka.auth.mode": Identifies the connector authentication mode you want to use. There are two options: SERVICE_ACCOUNT or KAFKA_API_KEY (the default). To use an API key and secret, specify the configuration properties kafka.api.key and kafka.api.secret, as shown in the example configuration (above). To use a service account, specify the Resource ID in the property kafka.service.account.id=<service-account-resource-ID>. To list the available service account resource IDs, use the following command:

    confluent iam service-account list
    

    For example:

    confluent iam service-account list
    
       Id     | Resource ID |       Name        |    Description
    +---------+-------------+-------------------+-------------------
       123456 | sa-l1r23m   | sa-1              | Service account 1
       789101 | sa-l4d56p   | sa-2              | Service account 2
    
  • "input.data.format": Supports Avro, JSON (schemaless), String, or Bytes. A valid schema must be available in Schema Registry to use a schema-based message format, like Avro. Refer to Confluent Cloud connector limitations for additional information.

  • "output.data.format": Defaults to the file format selected for the input message format. AVRO, BYTES, JSON, JSON_SR, PROTOBUF, and STRING. A valid schema must be available in Schema Registry if using a schema-based format.

  • "gcs.credentials.json": This contains the contents of the downloaded JSON file. See Formatting GCP credentials for details about how to format and use the contents of the downloaded credentials file.

  • "tasks.max": The total number of tasks to run in parallel. More tasks may improve performance.

  • Transforms and Predicates: See the Single Message Transforms (SMT) documentation for details.

For configuration property values and descriptions, see Configuration Properties.

Formatting GCP 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 the escape character \ 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 and other properties have been omitted.

    ちなみに

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

      {
          "connector.class": "GcsSource",
          "name": "GcsSourceConnector_0",
          "kafka.api.key": "<my-kafka-api-key>",
          "kafka.api.secret": "<my-kafka-api-secret>",
          ... omitted ...
          "gcs.credentials.json": "{\"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\"}",
          "tasks.max": "1"
      }
    
  3. Add all the converted string content to the "gcs.credentials.json" section of your configuration file as shown in the example above.

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

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

confluent connect create --config <file-name>.json

For example:

confluent connect create --config gcs-source-config.json

Example output:

Created connector GcsSourceConnector_0 lcc-ix4dl

Step 5: Check the connector status.

Enter the following command to check the connector status:

confluent connect list

Example output:

ID          |       Name             | Status  |  Type
+-----------+------------------------+---------+--------+
lcc-ix4dl   | GcsSourceConnector_0   | RUNNING | source

Step 6. Check the Kafka topic.

After the connector is running, verify records are populating the Kafka topic.

注釈

The GCS Source connector loads and filters all object names in the bucket before it starts sourcing records. When starting up, the connector may display RUNNING but not show any throughput. This is because bucket loading is not finished. For buckets with a large amount of objects, bucket loading can take several minutes to complete.

For more information and examples to use with the Confluent Cloud API for Connect, see the Confluent Cloud API for Connect section.

Configuration Properties

Use the following configuration properties with this connector.

How should we connect to your data?

name

Sets a name for your connector.

  • Type: string
  • Valid Values: A string at most 64 characters long
  • Importance: high

Which topic(s) do you want to send data to?

topic.regex.list

A list of topics along with a regex expression of the files which are to be sent to that topic. For example: "my-topic:.*" will send all files to "my-topic", while a list containing only the expression "special-topic:.*.json" will send only files starting with ".json" to "special-topic", and all other files not matching any patterns will be ignored and not sourced. Files that match multiple mappings will be sent to the first topic in the list that maps the file.

  • Type: list
  • Importance: high

Kafka Cluster credentials

kafka.auth.mode

Kafka Authentication mode. It can be one of KAFKA_API_KEY or SERVICE_ACCOUNT. It defaults to KAFKA_API_KEY mode.

  • Type: string
  • Default: KAFKA_API_KEY
  • Valid Values: KAFKA_API_KEY, SERVICE_ACCOUNT
  • Importance: high
kafka.api.key
  • Type: password
  • Importance: high
kafka.service.account.id

The Service Account that will be used to generate the API keys to communicate with Kafka Cluster.

  • Type: string
  • Importance: high
kafka.api.secret
  • Type: password
  • Importance: high

GCP credentials

gcs.credentials.json

GCP service account JSON file with read permissions for Google Cloud Storage.

  • Type: password
  • Importance: high

Google Cloud Storage details

gcs.bucket.name

The name of the GCS bucket.

  • Type: string
  • Importance: high
gcs.part.retries

Number of upload retries of a single GCS part. Zero means no retries

  • Type: int
  • Default: 3
  • Importance: medium
gcs.retry.backoff.ms

How long to wait in milliseconds before attempting the first retry of a failed GCS request. Upon a failure, this connector may wait up to twice as long as the previous wait, up to the maximum number of retries. This avoids retrying in a tight loop under failure scenarios.

  • Type: int
  • Default: 200
  • Importance: medium

Input and output messages

input.data.format

Sets the input message format. Valid entries are AVRO, JSON, or BYTES. Note that you need to have Confluent Cloud Schema Registry configured if using a schema-based message format like AVRO.

  • Type: string
  • Importance: high
output.data.format

Set the output Kafka record value format. Valid entries are AVRO, JSON_SR, PROTOBUF, JSON or BYTES. Note that you need to have Confluent Cloud Schema Registry configured if using a schema-based message format like AVRO. Note that the output message format defaults to the value in the Input Message Format field. If no value for this property is provided, the value specified for the 'input.data.format' property is used.

  • Type: string
  • Importance: high

Storage

topics.dir

Top-level directory (in the GCS bucket) where data to be ingested is stored.

  • Type: string
  • Default: topics
  • Importance: high
directory.delim

Directory delimiter pattern.

  • Type: string
  • Default: /
  • Importance: medium
behavior.on.error

Should the task halt when it encounters an error or continue to the next file.

  • Type: string
  • Default: FAIL
  • Importance: high
format.bytearray.separator

String inserted between records for ByteArrayFormat. Defaults to n and may contain escape sequences like n. An input record that contains the line separator looks like multiple records in the storage object input.

  • Type: string
  • Default: ""
  • Importance: medium
task.batch.size

The number of files assigned to each task at a time

  • Type: int
  • Default: 10
  • Valid Values: [1,...,2000]
  • Importance: high
file.discovery.starting.timestamp

A unix timestamp (seconds since Jan 1, 1970 UTC) that denotes where to start processing files. Any file encountered with a creation time earlier than this will be ignored.

  • Type: long
  • Default: 0
  • Importance: high

Data polling policy

gcs.poll.interval.ms

Frequency in milliseconds to poll for new or removed folders. This may result in updated task configurations starting to poll for data in added folders or stopping polling for data in removed folders

  • Type: long
  • Default: 60000 (1 minute)
  • Valid Values: [1000,...]
  • Importance: medium
record.batch.max.size

The maximum amount of records to return each time storage is polled.

  • Type: int
  • Default: 200
  • Valid Values: [1,...,10000]
  • Importance: medium

Number of tasks for this connector

tasks.max

The total number of tasks to run in parallel.

  • Type: int
  • Valid Values: [1,...,1000]
  • Importance: high

Next Steps

参考

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

../_images/topology.ja.png