Getting started with Managed Service for Apache Kafka®
To get started:
Getting started
-
Navigate to the management console
and log in to Yandex Cloud or sign up if not signed up yet. -
If you do not have a folder yet, create one:
-
In the management console
, in the top panel, click and select the cloud. -
To the right of the cloud name, click
. -
Select Create folder
.
-
Give your folder a name. The naming requirements are as follows:
- Length: between 3 and 63 characters.
- It can only contain lowercase Latin letters, numbers, and hyphens.
- It must start with a letter and cannot end with a hyphen.
-
Optionally, specify the description for your folder.
-
Select Create a default network. This will create a network with subnets in each availability zone. Within this network, you will also have a default security group, within which all network traffic will be allowed.
-
Click Create.

-
-
Assign the vpc.user role and the managed-kafka.editor role or higher to your Yandex Cloud account. These roles allow creating a cluster.
Note
If you cannot manage roles, contact your cloud or organization administrator.
-
You can connect to an Apache Kafka® cluster from both inside and outside Yandex Cloud:
-
Connect to your VM over SSH.
Note
It is assumed that you are connecting to the cluster from a Linux VM.
-
Install
kafkacat, an open-source tool for producing and consuming data:sudo apt-get install kafkacatMake sure you can use it to connect to the Managed Service for Apache Kafka® source cluster over SSL.
Create a cluster
To create a cluster:
- In the management console, select the folder where you want to create a cluster.
- Go to Managed Service for Kafka.
- Click Create cluster.
- Configure your cluster and click Create. For more information, see Creating a cluster.
- Wait until the cluster is ready: its status on the Managed Service for Apache Kafka® dashboard will change to
Running, and its state, toAlive. This may take a while.
Then create a topic in the cluster.
Create a topic
A topic is used to group message streams by category. Producers write messages to a topic, and consumers read messages from it.
To create a topic:
- In the management console, select the folder with the cluster.
- Go to Managed Service for Kafka.
- Click the name of the cluster you created earlier and select the Topics tab.
- Click Create topic.
- Specify the topic settings and click Create. For details, see Managing Apache Kafka® topics.
Then create users for producers and consumers.
Create a user
User settings enable you to manage producer and consumer permissions for cluster topics.
Learn more about the permissions you get with each role here.
To create a user:
- In the management console, select the folder with the cluster.
- Go to Managed Service for Kafka.
- Click the cluster name and select the Users tab.
- Click Create user.
- Enter a username and password (from 8 to 128 characters).
- Click
Add topic and select the previously created topic from the drop-down list. - Grant access permissions for this topic to the producer and consumer. For more information, see User management.
- Click Create.
Then connect to the cluster as this user.
Connect to the cluster
You can connect both the producer and consumer to the cluster as the same user. Both the producer and the consumer can work only with the topics that this user has access to.
To connect to your cluster:
-
If you are using security groups for your cloud network, configure them to allow all relevant traffic between the cluster and the connecting host.
-
Install an SSL certificate on the VM:
Linux (Bash)/macOS (Zsh)Windows (PowerShell)mkdir -p /usr/local/share/ca-certificates/Yandex/ && \ wget "https://storage.yandexcloud.net/cloud-certs/CA.pem" \ --output-document /usr/local/share/ca-certificates/Yandex/YandexInternalRootCA.crt && \ chmod 0655 /usr/local/share/ca-certificates/Yandex/YandexInternalRootCA.crtThe certificate will be saved to the
/usr/local/share/ca-certificates/Yandex/YandexInternalRootCA.crtfile.mkdir $HOME\.kafka; curl.exe -o $HOME\.kafka\YandexInternalRootCA.crt https://storage.yandexcloud.net/cloud-certs/CA.pemThe certificate will be saved to the
$HOME\.kafka\YandexInternalRootCA.crtfile.Your corporate security policies and antivirus software may block the certificate download. For more information, see FAQ.
-
To send a message to a topic, run this command:
echo "test message" | kafkacat -P \ -b <broker_FQDN>:9091 \ -t <topic_name> \ -k key \ -X security.protocol=SASL_SSL \ -X sasl.mechanism=SCRAM-SHA-512 \ -X sasl.username="<producer_login>" \ -X sasl.password="<producer_password>" \ -X ssl.ca.location=/usr/local/share/ca-certificates/Yandex/YandexInternalRootCA.crt -ZIn the command, specify the broker FQDN, topic name, username and password of the Apache Kafka® user you created earlier.
To learn how to get a broker host FQDN, see this guide.
-
To get messages from a topic, run the following command:
kafkacat -C \ -b <broker_FQDN>:9091 \ -t <topic_name> \ -X security.protocol=SASL_SSL \ -X sasl.mechanism=SCRAM-SHA-512 \ -X sasl.username="<consumer_username>" \ -X sasl.password="<consumer_password>" \ -X ssl.ca.location=/usr/local/share/ca-certificates/Yandex/YandexInternalRootCA.crt -Z -K:In the command, specify the broker FQDN, topic name, username and password of the Apache Kafka® user you created earlier.
To learn how to get a broker host FQDN, see this guide.
For a detailed description of the Managed Service for Apache Kafka® cluster connection process, see Connecting to topics in a cluster.
What's next
- Read about the service concepts.
- Learn more about creating a cluster and connecting to a cluster.