You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by Shuangjiang Li <pa...@gmail.com> on 2018/03/15 05:58:12 UTC

How to set Kafka working behind virtual IP

Below is a simple kafka producer code. The bootstrap.servers address
100.67.148.133:8080is a Virtual IP and translates to a real broker server
IP/port: 11.180.140.172:9092.

After I sent the request, the Virtual IP successfully sent back topic
VIP_test1's metadata. (see wireshark screen capture).

The the producer send the record using the returned broker list from
metadata response, in this case, IP/port 11.180.140.201:9092. However, my
producer can not directly access this IP/port, it has to go through a
different virtual IP which translates to this 11.180.140.201:9092.

What I tried so far is using listeners and advertised.listeners and try to
publish my virtual IP to zookeeper for producer to use. But seems not work.

listeners=INTERNAL://:9092,EXTERNAL_PLAINTEXT://:8080
advertised.listeners=INTERNAL://11.180.140.201:9092,EXTERNAL_PLAINTEXT://
100.67.148.156:8080
listener.security.protocol.map=INTERNAL:PLAINTEXT,EXTERNAL_PLAINTEXT:PLAINTEXT
inter.broker.listener.name=INTERNAL

public static void main(String[] args) throws InterruptedException {
    Properties props = new Properties();
    props.put("bootstrap.servers", "100.67.148.133:8080");
    props.put("acks", "0");
    props.put("key.serializer",
"org.apache.kafka.common.serialization.StringSerializer");
    props.put("value.serializer",
"org.apache.kafka.common.serialization.StringSerializer");
    KafkaProducer<String, String> producer = new KafkaProducer<>(props);
    for (int i = 0; i < 10; i++) {
        System.out.println("ib = " + i);
        ProducerRecord<String, String> record = new
ProducerRecord<>("VIP_test1", "1", "value-" + i);
        System.out.println(record.toString());
        producer.send(record);
        Thread.sleep(250);
    }

    producer.close();
}





​