<a id="cloud-config-client"></a>

# Kafka Client Quick Start for Confluent Cloud

You can write Kafka client applications to connect to Confluent Cloud in any supported
language. You just need to configure the clients using the Confluent Cloud cluster
credentials.

<!-- WARNING: THIS IS A SHARED FILE AND THE SOURCE IS LOCATED IN DOCS-COMMON. DO NOT ADD TO ANY OTHER REPO. -->

Official Confluent clients are available for:

- [Java](https://docs.confluent.io/clients-kafka-java/current/overview.html)
- [librdkafka](https://github.com/edenhill/librdkafka) and derived clients, including
  [Golang](https://github.com/confluentinc/confluent-kafka-go),
  [.NET](https://github.com/confluentinc/confluent-kafka-dotnet),
  and [Python](https://github.com/confluentinc/confluent-kafka-python)

This document covers how to properly configure a client. If you have already configured
a client and are looking for examples on writing a client application, see the “Hello, World!”
[code examples](/platform/current/tutorials/examples/clients/docs/clients-all-examples.html) that produce to and
consume from any Kafka cluster, including Confluent Cloud clusters.

## Security requirements

All clients must support TLS 1.2 encryption and either SASL_PLAIN or SASL_OAUTHBEARER
authentication. For detailed security configuration, certificate management,
and TLS requirements, see [Client Configuration Properties](client-configs.md#client-producer-consumer-config-recs-cc).

<a id="ccloud-clients"></a>

## Configure clients

Clients must be configured properly to connect to a Confluent Cloud cluster. For a subset
of client languages, you can also configure clients to connect to a Confluent Cloud Schema Registry cluster.

You can obtain a configuration file prefilled with necessary credentials either
from the Confluent Cloud Console or on the Confluent CLI.

### Configure clients from the Confluent Cloud Console

The easiest way to get started connecting your client apps to Confluent Cloud is to
copy and paste the configuration file from the Confluent Cloud Console.

1. Log in to Confluent Cloud.
2. Select an environment.
3. Select a cluster.
4. Select **Clients** from the navigation menu.
5. (Optional) Click **+ New client** button.
6. Select the language you are using for your client application.
   ![image](images/cloud-client-languages.png)
7. After you have selected a language, create or use existing API keys for your Kafka cluster and Schema Registry cluster as needed.
   Then, copy and paste the displayed configuration into your client application source code.
   ![image](images/cloud-client-configuration-example.png)

<a id="configure-clients-cli"></a>

### Configure clients from the Confluent CLI

For [Confluent CLI](https://docs.confluent.io/confluent-cli/current/overview.html) frequent users, once you
have set up context in the CLI, you can use one-line command [confluent kafka client-config create](https://docs.confluent.io/confluent-cli/current/command-reference/kafka/client-config/index.html#confluent-kafka-client-config)
to create a configuration file for connecting your client apps to Confluent Cloud.

The following table lists client languages, corresponding language ID, and
whether the language supports Confluent Cloud Schema Registry configuration. For languages that support
Confluent Cloud Schema Registry configuration, you can optionally configure it for your client apps by
passing Schema Registry information via the flags to the command.

<a id="client-language-table"></a>

| Language    | Language ID   | Support for Confluent Cloud Schema Registry   | Notes                                                                                                                                |
|-------------|---------------|-----------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|
| Clojure     | `clojure`     | No                                            |                                                                                                                                      |
| C/C++       | `cpp`         | No                                            | See examples: [C/C++ examples (librdkafka)](https://github.com/edenhill/librdkafka/tree/master/examples)                             |
| C#          | `csharp`      | No                                            |                                                                                                                                      |
| Go          | `go`          | Yes                                           | See examples: [confluent-kafka-go/examples](https://github.com/confluentinc/confluent-kafka-go/tree/master/examples)                 |
| Groovy      | `groovy`      | No                                            |                                                                                                                                      |
| Java        | `java`        | Yes                                           |                                                                                                                                      |
| Kotlin      | `kotlin`      | No                                            |                                                                                                                                      |
| Ktor        | `ktor`        | Yes                                           |                                                                                                                                      |
| JavaScript  | `javascript`  | Yes                                           | See examples: [confluent-kafka-javascript/examples](https://github.com/confluentinc/confluent-kafka-javascript/tree/master/examples) |
| Python      | `python`      | Yes                                           | See examples: [confluent-kafka-python/examples](https://github.com/confluentinc/confluent-kafka-python/tree/master/examples)         |
| REST API    | `restapi`     | Yes                                           |                                                                                                                                      |
| Ruby        | `ruby`        | No                                            |                                                                                                                                      |
| Rust        | `rust`        | No                                            |                                                                                                                                      |
| Scala       | `scala`       | No                                            |                                                                                                                                      |
| Spring Boot | `springboot`  | Yes                                           |                                                                                                                                      |

Prerequisites:
: - [Access to Confluent Cloud](https://www.confluent.io/confluent-cloud/) with an active cluster.
  - [Install the Confluent CLI](https://docs.confluent.io/confluent-cli/current/install.html).

1. Log in to your cluster using the [confluent login](https://docs.confluent.io/confluent-cli/current/command-reference/confluent_login.html) command with the cluster URL specified.
   ```none
   confluent login
   ```

   ```none
   Enter your Confluent Cloud credentials:
   Email: susan@myemail.com
   Password:
   ```
2. Set the Confluent Cloud [environment](../security/access-control/hierarchy/cloud-environments.md#cloud-environments).
   1. Get the environment ID.
      ```none
      confluent environment list
      ```

      Your output should resemble:
      ```none
            Id       |        Name
      +--------------+--------------------+
        * t2703      | default
          env-abc123 | demo-env-102893
          env-xyz123 | ccloud-demo
          env-wxy123 | data-lineage-demo
          env-abc12d | my-new-environment
      ```
   2. Set the environment using the ID (`<env-id>`).
      ```none
      confluent environment use <env-id>
      ```

      Your output should resemble:
      ```none
      Now using "env-xyz123" as the default (active) environment.
      ```
3. Set the cluster to use.
   1. Get the cluster ID.
      ```none
      confluent kafka cluster list
      ```

      Your output should resemble:
      ```none
            Id      |   Name    | Type  | Cloud    |  Region  | Availability | Status
      +-------------+-----------+-------+----------+----------+--------------+--------+
          lkc-oymmj | cluster_1 | BASIC | gcp      | us-east4 | single-zone  | UP
        * lkc-7k6kj | cluster_0 | BASIC | gcp      | us-east1 | single-zone  | UP
      ```
   2. Set the cluster using the ID (`<cluster-id>`). This is the cluster where the commands are run.
      ```none
      confluent kafka cluster use <cluster-id>
      ```

      To verify the selected cluster after setting it, type `confluent kafka cluster list` again.
      The selected cluster will have an asterisk (`*`) next to it.
4. Create an API key and secret, and save them.

   You can generate the API key on the Confluent CLI or from the Confluent Cloud Console. Be sure to save the API key and secret.

   You can use either a Kafka cluster API key scoped to the specific cluster or a
   [global API key](../security/authenticate/workload-identities/service-accounts/api-keys/overview.md#cloud-global-api-keys). A global API key works identically
   to a Kafka cluster key for client authentication. Use the same `sasl.username`
   and `sasl.password` configuration fields. Global API keys are useful when your
   application connects to multiple clusters or also accesses other Confluent Cloud resources
   such as Schema Registry or Flink.

   #### NOTE
   Global API keys do not support [Basic](../clusters/cluster-types.md#basic-cluster) and [Standard](../clusters/cluster-types.md#standard-cluster) Kafka clusters. For those
   cluster types, use a resource-scoped Kafka cluster API key.

   ### Confluent CLI

   1. Run the following command to create the API key and secret, using the ID (`<cluster-id>`).
      ```bash
      confluent api-key create --resource <cluster-id>
      ```

      Your output should resemble:
      ```none
      It may take a couple of minutes for the API key to be ready.
      Save the API key and secret. The secret is not retrievable later.
      +---------+------------------------------------------------------------------+
      | API Key | ABC123xyz                                                        |
      | Secret  | 123xyzABC123xyzABC123xyzABC123xyzABC123xyzABC123xyzABC123xyzABCx |
      +---------+------------------------------------------------------------------+
      ```

      For more information, see [Use API Keys to Authenticate to Confluent Cloud](../security/authenticate/workload-identities/service-accounts/api-keys/overview.md#cloud-api-key-resource).

   ### Confluent Cloud Console

   1. In the console, click the **Kafka API keys** tab and click **Create key**.
      Save the key and secret, then click the checkbox next to **I have saved my API key and secret
      and am ready to continue.**
      ![image](images/cloud-api-key-confirm.png)
   2. Add the API secret with `confluent api-key store <key> <secret>`. When you create an API
      key with the CLI, it is automatically stored locally. However, when you create an API key using
      the console, API, or with the CLI on another machine, the secret is not available for CLI use until
      you store it. This is required because secrets cannot be retrieved after creation.
      ```bash
      confluent api-key store <api-key> <api-secret> --resource <cluster-id>
      ```

      For more information, see [Use API Keys to Authenticate to Confluent Cloud](../security/authenticate/workload-identities/service-accounts/api-keys/overview.md#cloud-api-key-resource).
5. Set the API key to use for Confluent CLI commands, using the ID (`<cluster-id>`).
   ```none
   confluent api-key use <api-key> --resource <cluster-id>
   ```
6. Create a client configuration file for the language of your choice, using language ID (`<language-id>`). Then,
   copy and paste the displayed configuration into your client application source code.

   See [Client Language Table](#client-language-table) for a list of language IDs and whether the language supports Schema Registry configuration.
   - For the output of command `confluent kafka client-config create <language-id>`, the client configuration file
     is printed to **stdout** and the errors or warnings are printed to **stderr**.

     You can redirect the command output to separate files by doing the following:
     ```bash
     confluent kafka client-config create <language-id> 1> config-file.config 2> errors-warnings-file.err
     ```
   - If you do not want to use the CLI context, you can alternatively pass all the necessary information via flags:
     ```bash
     confluent kafka client-config create <language-id> \
       --environment <env-id> \
       --cluster <cluster-id> \
       --api-key <api-key> --api-secret <api-secret> \
       --schema-registry-api-key <api-key> --schema-registry-api-secret <api-secret> # only for languages that support Schema Registry configuration
     ```
   - For languages that do NOT support Schema Registry configuration, run the following command:
     ```bash
     confluent kafka client-config create <language-id>
     ```
   - For languages that support Schema Registry configuration, run the following command:
     ```bash
     confluent kafka client-config create <language-id> \
       --schema-registry-api-key <api-key> \
       --schema-registry-api-secret <api-secret>
     ```

### Related content

* For tips and recommendations for configuring resilient clients, see
  [Client Configuration Settings for Confluent Cloud](client-configs.md#client-producer-consumer-config-recs-cc).
* For more information about using the CLI, see [confluent kafka client-config
  create](https://docs.confluent.io/confluent-cli/current/command-reference/kafka/client-config/index.html#confluent-kafka-client-config).
