【发布时间】:2021-02-27 11:55:53
【问题描述】:
我已经在 Confluent 云 (https://confluent.cloud/) 上设置了一个 Kafka 主题,并且可以使用以下配置将消息连接/发送到该主题:
kafka-config.properties:
# Kafka
ssl.endpoint.identification.algorithm=
bootstrap.servers=pkc-4yyd6.us-east1.gcp.confluent.cloud:9092
security.protocol=SASL_SSL
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="uname" password="pwd";
sasl.mechanism=PLAIN
从我收到的 docker 容器连接:
Failed to produce: org.apache.kafka.common.errors.SslAuthenticationException: SSL handshake failed
搜索上述错误表明 ssl.endpoint.identification.algorithm= 应该修复
这是我的 Dockerfile:
FROM ysihaoy/scala-play:2.12.2-2.6.0-sbt-0.13.15
COPY ["build.sbt", "/tmp/build/"]
COPY ["project/plugins.sbt", "project/build.properties", "/tmp/build/project/"]
COPY . /root/app/
WORKDIR /root/app
CMD ["sbt" , "run"]
我使用以下方法构建和运行容器:
docker build -t kafkatest .
docker run -it kafkatest
允许连接到 Confluent Kafka 是否需要额外的配置?
在本地构建(不使用 Docker)时我没有收到此问题。
更新:
这是我用来构建属性的 Scala 源代码:
def buildProperties(): Properties = {
val kafkaPropertiesFile = Source.fromResource("kafka-config.properties")
val properties: Properties = new Properties
properties.load(kafkaPropertiesFile.bufferedReader())
properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer")
properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.connect.json.JsonSerializer")
properties
}
更新 2:
def buildProperties(): Properties = {
val kafkaPropertiesFile = Source.fromResource("kafka-config.properties")
val properties: Properties = new Properties
properties.load(kafkaPropertiesFile.bufferedReader())
println("bootstrap.servers:"+properties.get("bootstrap.servers"))
properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer")
properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.connect.json.JsonSerializer")
properties
}
找到属性bootstrap.servers,因此将文件添加到容器中。
更新3:
sasl.jaas.config:org.apache.kafka.common.security.plain.PlainLoginModule required username="Q763KBPRI" password="bFehkfL/J6m8L2aukX+A/L59LAYb/bWr"
更新4:
docker run -it kafkatest --network host
返回错误:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"--network\": executable file not found in $PATH": unknown.
【问题讨论】:
-
你能分享一下你用来连接Kafka的代码吗
-
@RobinMoffatt 请查看问题更新
-
你是否将 kafka-config.properties 复制到 docker 镜像?为了确保您使用正确的属性,您可以在
buildProperties函数的末尾将它们注销吗? -
@amorfis 文件已添加到 docker 映像中 - 请参阅更新。
-
好吧,他们看起来太有说服力了:D
标签: scala docker apache-kafka confluent-platform