播放框架:使用security.protocol = SASL_SSL的Kafka连接由于错误而无法启动

时间:2019-11-14 05:54:42

标签: java ssl playframework apache-kafka

我想在向其中添加Kafka连接后启动Play应用,但是一旦我们将属性security.protocol设置为使用任何形式的SSL,它在启动期间都会失败。 SASL_SSL是我们的目标配置类型,我使用SASL_PLAINTEXT进行了测试,该应用程序加载得很好。这使我认为它可能找不到信任库?我将信任库放置在下面的属性文件中提到的位置。信任库的密码是在运行时通过env变量添加的,该密码显示在EventProducer.class文件中。事件产生器在运行时注入到另一个类中,正如我将security.protocol=SASL_PLAINTEXT设置为应用程序正常启动时提到的那样,但是security.protocol=SASL_SSL导致崩溃。这就是为什么我认为问题可能出在信任库的位置,但是我也将堆栈跟踪信息粘贴到了下面,因为我不确定是否出了问题。我尝试将信任库放置在应用程序/project_dir/trustore.jks的根目录下,并通过ssl.truststore.location=truststore.jks进行引用,但也失败了。也许我对应用程序如何引用文件的理​​解是不正确的,但会有所帮助。

producer.properties:

bootstrap.servers=....
acks=all
retries=0
batch.size=16384
linger.ms=1
buffer.memory=33554432
key.serializer=org.apache.kafka.common.serialization.StringSerializer
value.serializer=org.apache.kafka.common.serialization.StringSerializer
ssl.enabled.protocols=TLSv1.2,TLSv1.1,TLSv1
ssl.truststore.location=/tmp/ssl/truststore.jks
ssl.protocol=TLS
security.protocol=SASL_SSL
ssl.endpoint.identification.algorithm=
sasl.mechanism=SCRAM-SHA-256

EventProducer.class

public class EventProducer() {

    @Inject
    public EventProducer(ApplicationLifecycle lifecycle) {
        this.lifecycle = lifecycle;
        this.producer = initializeProducer();

        // add shutdown hook
        this.lifecycle.addStopHook(() -> {
            producer.close();
            return CompletableFuture.completedFuture(null);
        });
    }

    private KafkaProducer<String, String> initializeProducer() {
        Properties props = new Properties();

        try {

// Loads the props from the resource folder
props.load(EventProducer.class.getClassLoader().getResourceAsStream(String.format("kafka/%s", Config.KAFKA_PRODUCER_PROPERTIES)));

            // Adding extra config values for the SASL and SSL configs
            props.put("sasl.jaas.config", Config.KAFKA_SASL_JAAS_CONFIG);
            props.put("ssl.truststore.password", Config.KAFKA_SSL_TRUSTSTORE_PASSWORD);
        } catch (IOException e) {
            Logger.warn("Error reading Kafka producer properties file", e);
        }

        return new KafkaProducer<>(props);
    }
}

堆栈跟踪:

2019-11-13 22:30:07,339 ERROR [play-dev-mode-akka.actor.default-dispatcher-6] Slf4jLogger$$anonfun$receive$1 - Internal server error, sending 500 response
com.google.common.util.concurrent.UncheckedExecutionException: java.lang.IllegalArgumentException
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2218)
    at com.google.common.cache.LocalCache.get(LocalCache.java:4147)
    at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4151)
    at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:5140)
    at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:5146)
    at com.google.inject.internal.util.StackTraceElements.forMember(StackTraceElements.java:70)
    at com.google.inject.internal.Errors.formatSource(Errors.java:817)
    at com.google.inject.internal.Errors.formatSource(Errors.java:796)
    at com.google.inject.internal.Errors.formatInjectionPoint(Errors.java:849)
    at com.google.inject.internal.Errors.formatSource(Errors.java:811)
    at com.google.inject.internal.Errors.formatSource(Errors.java:796)
    at com.google.inject.internal.Errors.format(Errors.java:590)
    at com.google.inject.ProvisionException.getMessage(ProvisionException.java:60)
    at play.api.UnexpectedException$$anonfun$$lessinit$greater$1.$anonfun$new$1(Exceptions.scala:12)
    at scala.Option.map(Option.scala:163)
    at play.api.UnexpectedException$$anonfun$$lessinit$greater$1.apply(Exceptions.scala:12)
    at play.api.UnexpectedException$$anonfun$$lessinit$greater$1.apply(Exceptions.scala:12)
    at scala.Option.getOrElse(Option.scala:138)
    at play.api.UnexpectedException.<init>(Exceptions.scala:12)
    at play.core.server.DevServerStart$$anon$1.reload(DevServerStart.scala:186)
    at play.core.server.DevServerStart$$anon$1.get(DevServerStart.scala:124)
    at play.core.server.AkkaHttpServer.handleRequest(AkkaHttpServer.scala:241)
    at play.core.server.AkkaHttpServer.$anonfun$createServerBinding$1(AkkaHttpServer.scala:138)
    at akka.stream.impl.fusing.MapAsyncUnordered$$anon$26.onPush(Ops.scala:1304)
    at akka.stream.impl.fusing.GraphInterpreter.processPush(GraphInterpreter.scala:519)
    at akka.stream.impl.fusing.GraphInterpreter.processEvent(GraphInterpreter.scala:482)
    at akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:378)
    at akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:588)
    at akka.stream.impl.fusing.GraphInterpreterShell$AsyncInput.execute(ActorGraphInterpreter.scala:472)
    at akka.stream.impl.fusing.GraphInterpreterShell.processEvent(ActorGraphInterpreter.scala:563)
    at akka.stream.impl.fusing.ActorGraphInterpreter.akka$stream$impl$fusing$ActorGraphInterpreter$$processEvent(ActorGraphInterpreter.scala:745)
    at akka.stream.impl.fusing.ActorGraphInterpreter$$anonfun$receive$1.applyOrElse(ActorGraphInterpreter.scala:760)
    at akka.actor.Actor.aroundReceive(Actor.scala:517)
    at akka.actor.Actor.aroundReceive$(Actor.scala:515)
    at akka.stream.impl.fusing.ActorGraphInterpreter.aroundReceive(ActorGraphInterpreter.scala:670)
    at akka.actor.ActorCell.receiveMessage(ActorCell.scala:588)
    at akka.actor.ActorCell.invoke(ActorCell.scala:557)
    at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:258)
    at akka.dispatch.Mailbox.run(Mailbox.scala:225)
    at akka.dispatch.Mailbox.exec(Mailbox.scala:235)
    at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
    at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
    at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Caused by: java.lang.IllegalArgumentException: null
    at com.google.inject.internal.asm.$ClassReader.<init>(Unknown Source)
    at com.google.inject.internal.asm.$ClassReader.<init>(Unknown Source)
    at com.google.inject.internal.asm.$ClassReader.<init>(Unknown Source)
    at com.google.inject.internal.util.LineNumbers.<init>(LineNumbers.java:66)
    at com.google.inject.internal.util.StackTraceElements$1.load(StackTraceElements.java:46)
    at com.google.inject.internal.util.StackTraceElements$1.load(StackTraceElements.java:43)
    at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3708)
    at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2416)
    at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2299)
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2212)
    ... 43 common frames omitted

0 个答案:

没有答案