Connect to the cluster
The Kafka cluster can be connected to by DNS address and IP address.
We recommend connecting by DNS address because DNS addresses correspond to node roles and lead to the actual IP addresses of the master and replicas. IP addresses correspond to specific nodes. If the master is unavailable, one of the replicas will assume its role, the master's IP address will change, and the IP connection will stop working.
If the cluster is connected to a private subnet and you want to work with it via DNS, connect the cluster subnet to a cloud router with access to the external network. Use the following instructions Set up internet access via cloud router.
A public IP address cannot be used.
Ports
Use ports to connect to Kafka:
- 9092 — port for connection without SSL certificate;
- 9093 — port for connection with SSL certificate.
Ways of connection
- through the kcat terminal client;
- from program code with SSL и without SSL.
View the address for connection
- В control panels go to Cloud platform → Databases.
- Open the Database Cluster page → tab Connection.
- In the block Addresses for connection check out the address.
Connect with SSL
Connecting using TLS/SSL encryption provides a secure connection between your server and the database cluster.
Bash
Python (confluent-kafka)
Python (kafka-python)
Node.js
Java
-
Download the root certificate and place it in the folder
~/.kafka/
:mkdir -p ~/.kafka/
wget https://storage.dbaas.selcloud.ru/CA.pem -O ~/.kafka/root.crt
chmod 600 ~/.kafka/root.crt -
Use the connection example for the concumer:
kcat -C \
-b <host>:9093 \
-t <topic_name> \
-X sasl.username=<user_name> \
-X sasl.password=<password> \
-X security.protocol=SASL_SSL \
-X sasl.mechanisms=SCRAM-SHA-512 \
-X ssl.ca.location=~/.kafka/root.crtSpecify:
<host>
— DNS address of the node;<topic_name>
— TOPIC NAME;<user_name>
— the name of the user with the role of concumer who has access to the topic;<password>
— user password.
-
Use the connection example for the producer:
kcat -C \
-b <host>:9093 \
-t <topic_name> \
-X sasl.username=<user_name> \
-X sasl.password=<password> \
-X security.protocol=SASL_SSL \
-X sasl.mechanisms=SCRAM-SHA-512 \
-X ssl.ca.location=~/.kafka/root.crtSpecify:
<host>
— DNS address of the node;<topic_name>
— TOPIC NAME;<user_name>
— the name of the user with the producer role who has access to the topix;<password>