ConnectException: Connection refused Kafka producer

1/21/2019

I have deployed Kafka using Helm and Minikube. I need to build a producer in Scala for that broker IP-address and host are required. I have defined NodePort service to expose Kafka to the outside world. I set up broker as minkube-ip:service-node-port, however, I get connection exception. What is wrong with the configuration I defined? With a docker-compose file, the application works fine.

Error stack trace:

Exception in thread "main" org.apache.kafka.common.errors.SerializationException: Error serializing Avro message
Caused by: java.net.ConnectException: Connection refused (Connection refused)

Kafka configurations look like this:

  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 service definition where labels match Kafka pods labeled produced by Helm:

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

This is the list of all the created services:

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
-- Cassie
apache-kafka
kubernetes
kubernetes-helm

1 Answer

1/21/2019

The error is from the deserialiser trying to connect to the Schema Registry

props.put("schema.registry.url", "http://0.0.0.0:8081")

should read

props.put("schema.registry.url", "http://<hostname of Schema Registry resolvable from Connect node>:8081")

-- Robin Moffatt
Source: StackOverflow