Skip to main content

Connect to the Kafka cluster

The Kafka cluster can be connected to:

  • through the kcat terminal client;
  • program code.

SSL and non-SSL connections are available for all methods.

Specify the port and address when connecting.

Connection ports

Use ports to connect to Kafka:

  • 9092 — port for connection without SSL certificate;
  • 9093 — port for connection with SSL certificate.

Addresses for connection

The address to connect to depends on the cluster subnet and where you are connecting from. You can select an address depending on one of the scenarios:

You cannot connect to a cluster on a private subnet from the Internet.

Connecting to a cluster on a public subnet

If the cluster is on a public subnet, the nodes can be connected to by DNS address or IP address from the public subnet.

We recommend connecting by DNS address. For DNS addresses in the cluster, the master discovery mechanism is used — the address is bound to the node role, not to the node itself. If the master is unavailable, one of the replicas becomes the new master and the address is transferred to the new node along with the role.

When connecting using an IP address from a public subnet, the master discovery mechanism is not used. If one of the replicas becomes the new master, the master IP address will change and the connection to the old IP address will not work.

You can view the address to connect to in the control panel.

Connecting from a private subnet to a cluster on a private subnet

If you are connecting from a private subnet to a cluster on a private subnet, you can use a DNS address or a private IP address.

We recommend connecting by DNS address. For DNS addresses in the cluster, the master discovery mechanism is used — the address is bound to the node role, not to the node itself. If the master is unavailable, one of the replicas becomes the new master and the address is transferred to the new node along with the role.

When connecting by private IP address, the master discovery mechanism is not used. If one of the replicas becomes the new master, the master IP address will change and the connection using the old IP address will not work.

To connect from another private subnet, first connect both private subnets to the cloud router.

You can view the address to connect to in the control panel.

View the address for connection

  1. In the Dashboard, on the top menu, click Products and select Cloud Databases.
  2. Open the Active tab.
  3. Open the Database Cluster page → Connection tab.
  4. 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 0600 ~/.kafka/root.crt
  2. Use the connection example for the concumer:

    kcat -C \
    -b <host>:<port> \
    -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=$HOME/.kafka/root.crt

    Specify:

    • <host> — DNS address of the node;
    • <port> — port for connection;
    • <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.
  3. Use the connection example for the producer:

    kcat -P \
    -b <host>:<port> \
    -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=$HOME/.kafka/root.crt

    Specify:

    • <host> — DNS address of the node;
    • <port> — port for connection;
    • <topic_name> — topic name;
    • <user_name> — the name of the user with the producer role who has access to the topic;
    • <password> — user password.

Connect without SSL

  1. Open the CLI.

  2. Use the connection example for the concumer:

    kcat -C \
    -b <host>:<port> \
    -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;
    • <port> — port for connection;
    • <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.
  3. Use the connection example for the producer:

    kcat -P \
    -b <host>:<port> \
    -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;
    • <port> — port for connection;
    • <topic_name> — topic name;
    • <user_name> — the name of the user with the producer role who has access to the topic;
    • <password> — user password.