IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 大数据 -> Invalid value earliest for configuration auto.commit.interval.ms: Not a number of type INT -> 正文阅读

[大数据]Invalid value earliest for configuration auto.commit.interval.ms: Not a number of type INT

Invalid value earliest for configuration auto.commit.interval.ms: Not a number of type INT 以及 Failed to construct kafka consumer

kafka消费者的api操作

代码如下

package com.qf.kafka.day1;

import org.apache.kafka.clients.consumer.*;
import scala.Int;

import java.util.Collections;
import java.util.Properties;

public class KafkaConsumerDemo {
    public static void main(String[] args) {

        Properties props = new Properties();
        props.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "hadoop01:9092,hadoop02:9092,hadoop03:9092");
        props.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
        props.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
        props.setProperty(ConsumerConfig.GROUP_ID_CONFIG, "g2");
        props.setProperty(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG, "earliest");

        //自动提交偏移量,默认true
        //当设置为false,consumer不再自动提交offset
//        props.setProperty(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG,"false");

//报错信息指向的位置
        KafkaConsumer consumer = new KafkaConsumer<String, String>(props);

        consumer.subscribe(Collections.singletonList("hadoop"));


        while (true) {
            ConsumerRecords<String, String> consumerRecord = consumer.poll(1000);//consumer会在Kafka停(猫)一秒
            for (ConsumerRecord<String, String> record : consumerRecord) {
                System.out.println(String.format("key=%s value=%s topic=%s partition=%d offset=%d timestamp=%d"
                        , record.key(), record.value(), record.topic(), record.partition(), record.offset(), record.timestamp()));
            }
        }


    }
}

(1)报错信息如下

