gpt4 book ai didi

JAAS/SASL 的 spring-kafka application.properties 配置不起作用

转载 作者:行者123 更新时间:2023-12-04 16:27:21 33 4
gpt4 key购买 nike

用例:
我正在使用 Spring Boot 2.2.5.RELEASEKafka 2.4.1JAAS/SASL 配置在 Kafka/ZooKeeper 上正确完成,因为创建的主题没有问题 kafka-topics.bat
问题:
当我启动 Spring Boot 应用程序时,我立即收到以下错误:

kafka-server-start.bat 控制台:INFO [SocketServer brokerId=1] Failed authentication with /127.0.0.1 (Unexpected Kafka request of type METADATA during SASL handshake.) (org.apache.kafka.common.network.Selector)
IDE控制台:WARN org.apache.kafka.clients.NetworkClient - [Consumer clientId=xxx, groupId=yyy] Bootstrap broker localhost:9093 (id: -3 rack: null) disconnected
我的 application.properties配置:

spring.kafka.jaas.enabled=true
spring.kafka.properties.security.protocol=SASL_PLAINTEXT
spring.kafka.properties.sasl.mechanism=PLAIN
spring.kafka.properties.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="spring_bO0t" password="i_am_a_spring_bO0t_user";
kafka_server_jaas.conf :
KafkaServer {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="admin"
password="12345"
user_admin="12345"
user_spring_bO0t="i_am_a_spring_bO0t_user";
};

我错过了什么吗?

提前致谢。

最佳答案

@jumping_monkey 提供的答案是正确的,但是我不知道将这些配置放在哪里 ProducerFactory & ConsumerFactory beans,所以我会在下面为那些想知道的人留下一个例子:
-在您的 ProducerConfigConsumerConfig Beans 分别(我的名为 generalMessageProducerFactory ):

@Bean
public ProducerFactory<String, GeneralMessageDto> generalMessageProducerFactory() {
Map<String, Object> configProps = new HashMap<>();
configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);
configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
configProps.put("sasl.mechanism", "PLAIN");
configProps.put("sasl.jaas.config", "org.apache.kafka.common.security.plain.PlainLoginModule required username='YOUR_KAFKA_CLUSTER_USERNAME' password='YOUR_KAFKA_CLUSTER_PASSWORD';");
configProps.put("security.protocol", "SASL_SSL");
return new DefaultKafkaProducerFactory<>(configProps);
}
还有您的 TopicConfiguration上课 kafkaAdmin方法:
@Bean
public KafkaAdmin kafkaAdmin() {
Map<String, Object> configs = new HashMap<>();
configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);
configs.put("sasl.mechanism", "PLAIN");
configs.put("sasl.jaas.config", "org.apache.kafka.common.security.plain.PlainLoginModule required username='YOUR_KAFKA_CLUSTER_USERNAME' password='YOUR_KAFKA_CLUSTER_PASSWORD';");
configs.put("security.protocol", "SASL_SSL");
return new KafkaAdmin(configs);
}
希望这是有帮助的家伙!

关于JAAS/SASL 的 spring-kafka application.properties 配置不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60825373/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com