簡體   English   中英

在kafka中創建主題時出錯

[英]Error while creating topic in kafka

我在Cygwin的窗口上使用kafka並試圖創建一個主題並得到以下錯誤

log4j:ERROR Could not read configuration file from URL [file:/cygdrive/d/kafka/bin/../config/tools-log4j.properties].
java.io.FileNotFoundException: \cygdrive\d\kafka\bin\..\config\tools-log4j.properties (The system cannot find the path specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
    at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:524)
    at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:483)
    at org.apache.log4j.LogManager.<clinit>(LogManager.java:127)
    at org.apache.log4j.Logger.getLogger(Logger.java:117)
    at org.I0Itec.zkclient.ZkClient.<clinit>(ZkClient.java:57)
    at kafka.admin.TopicCommand$.main(TopicCommand.scala:51)
    at kafka.admin.TopicCommand.main(TopicCommand.scala)
log4j:ERROR Ignoring configuration file [file:/cygdrive/d/kafka/bin/../config/tools-log4j.properties].
log4j:WARN No appenders could be found for logger (org.I0Itec.zkclient.ZkEventThread).
log4j:WARN No appenders could be found for logger (org.I0Itec.zkclient.ZkConnection).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

但這個話題正在創建中。 你能幫幫我嗎?

您是否使用Kafka文檔中的此命令行創建主題?

bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

在Cygwin中運行腳本時,我遇到了同樣的錯誤,我作出斌/ kafka-run-class.sh這種變化來解決問題(類似於第一個答案的第3步中引用的類路徑Cygwin的解決方案在這里 ):

原版的:

# Log4j settings if [ -z "$KAFKA_LOG4J_OPTS" ]; then KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:$base_dir/config/tools-log4j.properties" fi

至:

# Log4j settings if [ -z "$KAFKA_LOG4J_OPTS" ]; then KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:$(cygpath -wp $base_dir/config/tools-log4j.properties)" fi

我認為你提到的路徑不正確。 正如消息所示,文件未找到異常。 下面是一個用Java發送消息到kafka的示例代碼。 假設Kafka服務器在本地運行。

`public static void main(String[] args){
    long events = 100000;
    Random rnd  = new Random();

    Properties props = new Properties();
    props.put("metadata.broker.list", "localhost:9092");
    props.put("serializer.class", "kafka.serializer.StringEncoder");
    props.put("partitioner.class", "com.pranjal.kafkatest.SimplePartitioner");
    props.put("request.required.acks", "1");

    ProducerConfig config = new ProducerConfig(props);

    Producer<String, String> producer = new Producer<String, String>(config);

    for(int i=0;i<events;++i){

        long runtime = new Date().getTime();
        String ip    = "192.168.2." + rnd.nextInt(255);

        String msg= "Hello";

        KeyedMessage<String, String> data = new KeyedMessage<String, String>("sentences", ip, msg);
        producer.send(data);
    }
    producer.close();
}`

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM