0

I am building up a jar file for my spring boot microservice, but upon maven install i am getting the error as stated below.

Caused by: org.apache.kafka.common.config.ConfigException: No resolvable bootstrap urls given in bootstrap.servers
at org.apache.kafka.clients.ClientUtils.parseAndValidateAddresses(ClientUtils.java:89) ~[kafka-clients-3.1.1.jar:na]
at org.apache.kafka.clients.ClientUtils.parseAndValidateAddresses(ClientUtils.java:48) ~[kafka-clients-3.1.1.jar:na]
at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:730) ~[kafka-clients-3.1.1.jar:na]

my docker-compose file for the application is

version: '2'
services:
  zookeeper:
    image: confluentinc/cp-zookeeper:latest
    restart: always
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000
    ports:
      - 2181:2181
    networks:
      - app-network

  kafka:
    image: confluentinc/cp-kafka:latest
    container_name: kafka
    restart: always
    depends_on:
      - zookeeper
    ports:
      - 9092:9092
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
    networks:
      - app-network

  mongodb:
    image: mongo:latest
    restart: always
    container_name: mongodb
    networks:
      - app-network
    ports:
      - 27017:27017

  matching-engine-helper:
    image: matching-engine-helper:latest
    restart: always
    container_name: "matching-engine-helper"
    networks:
      - app-network
    ports:
      - 9192:9192
    depends_on:
      - mongodb
      - zookeeper
      - kafka

  matching-engine-core:
    image: matching-engine-core:latest
    restart: always
    container_name: "matching-engine-core"
    networks:
      - app-network
    ports:
      - 9191:9191
    depends_on:
      - matching-engine-helper
      - zookeeper
      - kafka
      - mongodb

networks:
  app-network:
    driver: bridge

and the application.yml is


spring:
  data:
    mongodb:
      database: matching-engine-mongodb
      host: mongodb
      port: 27017
  kafka:
    bootstrap-servers: kafka:9092
server:
  port: 9192

let me know if i need some environment variable's configuration here. as its running fine on local environment on local host but not on docker containers as i am unable to make a jar out of it.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Manzoor Ahmad
  • 481
  • 6
  • 21

1 Answers1

2

Assuming mvn install is running on your host, then your host doesn't know how to resolve kafka as a DNS name running in a container. It that's what you wanted, then you should rename your file to application-docker.yml and use Spring profiles to properly override any defaults when you actually do run your code in a container. In your case, you would need to have localhost:29092 for Kafka, and similarly use localhost:27017 for Mongo in your default application.yml. You can also use environment variables for those two properties rather than hard-code them.

Or, if mvn install is running in a Docker layer itself, then that is completely isolated from other Docker networks. You can pass --network flag to docker build, though.

Assuming you don't want to mvn install -DskipTests, ideally, your tests do not rely on external services to be running. If you want to run a Kafka unit test, which is failing to connect, then you should either mock that, or using Spring-Kafka's EmbeddedKafka for integration-tests.

Worth mentioning that Spring boot has a Maven plugin for building Docker images, and it doesn't need a JAR to do so.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245