> ## Documentation Index
> Fetch the complete documentation index at: https://upstash-vector.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect Using kaf CLI

[kaf](https://github.com/birdayz/kaf) is a modern CLI for Apache Kafka. You can
connect to your Upstash Kafka cluster using `kaf`.

<Info>
  If you do not have a Kafka cluster and/or topic already, follow [these
  steps](../overall/getstarted) to create one.
</Info>

In the cluster details section of the
[Upstash Console](https://console.upstash.com) copy bootstrap endpoint, username
and password. Then replace following parameters in the code snippets below with
the actual values you copied earlier.

* `$BOOTSTRAP_ENDPOINT`
* `$UPSTASH_KAFKA_USERNAME`
* `$UPSTASH_KAFKA_PASSWORD`
* `$GROUP_ID`
* `$TOPIC_NAME`

Initially we should add cluster configuration to `kaf`'s config file, which
should be located in `~/.kaf/config`. Open config file if it exists or create an
empty one and insert following config:

```yaml
clusters:
  - name: $CLUSTER_NAME
    brokers:
      - $BOOTSTRAP_ENDPOINT
    SASL:
      mechanism: SCRAM-SHA-512
      username: $UPSTASH_KAFKA_USERNAME
      password: $UPSTASH_KAFKA_PASSWORD
    security-protocol: SASL_SSL
```

<Note>
  `$CLUSTER_NAME` is a logical name, which is used to identify different Kafka
  cluster. You can use your Upstash cluster name.
</Note>

To select the cluster configuration to use, run:

```shell
kaf config use-cluster $CLUSTER_NAME
```

At this point you should be able to connect to your Kafka cluster using `kaf`.

**List Brokers and Topics:**

```shell
kaf nodes
```

```shell
kaf topics
```

**Produce a message:**

```shell
echo "Hello Upstash!" | kaf produce $TOPIC_NAME
```

**Fetch messages:**

```shell
kaf consume $TOPIC_NAME
```

**Consume messages using consumer groups:**

```shell
kaf consume $TOPIC_NAME -g $GROUP_ID --offset oldest
```

For more information see [kaf](https://github.com/birdayz/kaf) repository.
