Create Kafka action

To send PubNub data to Kafka, first configure your Kafka environment and then create a Kafka Action in the Admin Portal.

For Events & Actions, hosting is agnostic. Configure the Kafka Action in the Admin Portal to connect to any supported cluster.

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.

Existing Kafka cluster

You need the following information to connect Events & Actions to Apache Kafka:

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

Then go to the 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.

Use the Kafka Quick Start 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

  1. In the Events & Actions view on the Admin Portal, 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 order

    Each 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, SCRAM-SHA-256, and SCRAM-SHA-512.
  6. In Username, enter your Kafka username. In Confluent Cloud, this is the Key you noted when you created an API key.
    Secure connections

    Use 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.
  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.
    Broker list

    You can provide a list in this format: hostname:port, hostname2:port.

  9. (Optional) Enable and configure retries in Kafka retry.
  10. Pair the action with an event listener. Click Add event listener and select an existing listener or create one. Link it to a listener that captures the events you want.
  11. Click Save changes.
Last updated on