Skip to main content
Connect to the cluster
Last update:

Connect to the cluster

The Kafka cluster can be connected to by DNS address and IP address.

We recommend connecting by DNS address because the DNS addresses correspond to the 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 cloud router-to-external-network to the cluster subnet.

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 to connect

View the address to connect

  1. In Control Panel, go to Cloud PlatformDatabases.
  2. Open the Database Cluster page → Connect tab.
  3. In the Addresses to connect block, look up the address.

Connect with SSL

Connecting using TLS/SSL encryption provides a secure connection between your server and the database cluster.

  1. Download the root certificate and place it in the ~/.kafka/ folder:

    mkdir -p ~/.kafka/
    wget https://storage.dbaas.selcloud.ru/CA.pem -O ~/.kafka/root.crt
    chmod 600 ~/.kafka/root.crt
  2. Use the connection example for the concumer:

    kafkacat -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.crt

    Specify:

    • <host> — DNS address of the node;
    • <topic_name> is the name of the topic;
    • <user_name> is the name of the user with the role of consumer who has access to the topix;
    • <password> is the user's password.
  3. Use the connection example for the producer:

    kafkacat -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.crt

    Specify:

    • <host> — DNS address of the node;
    • <topic_name> is the name of the topic;
    • <user_name> is the username of the user with the producer role who has access to the topic;
    • <password> is the user's password.

Connect without SSL

  1. Open the CLI.

  2. Use the connection example for the concumer:

    kafkacat -C \
    -b <host>:9092 \
    -t <topic_name> \
    -X sasl.username=<user_name> \
    -X sasl.password=<password> \
    -X security.protocol=SASL_PLAINTEXT \
    -X sasl.mechanisms=SCRAM-SHA-512.

    Specify:

    • <host> — DNS address of the node;
    • <topic_name> is the name of the topic;
    • <user_name> is the name of the user with the role of consumer who has access to the topix;
    • <password> is the user's password.
  3. Use the connection example for the producer:

    kafkacat -P \
    -b <host>:9092 \
    -t <topic_name> \
    -X sasl.username=<user> \
    -X sasl.password=<password> \
    -X security.protocol=SASL_PLAINTEXT \
    -X sasl.mechanisms=SCRAM-SHA-512

    Specify:

    • <host> — DNS address of the node;
    • <topic_name> is the name of the topic;
    • <user_name> is the username of the user with the producer role who has access to the topic;
    • <password> is the user's password.