"C:\Program Files\Java\jdk1.8.0_241\bin\java.exe" "-javaagent:D:\大数据\Big--Data软件\IDEA\IntelliJ IDEA 2021.1.1\lib\idea_rt.jar=11555:D:\大数据\Big--Data软件\IDEA\IntelliJ IDEA 2021.1.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_241\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\rt.jar;E:\IDEA__workstation\kafka-2102\target\classes;F:\apache-maven-3.6.3\repository\org\apache\kafka\kafka_2.11\2.3.0\kafka_2.11-2.3.0.jar;F:\apache-maven-3.6.3\repository\org\apache\kafka\kafka-clients\2.3.0\kafka-clients-2.3.0.jar;F:\apache-maven-3.6.3\repository\com\github\luben\zstd-jni\1.4.0-1\zstd-jni-1.4.0-1.jar;F:\apache-maven-3.6.3\repository\org\lz4\lz4-java\1.6.0\lz4-java-1.6.0.jar;F:\apache-maven-3.6.3\repository\org\xerial\snappy\snappy-java\1.1.7.3\snappy-java-1.1.7.3.jar;F:\apache-maven-3.6.3\repository\com\fasterxml\jackson\core\jackson-databind\2.9.9\jackson-databind-2.9.9.jar;F:\apache-maven-3.6.3\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;F:\apache-maven-3.6.3\repository\com\fasterxml\jackson\core\jackson-core\2.9.9\jackson-core-2.9.9.jar;F:\apache-maven-3.6.3\repository\com\fasterxml\jackson\module\jackson-module-scala_2.11\2.9.9\jackson-module-scala_2.11-2.9.9.jar;F:\apache-maven-3.6.3\repository\com\fasterxml\jackson\module\jackson-module-paranamer\2.9.9\jackson-module-paranamer-2.9.9.jar;F:\apache-maven-3.6.3\repository\com\thoughtworks\paranamer\paranamer\2.8\paranamer-2.8.jar;F:\apache-maven-3.6.3\repository\com\fasterxml\jackson\dataformat\jackson-dataformat-csv\2.9.9\jackson-dataformat-csv-2.9.9.jar;F:\apache-maven-3.6.3\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.9\jackson-datatype-jdk8-2.9.9.jar;F:\apache-maven-3.6.3\repository\net\sf\jopt-simple\jopt-simple\5.0.4\jopt-simple-5.0.4.jar;F:\apache-maven-3.6.3\repository\com\yammer\metrics\metrics-core\2.2.0\metrics-core-2.2.0.jar;F:\apache-maven-3.6.3\repository\org\scala-lang\scala-library\2.11.12\scala-library-2.11.12.jar;F:\apache-maven-3.6.3\repository\org\scala-lang\scala-reflect\2.11.12\scala-reflect-2.11.12.jar;F:\apache-maven-3.6.3\repository\com\typesafe\scala-logging\scala-logging_2.11\3.9.0\scala-logging_2.11-3.9.0.jar;F:\apache-maven-3.6.3\repository\org\slf4j\slf4j-api\1.7.26\slf4j-api-1.7.26.jar;F:\apache-maven-3.6.3\repository\com\101tec\zkclient\0.11\zkclient-0.11.jar;F:\apache-maven-3.6.3\repository\org\apache\zookeeper\zookeeper\3.4.14\zookeeper-3.4.14.jar;F:\apache-maven-3.6.3\repository\com\github\spotbugs\spotbugs-annotations\3.1.9\spotbugs-annotations-3.1.9.jar;F:\apache-maven-3.6.3\repository\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar;F:\apache-maven-3.6.3\repository\org\apache\yetus\audience-annotations\0.5.0\audience-annotations-0.5.0.jar" com.qf.kafka.day1.KafkaConsumerDemo
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" org.apache.kafka.common.config.ConfigException: Invalid value earliest for configuration auto.commit.interval.ms: Not a number of type INT
	at org.apache.kafka.common.config.ConfigDef.parseType(ConfigDef.java:718)
	at org.apache.kafka.common.config.ConfigDef.parseValue(ConfigDef.java:473)
	at org.apache.kafka.common.config.ConfigDef.parse(ConfigDef.java:466)
	at org.apache.kafka.common.config.AbstractConfig.<init>(AbstractConfig.java:108)
	at org.apache.kafka.common.config.AbstractConfig.<init>(AbstractConfig.java:129)
	at org.apache.kafka.clients.consumer.ConsumerConfig.<init>(ConsumerConfig.java:544)
	at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:664)
	at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:644)
	at com.qf.kafka.day1.KafkaConsumerDemo.main(KafkaConsumerDemo.java:23)

Process finished with exit code 1

解决办法
粗心导致

props.setProperty(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG, "earliest");

改为:
props.setProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); // auto.offset.reset 默认是 latest 当指定的组是一个未知的组,应该从哪个位置开始消费

#(2) Failed to construct kafka consumer
报错信息

