1

I am writing a simple web java program to fire request to kafka to create topic and so on.

Everything working fine, until I run my web java program in docker and run my kafka in docker.

I will hit

Connection to node 1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.

Even I pass in the correct value for the bootstrap.servers.

The following the the log:

[INFO] AdminClientConfig values: 
    bootstrap.servers = [broker:9092]
    client.dns.lookup = use_all_dns_ips
    client.id = 
    connections.max.idle.ms = 300000
    default.api.timeout.ms = 60000
    metadata.max.age.ms = 300000
    metric.reporters = []
    metrics.num.samples = 2
    metrics.recording.level = INFO
    metrics.sample.window.ms = 30000
    receive.buffer.bytes = 65536
    reconnect.backoff.max.ms = 1000
    reconnect.backoff.ms = 50
    request.timeout.ms = 30000
    retries = 2147483647
    retry.backoff.ms = 100
    sasl.client.callback.handler.class = null
    sasl.jaas.config = null
    sasl.kerberos.kinit.cmd = /usr/bin/kinit
    sasl.kerberos.min.time.before.relogin = 60000
    sasl.kerberos.service.name = null
    sasl.kerberos.ticket.renew.jitter = 0.05
    sasl.kerberos.ticket.renew.window.factor = 0.8
    sasl.login.callback.handler.class = null
    sasl.login.class = null
    sasl.login.connect.timeout.ms = null
    sasl.login.read.timeout.ms = null
    sasl.login.refresh.buffer.seconds = 300
    sasl.login.refresh.min.period.seconds = 60
    sasl.login.refresh.window.factor = 0.8
    sasl.login.refresh.window.jitter = 0.05
    sasl.login.retry.backoff.max.ms = 10000
    sasl.login.retry.backoff.ms = 100
    sasl.mechanism = GSSAPI
    sasl.oauthbearer.clock.skew.seconds = 30
    sasl.oauthbearer.expected.audience = null
    sasl.oauthbearer.expected.issuer = null
    sasl.oauthbearer.jwks.endpoint.refresh.ms = 3600000
    sasl.oauthbearer.jwks.endpoint.retry.backoff.max.ms = 10000
    sasl.oauthbearer.jwks.endpoint.retry.backoff.ms = 100
    sasl.oauthbearer.jwks.endpoint.url = null
    sasl.oauthbearer.scope.claim.name = scope
    sasl.oauthbearer.sub.claim.name = sub
    sasl.oauthbearer.token.endpoint.url = null
    security.protocol = PLAINTEXT
    security.providers = null
    send.buffer.bytes = 131072
    socket.connection.setup.timeout.max.ms = 30000
    socket.connection.setup.timeout.ms = 10000
    ssl.cipher.suites = null
    ssl.enabled.protocols = [TLSv1.2]
    ssl.endpoint.identification.algorithm = https
    ssl.engine.factory.class = null
    ssl.key.password = null
    ssl.keymanager.algorithm = SunX509
    ssl.keystore.certificate.chain = null
    ssl.keystore.key = null
    ssl.keystore.location = null
    ssl.keystore.password = null
    ssl.keystore.type = JKS
    ssl.protocol = TLSv1.2
    ssl.provider = null
    ssl.secure.random.implementation = null
    ssl.trustmanager.algorithm = PKIX
    ssl.truststore.certificates = null
    ssl.truststore.location = null
    ssl.truststore.password = null
    ssl.truststore.type = JKS

[INFO] Kafka version: 3.1.0
[INFO] Kafka commitId: 37edeed0777bacb3
[INFO] Kafka startTimeMs: 1649824648847
[INFO] [AdminClient clientId=adminclient-1] Node 1 disconnected.
[WARN] [AdminClient clientId=adminclient-1] Connection to node 1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.
[INFO] [AdminClient clientId=adminclient-1] Node 1 disconnected.

As you can see from the log, second line, my bootstap.servers value is broker:9092. However, at the last part there, it still showing localhost/127.0.0.1:9092:

[INFO] [AdminClient clientId=adminclient-1] Node 1 disconnected.
    [WARN] [AdminClient clientId=adminclient-1] Connection to node 1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.
    [INFO] [AdminClient clientId=adminclient-1] Node 1 disconnected.

In my java code, I am using AdminClient, which is org.apache.kafka.clients.admin.AdminClient.

System.out.println("cloudConfig is " + cloudConfig.get("bootstrap.servers"));
        try (final AdminClient adminClient = AdminClient.create(cloudConfig)) {

            adminClient.createTopics(Collections.singletonList(newTopic)).all().get();
            System.out.println("successfully create");
        } catch (final InterruptedException | ExecutionException e) {
            // Ignore if TopicExistsException, which may be valid if topic exists
        }

Even in log of System.out.println("cloudConfig is " + cloudConfig.get("bootstrap.servers"));, its showing broker:9092.

Anyone know what is going wrong?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Panadol Chong
  • 1,793
  • 13
  • 54
  • 119

0 Answers0