构建一个SPI以将事件推送到Kafka中,以在Keycloak 6.0.1中部署为EAR,它使用WildFly Server,打包在基于.jboss/keycloak:6.0.1我遇到了:Kafka Producer - org.apache.kafka.common.serialization.StringSerializer 找不到所以我应用了建议的设置解决方案Thread.currentThread().setContextClassLoader(null);。这似乎适用于我在端口 9092 上的本地 Kafka,无需身份验证。一旦我按照此处所述进行身份验证:String jaasTemplate = "org.apache.kafka.common.security.scram.ScramLoginModule required username=\"%s\" password=\"%s\";";String jaasCfg = String.format(jaasTemplate, username, password);Properties props = new Properties();props.put("sasl.jaas.config", jaasCfg);// ...Thread.currentThread().setContextClassLoader(null);KafkaProducer<String, String> producer = new KafkaProducer<>(props);我遇到了错误:org.apache.kafka.common.KafkaException: javax.security.auth.login.LoginException: unable to find LoginModule class: org.apache.kafka.common.security.scram.ScramLoginModule at org.apache.kafka.common.network.SaslChannelBuilder.configure(SaslChannelBuilder.java:160) at org.apache.kafka.common.network.ChannelBuilders.create(ChannelBuilders.java:146) at org.apache.kafka.common.network.ChannelBuilders.clientChannelBuilder(ChannelBuilders.java:67) at org.apache.kafka.clients.ClientUtils.createChannelBuilder(ClientUtils.java:99) at org.apache.kafka.clients.producer.KafkaProducer.newSender(KafkaProducer.java:441) at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:422)我怀疑这是由于将 ClassLoader 设置为 引起的null,但我不确定。JAAS 字符串提到了这个org.apache.kafka.common.security.scram.ScramLoginModule。我尝试不使用 JAAS,而是使用简单的用户名 + 密码,如下所示:Properties props = new Properties();props.put("sasl.username", username);props.put("sasl.password", password);// ...Thread.currentThread().setContextClassLoader(null);KafkaProducer<String, String> producer = new KafkaProducer<>(props);我怎样才能找到它org.apache.kafka.common.security.scram.ScramLoginModule?谢谢!
1 回答
千巷猫影
TA贡献1829条经验 获得超7个赞
警告:丑陋的骇客!
在创建 KafkaProducer 之前,设置如下所示的上下文类加载器:
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
添加回答
举报
0/150
提交
取消