"C:\Program Files\Java\jdk1.8.0_241\bin\java.exe" "-javaagent:D:\大数据\Big--Data软件\IDEA\IntelliJ IDEA 2021.1.1\lib\idea_rt.jar=9495:D:\大数据\Big--Data软件\IDEA\IntelliJ IDEA 2021.1.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_241\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\rt.jar;E:\IDEA__workstation\kafka-2102\target\classes;F:\apache-maven-3.6.3\repository\org\apache\kafka\kafka_2.11\2.3.0\kafka_2.11-2.3.0.jar;F:\apache-maven-3.6.3\repository\org\apache\kafka\kafka-clients\2.3.0\kafka-clients-2.3.0.jar;F:\apache-maven-3.6.3\repository\com\github\luben\zstd-jni\1.4.0-1\zstd-jni-1.4.0-1.jar;F:\apache-maven-3.6.3\repository\org\lz4\lz4-java\1.6.0\lz4-java-1.6.0.jar;F:\apache-maven-3.6.3\repository\org\xerial\snappy\snappy-java\1.1.7.3\snappy-java-1.1.7.3.jar;F:\apache-maven-3.6.3\repository\com\fasterxml\jackson\core\jackson-databind\2.9.9\jackson-databind-2.9.9.jar;F:\apache-maven-3.6.3\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;F:\apache-maven-3.6.3\repository\com\fasterxml\jackson\core\jackson-core\2.9.9\jackson-core-2.9.9.jar;F:\apache-maven-3.6.3\repository\com\fasterxml\jackson\module\jackson-module-scala_2.11\2.9.9\jackson-module-scala_2.11-2.9.9.jar;F:\apache-maven-3.6.3\repository\com\fasterxml\jackson\module\jackson-module-paranamer\2.9.9\jackson-module-paranamer-2.9.9.jar;F:\apache-maven-3.6.3\repository\com\thoughtworks\paranamer\paranamer\2.8\paranamer-2.8.jar;F:\apache-maven-3.6.3\repository\com\fasterxml\jackson\dataformat\jackson-dataformat-csv\2.9.9\jackson-dataformat-csv-2.9.9.jar;F:\apache-maven-3.6.3\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.9\jackson-datatype-jdk8-2.9.9.jar;F:\apache-maven-3.6.3\repository\net\sf\jopt-simple\jopt-simple\5.0.4\jopt-simple-5.0.4.jar;F:\apache-maven-3.6.3\repository\com\yammer\metrics\metrics-core\2.2.0\metrics-core-2.2.0.jar;F:\apache-maven-3.6.3\repository\org\scala-lang\scala-library\2.11.12\scala-library-2.11.12.jar;F:\apache-maven-3.6.3\repository\org\scala-lang\scala-reflect\2.11.12\scala-reflect-2.11.12.jar;F:\apache-maven-3.6.3\repository\com\typesafe\scala-logging\scala-logging_2.11\3.9.0\scala-logging_2.11-3.9.0.jar;F:\apache-maven-3.6.3\repository\org\slf4j\slf4j-api\1.7.26\slf4j-api-1.7.26.jar;F:\apache-maven-3.6.3\repository\com\101tec\zkclient\0.11\zkclient-0.11.jar;F:\apache-maven-3.6.3\repository\org\apache\zookeeper\zookeeper\3.4.14\zookeeper-3.4.14.jar;F:\apache-maven-3.6.3\repository\com\github\spotbugs\spotbugs-annotations\3.1.9\spotbugs-annotations-3.1.9.jar;F:\apache-maven-3.6.3\repository\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar;F:\apache-maven-3.6.3\repository\org\apache\yetus\audience-annotations\0.5.0\audience-annotations-0.5.0.jar" com.qf.kafka.day1.KafkaConsumerDemo
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" org.apache.kafka.common.KafkaException: Failed to construct kafka consumer
	at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:827)
	at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:664)
	at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:644)
	at com.qf.kafka.day1.KafkaConsumerDemo.main(KafkaConsumerDemo.java:25)
Caused by: org.apache.kafka.common.KafkaException: org.apache.kafka.common.serialization.StringSerializer is not an instance of org.apache.kafka.common.serialization.Deserializer
	at org.apache.kafka.common.config.AbstractConfig.getConfiguredInstance(AbstractConfig.java:372)
	at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:713)
	... 3 more

Process finished with exit code 1

这是包导错了,以上述代码为例

props.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
props.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");



改为:


props.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
props.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
        
  大数据 最新文章
实现Kafka至少消费一次
亚马逊云科技:还在苦于ETL?Zero ETL的时代
初探MapReduce
【SpringBoot框架篇】32.基于注解+redis实现
Elasticsearch:如何减少 Elasticsearch 集
Go redis操作
Redis面试题
专题五 Redis高并发场景
基于GBase8s和Calcite的多数据源查询
Redis——底层数据结构原理
上一篇文章      下一篇文章      查看所有文章
加:2021-08-19 12:07:10  更:2021-08-19 12:07:23 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/23 12:51:13-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码