I have properties.config
file and kafka.client.truststore.jsk
and I can easily get data from kafka with kafka-console-consumer
in console using :
kafka-console-consumer --topic test-topic --group group-id --bootstrap-server server:port --consumer.config config.properties
In config.properties file I have :
sasl_mechanism='PLAIN',
security_protocol='SASL_SSL',
sasl_jaas_config='''org.apache.kafka.common.security.plain.PlainLoginModule required \
username="sasl_username" \
password="sasl_password";'''
ssl_truststore_location='kafka.client.truststore.jks'
ssl_truststore_password='truststore_password'
But I want receive and process these data in python. So using keytool
I convert jsk file to CARoot.pem
and certificate.pem
and use them in python-confluent-kafka :
consumer_config = {
'bootstrap.servers': server:port,
'group.id': group_id,
'auto.offset.reset': 'earliest',
'enable.auto.commit': 'false',
'max.poll.interval.ms': '86400000',
'sasl.mechanism': 'PLAIN',
'security.protocol': 'SASL_SSL',
'ssl.ca.location':'CARoot.pem',
'ssl.certificate.location':'certificate.pem',
'sasl.username': 'sasl_username',
'sasl.password': 'sasl_password'
}
consumer = Consumer(consumer_config)
consumer.subscribe([test-topic])
But what i see in the console is :
%3|1653299842.609|FAIL|rdkafka#consumer-12| [thrd:sasl_ssl://server:port/bootstrap]: sasl_ssl://server:port/bootstrap: SASL authentication error: Authentication failed: Invalid username or password (after 179ms in state AUTH_REQ)
I expect to see data in output same as kafka-console-consumer
.
I try pykafka and python-kafka too. But There is no difference.
Note : I convert jsk to pem using this tutorial.