我已经使用Helm和Minikube部署了Kafka。我需要在Scala中为该代理IP地址和主机建立一个生产者。我已经定义了NodePort服务以将Kafka暴露给外界。我将代理设置为minkube-ip:service-node-port,但是,出现连接异常。 我定义的配置有什么问题? 使用docker-compose文件,该应用程序可以正常运行。
错误堆栈跟踪:
Exception in thread "main" org.apache.kafka.common.errors.SerializationException: Error serializing Avro message
Caused by: java.net.ConnectException: Connection refused (Connection refused)
Kafka配置如下:
val brokers = "192.168.99.100:32400"
val props = new Properties()
props.put("bootstrap.servers", brokers)
props.put("client.id", "AvroKafkaProducer")
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer")
props.put("value.serializer", "io.confluent.kafka.serializers.KafkaAvroSerializer")
props.put("schema.registry.url", "http://0.0.0.0:8081")
Kafka NodePort服务定义,其中的标签与Helm生产的带有标签的Kafka Pod相匹配:
kind: Service
apiVersion: v1
metadata:
name: kafka-service
spec:
selector:
app: cp-kafka
release: my-confluent-oss
ports:
- protocol: TCP
targetPort: 9092
port: 32400
nodePort: 32400
type: NodePort
这是所有已创建服务的列表:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-confluent-oss-cp-kafka ClusterIP 10.96.241.37 <none> 9092/TCP 6h25m
my-confluent-oss-cp-kafka-connect ClusterIP 10.105.148.181 <none> 8083/TCP 6h25m
my-confluent-oss-cp-kafka-headless ClusterIP None <none> 9092/TCP 6h25m
my-confluent-oss-cp-kafka-rest ClusterIP 10.99.154.76 <none> 8082/TCP 6h25m
my-confluent-oss-cp-ksql-server ClusterIP 10.108.41.220 <none> 8088/TCP 6h25m
my-confluent-oss-cp-schema-registry ClusterIP 10.108.182.212 <none> 8081/TCP 6h25m
my-confluent-oss-cp-zookeeper ClusterIP 10.97.148.103 <none> 2181/TCP 6h25m
my-confluent-oss-cp-zookeeper-headless ClusterIP None <none> 2888/TCP,3888/TCP 6h25m
答案 0 :(得分:2)
错误是由于反序列化程序试图连接到架构注册表
引起的 props.put("schema.registry.url", "http://0.0.0.0:8081")
应阅读
props.put("schema.registry.url", "http://<hostname of Schema Registry resolvable from Connect node>:8081")