2

我不想在 quarkus 中使用 smallrye-kafka 通过 SSL 连接到 kafka 主题。

我的代码在执行时有效mvn compile quarkus:dev

mvn clean package -Pnative是成功的。但是当我运行本机二进制文件时,它会失败,因为它找不到SaslClientCallbackHandler. 我按照 quarkus 指南使用 SSL 构建本机,并使用 smallrye 扩展配置 kafka。

我的 application.property 文件

mp.messaging.outgoing.stock-topic.connector=smallrye-kafka
mp.messaging.outgoing.stock-topic.value.serializer=org.apache.kafka.common.serialization.ByteArraySerializer
mp.messaging.outgoing.stock-topic.key.serializer=org.apache.kafka.common.serialization.IntegerSerializer
mp.messaging.outgoing.stock-topic.topic=topic
mp.messaging.outgoing.stock-topic.bootstrap.servers=${KAFKA_HOST}:${KAFKA_PORT}
mp.messaging.outgoing.stock-topic.sasl.mechanism=PLAIN
mp.messaging.outgoing.stock-topic.security.protocol=SASL_SSL
mp.messaging.outgoing.stock-topic.ssl.protocol=TLSv1.2
mp.messaging.outgoing.stock-topic.ssl.enabled.protocols=TLSv1.2
mp.messaging.outgoing.stock-topic.ssl.endpoint.identification.algorithm=HTTPS
mp.messaging.outgoing.stock-topic.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="${KAFKA_USER}" password="${KAFKA_PASS}";

quarkus.ssl.native=true
quarkus.native.enable-all-security-services=true

我希望本地人也能正常工作。当application.property被评论时,本机运行不会抛出异常。

错误日志:

Exception in thread "main" java.lang.RuntimeException: Failed to start quarkus
        at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:185)
        at io.quarkus.runtime.Application.start(Application.java:94)
        at io.quarkus.runtime.Application.run(Application.java:218)
        at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:41)
Caused by: javax.enterprise.inject.spi.DeploymentException: org.apache.kafka.common.KafkaException: Failed to construct kafka producer
        at io.quarkus.smallrye.reactivemessaging.runtime.SmallRyeReactiveMessagingLifecycle.onApplicationStart(SmallRyeReactiveMessagingLifecycle.java:22)
        at io.quarkus.smallrye.reactivemessaging.runtime.SmallRyeReactiveMessagingLifecycle_Observer_onApplicationStart_4e8937813d9e8faff65c3c07f88fa96615b70e70.notify(SmallRyeReactiveMessagingLifecycle_Observer_onApplicationStart_4e8937813d9e8faff65c3c07f88fa96615b70e70.zig:51)
        at io.quarkus.arc.impl.EventImpl$Notifier.notify(EventImpl.java:224)
        at io.quarkus.arc.impl.EventImpl.fire(EventImpl.java:65)
        at io.quarkus.arc.runtime.LifecycleEventRunner.fireStartupEvent(LifecycleEventRunner.java:23)
        at io.quarkus.arc.runtime.ArcRecorder.handleLifecycleEvents(ArcRecorder.java:108)
        at io.quarkus.deployment.steps.LifecycleEventsBuildStep$startupEvent27.deploy_0(LifecycleEventsBuildStep$startupEvent27.zig:58)
        at io.quarkus.deployment.steps.LifecycleEventsBuildStep$startupEvent27.deploy(LifecycleEventsBuildStep$startupEvent27.zig:77)
        at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:161)
        ... 3 more
Caused by: org.apache.kafka.common.KafkaException: Failed to construct kafka producer
        at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:431)
        at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:271)
        at io.vertx.kafka.client.producer.impl.KafkaWriteStreamImpl.create(KafkaWriteStreamImpl.java:52)
        at io.vertx.kafka.client.producer.KafkaWriteStream.create(KafkaWriteStream.java:92)
        at io.smallrye.reactive.messaging.kafka.KafkaSink.<init>(KafkaSink.java:50)
        at io.smallrye.reactive.messaging.kafka.KafkaConnector.getSubscriberBuilder(KafkaConnector.java:73)
        at io.smallrye.reactive.messaging.kafka.KafkaConnector_ClientProxy.getSubscriberBuilder(KafkaConnector_ClientProxy.zig:283)
        at io.smallrye.reactive.messaging.impl.ConfiguredChannelFactory.createSubscriberBuilder(ConfiguredChannelFactory.java:156)
        at io.smallrye.reactive.messaging.impl.ConfiguredChannelFactory.lambda$register$5(ConfiguredChannelFactory.java:124)
        at java.util.HashMap.forEach(HashMap.java:1289)
        at io.smallrye.reactive.messaging.impl.ConfiguredChannelFactory.register(ConfiguredChannelFactory.java:124)
        at io.smallrye.reactive.messaging.impl.ConfiguredChannelFactory.initialize(ConfiguredChannelFactory.java:118)
        at io.smallrye.reactive.messaging.impl.ConfiguredChannelFactory_ClientProxy.initialize(ConfiguredChannelFactory_ClientProxy.zig:195)
        at java.util.Iterator.forEachRemaining(Iterator.java:116)
        at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
        at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:647)
        at io.smallrye.reactive.messaging.extension.MediatorManager.initializeAndRun(MediatorManager.java:132)
        at io.smallrye.reactive.messaging.extension.MediatorManager_ClientProxy.initializeAndRun(MediatorManager_ClientProxy.zig:100)
        at io.quarkus.smallrye.reactivemessaging.runtime.SmallRyeReactiveMessagingLifecycle.onApplicationStart(SmallRyeReactiveMessagingLifecycle.java:20)
        ... 11 more
Caused by: org.apache.kafka.common.KafkaException: org.apache.kafka.common.KafkaException: Could not find a public no-argument constructor for org.apache.kafka.common.security.authenticator.SaslClientCallbackHandler
        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:439)
        at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:420)
        ... 29 more
Caused by: org.apache.kafka.common.KafkaException: Could not find a public no-argument constructor for org.apache.kafka.common.security.authenticator.SaslClientCallbackHandler
        at org.apache.kafka.common.utils.Utils.newInstance(Utils.java:314)
        at org.apache.kafka.common.network.SaslChannelBuilder.createClientCallbackHandler(SaslChannelBuilder.java:289)
        at org.apache.kafka.common.network.SaslChannelBuilder.configure(SaslChannelBuilder.java:127)
        ... 34 more
Caused by: java.lang.NoSuchMethodException: org.apache.kafka.common.security.authenticator.SaslClientCallbackHandler.<init>
        at java.lang.Class.getConstructor0(DynamicHub.java:3082)
        at java.lang.Class.getDeclaredConstructor(DynamicHub.java:2178)
        at org.apache.kafka.common.utils.Utils.newInstance(Utils.java:312)
        ... 36 more

重现:

  1. quarkus-smallrye-reactive-messaging-kafka使用扩展制作新的 quarkus 项目

  2. 配置应用程序属性

  3. 构建本机并运行它。

注意:我没有任何类src/main/java,当在中找到 SSL 配置时,本机失败application.property

4

0 回答 0