kafka --org.apache.kafka.common.config.ConfigException: No resolvable bootstrap urls given in bootst

报错内容:

Exception in thread "main" org.apache.kafka.common.KafkaException: Failed to construct kafka consumer
	at org.apache.kafka.clients.consumer.KafkaConsumer.(KafkaConsumer.java:781)
	at org.apache.kafka.clients.consumer.KafkaConsumer.(KafkaConsumer.java:635)
	at org.apache.kafka.clients.consumer.KafkaConsumer.(KafkaConsumer.java:617)
	at com.czxy.zy01.Consumer.main(Consumer.java:22)
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:64)
	at org.apache.kafka.clients.consumer.KafkaConsumer.(KafkaConsumer.java:698)
	... 3 more

项目源码:

package com.czxy.zy01;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;

import java.util.Arrays;
import java.util.Properties;

/**
 * @author kismet
 * @date 2020-03-19 15:00
 */
public class Consumer {
    public static void main(String[] args) {
        Properties props = new Properties();
        props.put("bootstrap.servers", "hadoop-01:9092");
        props.put("group.id", "test");
        props.put("enable.auto.commit", "true");
        props.put("auto.commit.interval.ms",  "1000");
        props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
        props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
        KafkaConsumer KafkaConsumer = new KafkaConsumer<>(props);
        KafkaConsumer.subscribe(Arrays.asList("student"));
        while (true){
            ConsumerRecords poll = KafkaConsumer.poll(1000);
            for (ConsumerRecord consumerRecord : poll) {
                System.out.println(consumerRecord.value());
            }
        }
    }

报错原因:

在bootstrap.servers中没有提供可解析的引导url

解决方法:

kafka --org.apache.kafka.common.config.ConfigException: No resolvable bootstrap urls given in bootst_第1张图片

你可能感兴趣的:(kafka)