java - 如何在 Quarkus 中为 Kafka 使用 TLS?

标签 java apache-kafka ibm-cloud quarkus

Kafka guide from Quarkus在 Docker 中本地运行 Kafka 时效果很好。我正在尝试通过将本地 Kafka 服务替换为需要 TLS 的云中托管 Kafka 服务来更改此示例。
有谁知道我如何配置它?在 Quarkus documentationSmallrye documentation我没有看到任何属性。
我想在 IBM Cloud 中使用 Kafka 服务。基于 documentation我在 application.properties 中尝试了以下配置:

kafka.bootstrap.servers=broker-0-8c8cph49mx2p2wqy.kafka.svc01.us-south.eventstreams.cloud.ibm.com:9093,broker-4-8c8cph49mx2p2wqy.kafka.svc01.us-south.eventstreams.cloud.ibm.com:9093,broker-3-8c8cph49mx2p2wqy.kafka.svc01.us-south.eventstreams.cloud.ibm.com:9093,broker-5-8c8cph49mx2p2wqy.kafka.svc01.us-south.eventstreams.cloud.ibm.com:9093,broker-2-8c8cph49mx2p2wqy.kafka.svc01.us-south.eventstreams.cloud.ibm.com:9093,broker-1-8c8cph49mx2p2wqy.kafka.svc01.us-south.eventstreams.cloud.ibm.com:9093
kafka.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="token" password="...";
kafka.sasl.mechanism=PLAIN
kafka.security.protocol=SASL_SSL
kafka.ssl.protocol=TLSv1.2
更新:
我也在下面尝试了 Gunnar 的建议,但它不起作用。当我使用以下 application.properties ...
mp.messaging.outgoing.generated-price.connector=smallrye-kafka
mp.messaging.outgoing.generated-price.topic=prices
mp.messaging.outgoing.generated-price.value.serializer=org.apache.kafka.common.serialization.IntegerSerializer

mp.messaging.outgoing.generated-price.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="token" password="...";
mp.messaging.outgoing.generated-price.sasl.mechanism=PLAIN
mp.messaging.outgoing.generated-price.security.protocol=SASL_SSL
mp.messaging.outgoing.generated-price.ssl.protocol=TLSv1.2

mp.messaging.incoming.prices.connector=smallrye-kafka
mp.messaging.incoming.prices.topic=prices
mp.messaging.incoming.prices.value.deserializer=org.apache.kafka.common.serialization.IntegerDeserializer

mp.messaging.outgoing.prices.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="token" password="...";
mp.messaging.outgoing.prices.sasl.mechanism=PLAIN
mp.messaging.outgoing.prices.security.protocol=SASL_SSL
mp.messaging.outgoing.prices.ssl.protocol=TLSv1.2

kafka.bootstrap.servers=broker-0-8c8cph49mx2p2wqy.kafka.svc01.us-south.eventstreams.cloud.ibm.com:9093,broker-4-8c8cph49mx2p2wqy.kafka.svc01.us-south.eventstreams.cloud.ibm.com:9093,broker-3-8c8cph49mx2p2wqy.kafka.svc01.us-south.eventstreams.cloud.ibm.com:9093,broker-5-8c8cph49mx2p2wqy.kafka.svc01.us-south.eventstreams.cloud.ibm.com:9093,broker-2-8c8cph49mx2p2wqy.kafka.svc01.us-south.eventstreams.cloud.ibm.com:9093,broker-1-8c8cph49mx2p2wqy.kafka.svc01.us-south.eventstreams.cloud.ibm.com:9093
...我收到一个错误:
javax.enterprise.inject.spi.DeploymentException: java.lang.IllegalArgumentException: 无效的 channel 配置 - connector必须为 channel 设置属性 prices在 io.quarkus.smallrye.reactivemessaging.runtime.SmallRyeReactiveMessagingLifecycle.onApplicationStart(SmallRyeReactiveMessagingLifecycle.java:22)
Quarkus 中的 Kafka 目前是否可以使用 TLS?
谢谢

最佳答案

您是否尝试过在 channel 级别指定相关属性?例如。

mp.messaging.outgoing.generated-price.connector=smallrye-kafka
mp.messaging.outgoing.generated-price.topic=mytopic
mp.messaging.outgoing.generated-price.ssl.protocol=...
mp.messaging.outgoing.generated-price.ssl.keystore.location=...
mp.messaging.outgoing.generated-price.ssl.keystore.password=...

当多个主题需要相同的值时,您也可以引用变量。

关于java - 如何在 Quarkus 中为 Kafka 使用 TLS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58975470/

相关文章:

apache-kafka - 卡夫卡有重复的消息

spring - Bluemix Docker Container部署结果为 “No route to host”

docker - 如何 docker exec 到 IBM bluemix 容器

在 Kubernetes 入口上使用 Gunicorn 的 Flask 产生 502 nginx 错误

java - 代码隐藏插件的访问路径为.action?

Java 出于功能目的从拆分中获取运算符

java - 编写一个 Java 代码,该代码从命令行接受字符串并按字母顺序显示其字符

java - 为单个 kafka 主题创建多个消费者

java - Filter 类中不能使用超过 16 位

apache-kafka - 卡夫卡指标|为什么我在指标报告中看到额外的节点 ID node--1 和 node--2