---
source_url: https://www.pubnub.com/docs/serverless/events-and-actions/actions/create-kafka-action
title: Create Kafka action
updated_at: 2026-06-12T11:27:18.395Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Create Kafka action

To send PubNub data to Kafka, first configure your Kafka environment and then create a Kafka Action in the [Admin Portal](#configure-admin-portal).

For [Events & Actions](https://www.pubnub.com/docs/serverless/events-and-actions/overview), hosting is agnostic. Configure the Kafka Action in the [Admin Portal](https://admin.pubnub.com/) to connect to any supported cluster.

:::tip Receive Kafka events in PubNub
Besides streaming PubNub events to Kafka using a Kafka Action, you can also receive Kafka events in PubNub. See the [PubNub Kafka Sink Connector](https://www.pubnub.com/docs/general/integrations/kafka/pubnub-kafka-sink-connector).
:::

## Existing Kafka cluster

You need the following information to connect Events & Actions to [Apache Kafka](https://kafka.apache.org/):

* Topic and key
* Broker URL and port
* Username and password

Then go to the [Configure Admin Portal](#configure-admin-portal) section.

## New Kafka cluster

There are many ways to create and host Kafka clusters. The Kafka Action in Events & Actions is technology‑agnostic. Regardless of where you host Kafka, the Kafka Action can connect.

If you need guidance on creating a cluster, read on.

### Self-hosted Kafka

Use the [Kafka Quick Start](https://kafka.apache.org/documentation/#quickstart) to create a local Kafka cluster. Have this information ready to create a Kafka Action:

* Topic and key
* Broker URL and port
* Username and password

After you create the cluster and gather this information, follow [Configure Admin Portal](#configure-admin-portal).

### Amazon MSK cluster using Terraform

Use the [Terraform](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/msk_cluster) guide to create an Amazon MSK cluster. Have this information ready to create a Kafka Action:

* Topic and key
* Broker URL and port
* Username and password

After you create the cluster and gather this information, follow [Configure Admin Portal](#configure-admin-portal).

### Confluent Cloud

This procedure uses the [Confluent Cloud](https://confluent.cloud) UI to set up your Kafka environment. It has three parts:

1. [Configure a Kafka cluster](#configure-a-kafka-cluster).
2. [Create a topic](#create-a-kafka-topic).
3. [Create an API key](#create-api-key).

For more on creating clusters on Confluent Cloud, see [Quick Start for Confluent Cloud](https://docs.confluent.io/cloud/current/get-started/index.html).

#### Configure a Kafka cluster

Create a cluster first. Then:

1. Log in to [Confluent Cloud](https://confluent.cloud) and create a Kafka cluster to receive PubNub messages.
2. Select the cloud provider and cluster type. Complete the wizard.
3. After the cluster launches, open **Cluster Settings** and note the **Bootstrap server**. You will need it in the Admin Portal.

#### Create a Kafka topic

Create a Kafka topic before sending PubNub data. Creating the topic first ensures delivery.

To create a topic:

1. On the cluster overview page in [Confluent Cloud](https://confluent.cloud), click **Topics**.
2. On the **Topics** page, click **Create topic** and configure it.
3. After the topic is created, note its name. You will need it in the Admin Portal.

#### Create API key

Use secure connections by setting up Kafka credentials.

To create an API key:

1. On the cluster overview page in [Confluent Cloud](https://confluent.cloud), click **API keys**. The **API keys** page opens.
2. On the **API keys** page, click **Create key** and configure it. Secret visibilityDo not click Download and continue yet. Doing so hides the Secret credential.
3. Note the **Key** and **Secret** values. You will need them in the Admin Portal.
4. Click **Download and continue** to finish creating the key.

## Configure Admin Portal

1. In the **Events & Actions** view on the [Admin Portal](https://admin.pubnub.com/), click **+ Add Action**.
2. Select **Apache Kafka** as the action type.
3. In **Routing Key**, enter your topic, for example, `topic_0`.
4. To add a key, enter `topic:key`, for example, `topic_0:stamford`. Key and message orderEach message sent to a topic may include a key. Kafka partitions topics and guarantees order only within the same partition. Adding a key ensures messages go to the same partition and preserves order.
5. In **Authentication Mechanism**, select the type your Kafka setup uses. Supported types include [SASL/PLAIN](https://docs.confluent.io/platform/current/kafka/authentication_sasl/authentication_sasl_plain.html#kafka-sasl-auth-plain), [SCRAM-SHA-256](https://docs.confluent.io/platform/current/kafka/authentication_sasl/authentication_sasl_scram.html#kafka-sasl-auth-scram), and [SCRAM-SHA-512](https://docs.confluent.io/platform/current/kafka/authentication_sasl/authentication_sasl_scram.html#kafka-sasl-auth-scram).
6. In **Username**, enter your Kafka username. In Confluent Cloud, this is the **Key** you noted when you [created an API key](#create-api-key). Secure connectionsUse secure connections. PubNub blocks unsecured connections to Kafka.
7. In **Password**, enter your Kafka password. In Confluent Cloud, this is the **Secret** you noted when you [created an API key](#create-api-key).
8. In **Brokers**, enter the cluster URL, for example, `574mf0rd-bridge.ldn-west:1905`. In Confluent Cloud, use the **Bootstrap server** from [Configure a Kafka cluster](#configure-a-kafka-cluster). Broker listYou can provide a list in this format: hostname:port, hostname2:port.
9. (Optional) Enable and configure [retries](https://www.pubnub.com/docs/serverless/events-and-actions/events#retries) in **Kafka retry**.
10. Pair the action with an event listener. Click **Add event listener** and select an existing listener or [create one](https://www.pubnub.com/docs/serverless/events-and-actions/configure-e&a#create-event-listener). Link it to a listener that captures the events you want.
11. Click **Save changes**.

## Terms in this document

* **Listener** - A function or objectthat reacts to events or messages, like new chat messages or connection updates, letting your app respond in real-time.
* **PubNub** - PubNub is a real-time messaging platform that provides APIs and SDKs for building scalable applications. It handles the complex infrastructure of real-time communication, including: Message delivery and persistence, Presence detection, Access control, Push notifications, File sharing, Serverless processing with Functions and Events & Actions, Analytics and monitoring with BizOps Workspace, AI-powered insights with Illuminate.
