2017-03-23 1 views
1

SASL_SSL (인증 (JAAS) 및 인증)이 활성화 된 Kafka10 클러스터가 있습니다. 자바 클라이언트를 사용하여 아래의 소품과 SASL을 통해 연결할 수 있습니다.Kafka 10 - 인증 및 권한이있는 Python 클라이언트

그리고 JAAS conf 파일을 JVM 매개 변수를 통해 전달합니다.

-Djava.security.auth.login.config=/path/to/client_jaas.conf 

어쨌든 파이썬 클라이언트에서 같은 것을 달성 할 수 있습니까?

답변

2

나는 다음과 같은 코드를 사용하여 후드 카프카 인 IBM의 메시지 허브에 연결했습니다 :

from kafka import KafkaProducer 
from kafka.errors import KafkaError 
import ssl 

sasl_mechanism = 'PLAIN' 
security_protocol = 'SASL_SSL' 

# Create a new context using system defaults, disable all but TLS1.2 
context = ssl.create_default_context() 
context.options &= ssl.OP_NO_TLSv1 
context.options &= ssl.OP_NO_TLSv1_1 

producer = KafkaProducer(bootstrap_servers = app.config['KAFKA_BROKERS_SASL'], 
         sasl_plain_username = app.config['KAFKA_USERNAME'], 
         sasl_plain_password = app.config['KAFKA_PASSWORD'], 
         security_protocol = security_protocol, 
         ssl_context = context, 
         sasl_mechanism = sasl_mechanism, 
         api_version = (0,10), 
         retries=5) 

def send_message(message): 

    try: 
     producer.send(app.config['KAFKA_TOPIC'], message.encode('utf-8')) 
    except: 
     print("Unexpected error:", sys.exc_info()[0]) 
     raise 
관련 문제