I want to connect to kraft controller on port 9093 (non broker). And I can't to connect
code example:
#!/usr/bin/env python3
from confluent_kafka.admin import AdminClient
import json
import os
credentials = 'credentials/example.json'
with open(credentials, 'r') as json_file:
data = json.load(json_file)
conf = {
'bootstrap.servers': 'kafkacontroller1.example.com:9093',
'security.protocol': 'SASL_SSL',
'ssl.ca.location': os.path.abspath('./credentials/example/ca_cert'),
'ssl.certificate.location': os.path.abspath('./credentials/example/ca'),
'ssl.key.location': os.path.abspath('./credentials/example/ca_key'),
'ssl.key.password': data['SSLKeyPassword'],
'sasl.mechanism': 'PLAIN',
'sasl.username': data['username'],
'sasl.password': data['password'],
'enable.ssl.certificate.verification': 'false',
'debug': 'security,broker,protocol'
}
admin_client = AdminClient(conf)
try:
cluster_metadata = admin_client.list_topics(timeout=10)
controller_id = cluster_metadata.controller_id
print(f"Controller ID: {controller_id}")
brokers = cluster_metadata.brokers
print(f"Total brokers: {len(brokers)}")
print(f"Number of controllers: {1 if controller_id else 0}")
except Exception as e:
print(f"Error occurred: {e}")
Of course it didn't connect. The code example provided works fine with the broker, but does not work at all with the controller. So the question is - should I even try to connect to the controller? If so, how and what will I see there? I would expect to get some kind of understandable cluster state from the controller, if possible.
Short answer is no - the Raft controllers are exclusively for a broker and the bootstrap server config is exclusively for discovering brokers. The AdminClient will find the cluster leader broker node and properly translate any requests.