# Kafka

These instructions apply to the current Admin Console.

## Description

The **Kafka** connection type (`kafka`) connects a Flow or Agent to an external Apache Kafka broker to send or receive messages.

## Required Information

After you select this type in **Connection Type**, the console asks for the following fields. Every connection also has a **Connection ID**, **Connection Name**, and **Connection Type**.

| **Field**          | **Required** | **Description**                                                                                                                                                                                                                            |
|--------------------|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **Brokers**        | Yes          | One or more broker addresses, for example `broker1.example.com:9092`. Select **Add** to add each broker.                                                                                                                                   |
| **Topic Template** | No           | A template for the full topic name. The topic name provided by the Flow is inserted at `${topicName}`. See the example below.                                                                                                              |
| **Mechanism**      | Yes          | How Contextual authenticates to the broker: `plain`, `scram-sha-256`, `scram-sha-512`, or `oauthbearer`. Choose the mechanism your Kafka broker is configured to accept. The credential fields depend on this choice.                      |
| **Partitioner**    | No           | Select **default** for new connections.                                                                                                                                                                                                    |
| **Headers**        | No           | Optional key-value headers attached to messages produced through this connection. Under **Headers**, select **Add**, then enter a **Key** and **Value**. Values are masked like other secrets. Select **Remove entry** to delete a header. |

### Mechanisms

| **Mechanism**                      | **Additional required fields**                                    | **Notes**                                                                                                                                                                                                                       |
|------------------------------------|-------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `plain`                            | **Username**, **Password**                                        | Sends the username and password directly. Use only when the connection to the broker is encrypted with TLS.                                                                                                                     |
| `scram-sha-256`<br>`scram-sha-512` | **Username**, **Password**                                        | Username and password authentication where the password is never sent over the network. The broker checks a value derived from it instead. Choose the variant (SHA-256 or SHA-512) that your Kafka broker is configured to use. |
| `oauthbearer`                      | **Client ID**, **Client Secret**, **Auth Endpoint**, **Audience** | Authenticates with an OAuth 2.0 access token, which Contextual obtains using the Client ID, Client Secret, Auth Endpoint, and Audience.                                                                                         |

### Topic Template Example

With a **Topic Template** of `myenv.myapplication.${topicName}`, a Flow that specifies the topic name `mytopic` sends to the fully qualified topic `myenv.myapplication.mytopic`.
