Ernestina Juan
Ernestina Juan

Reputation: 967

Spring Boot - Remote Zookeper configuration

In our Spring Boot program we are switching from a local Zookeeper and Apache Kafka servers to a remote ones (the best solution we have found at the moment is cloudkarafka, but that is not important).

From this provider we have downloaded the properties we have to add to our properties Kafka confguration map in order to use remote Kafka, such as bootstrap servers, but after all this, Spring Boot continues searching Zookeeper in local machine. Is there anything I can do?

application.yml

spring:
 cloud:
  zookeeper:
   connect-string: server:2181

Properties map

Map<String, Object> props = new HashMap<>();
    props.put("bootstrap.servers", getBrokers());
    props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
    props.put(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG, "100");
    props.put(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, "15000");
    props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
    props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
    props.put("security.protocol", "SSL");
    props.put("ssl.truststore.location", "truststore.jks");
    props.put("ssl.truststore.password", "test1234");
    props.put("ssl.keystore.location", "keystore.jks");
    props.put("ssl.keystore.password", "pass");
    props.put("ssl.keypassword", "pass");
    props.put("zk.connect", "server:2181");

Thank you.

Upvotes: 0

Views: 1287

Answers (1)

Monzurul Shimul
Monzurul Shimul

Reputation: 8396

I'm not sure about cloudkarafka specific settings. But surely this is a configuration issue Ive faced earlier while connecting remote kafka server in my dev environment.

Inside kafka server.properties there are two commented configuration.

#listeners=PLAINTEXT://:9092
#advertised.listeners=PLAINTEXT://your.host.name:9092

Need to uncomment them and set actual ip address.

listeners configuration is the address the socket server listens on. It will get the value returned from java.net.InetAddress.getCanonicalHostName() if not configured, which is localhost and thats why clients look for localhost.

Upvotes: 1

Related Questions