How to run kafka in OAUTHBEARER test mode.

2024-06-17 14:46:12 浏览数 (4)

  1. config the server.properties to run with SASL OAUTHBEARER test mode
代码语言:txt复制
listeners=SASL_PLAINTEXT://localhost:9093
advertised.listeners=SASL_PLAINTEXT://localhost:9093
security.inter.broker.protocol=SASL_PLAINTEXT
sasl.mechanism.inter.broker.protocol=OAUTHBEARER
sasl.enabled.mechanisms=OAUTHBEARER

# Specify the JAAS login context name for SASL/OAUTHBEARER
listener.name.sasl_plaintext.oauthbearer.sasl.jaas.config=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required unsecuredLoginStringClaim_sub="alice";

  1. start the zookeeper and kafka server
代码语言:txt复制
zookeeper-server-start.bat .configzookeeper.properties
kafka-server-start.bat .configserver.properties

  1. next create a file client.properties in the config folder for kafka-topic script to use
代码语言:txt复制
security.protocol=SASL_PLAINTEXT
sasl.mechanism=OAUTHBEARER
sasl.jaas.config=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required unsecuredLoginStringClaim_sub="alice";

  1. ccreate topic 'gaming-events' by kafka-topic script
代码语言:txt复制
kafka-topics.bat --create --topic gaming-events --bootstrap-server localhost:9093 --command-config .configclient.properties
kafka-topics.bat --list --bootstrap-server localhost:9093 --command-config .configclient.properties

  1. next modify consumer.properties/producer.properties the same as client.properties
代码语言:txt复制
security.protocol=SASL_PLAINTEXT
sasl.mechanism=OAUTHBEARER
sasl.jaas.config=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required unsecuredLoginStringClaim_sub="alice";

  1. finally start the consumer and producer communicating through the topic 'gaming-events'
代码语言:txt复制
kafka-console-consumer.bat --topic gaming-events --from-beginning --bootstrap-server localhost:9093 --consumer.config .configconsumer.properties
kafka-console-producer.bat --topic gaming-events --bootstrap-server localhost:9093 --producer.config .configproducer.properties

This is just a test setting of OAUTHBEARER for kafka.

0 人点赞