解決Kafka消費者啟動時頻繁列印日誌
環境:
SpringBoot 2.1.5.RELEASE
Kafka kafka_2.11-1.1.1.tgz
kafka maven依賴
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
</dependency>
消費者:
public class ConsumerFastStart {
public static final String brokerList = "hadoop000:9092,hadoop001:9092,hadoop002:9092";
public static final String topic = "tests";
public static void main(String[] args) {
Properties properties = new Properties();
properties.put("key.deserializer", StringDeserializer.class.getName());
properties.put("value.deserializer", StringDeserializer.class.getName());
properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, brokerList);
properties.put("group.id", args[0]);
KafkaConsumer<String, String> consumer = new KafkaConsumer<>(properties);
consumer.subscribe(Collections.singletonList(topic));
while (true){
ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(1000));
for (ConsumerRecord<String, String> record : records) {
System.out.println(record.value());
}
}
}
}
生產者:
public class ProducerFastStart {
public static final String brokerList = "hadoop000:9092,hadoop001:9092,hadoop002:9092";
public static final String topic = "tests";
public static void main(String[] args) {
Properties properties = new Properties();
properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, brokerList);
//丟擲可重試異常,設定重試次數
properties.put(ProducerConfig.RETRIES_CONFIG, 10);
KafkaProducer<String, String> producer = new KafkaProducer<>(properties);
ProducerRecord<String, String> record = new ProducerRecord<>(topic, "Hello, world!");
try {
producer.send(record);
} catch (Exception e) {
e.printStackTrace();
} finally {
producer.close();
}
}
}
問題分析
我在百度這個問題時,很多人都說新增一段日誌配置到log4j.properties中,但是一直沒生效。我檢視了maven依賴找到了logback-classic。
我想應該配置的是logback.xml
1.建立logback.xml
2.新增xml配置
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<logger name="org.apache.kafka.clients" level="info" />
</configuration>
3.重啟生產者沒有日誌輸出,問題解決。
有緣人,希望能幫助你解決這個問題。
相關文章
- Kafka 消費者解析Kafka
- Kafka 消費組消費者分配策略Kafka
- 華為、小米頻繁釋出新機,消費者為何不買賬?
- kafka消費者消費訊息的流程Kafka
- RocketMQ之消費者啟動與消費流程MQ
- 「Kafka應用」消費者Kafka
- Kafka 消費者組 RebalanceKafka
- Kakfa -- 消費者啟動流程
- RocketMQ -- 消費者啟動流程MQ
- kafka消費者客戶端Kafka客戶端
- Kafka 1.0.0 多消費者示例Kafka
- kafka中生產者和消費者APIKafkaAPI
- 無鏡--kafka之消費者(四)Kafka
- Kafka入門(4):深入消費者Kafka
- Kafka 入門(二)--資料日誌、副本機制和消費策略Kafka
- kafka消費Kafka
- kafka9重複消費問題解決Kafka
- Apache Kafka消費者再平衡 | TechMyTalkApacheKafka
- kafka消費者提交方式(程式碼演示)Kafka
- Google:瞭解中國移動消費者Go
- 探索Kafka消費者的內部結構Kafka
- 解決生產日誌重複列印的問題
- Innodb: 自動開啟列印show engine status到err日誌
- Kafka - 消費介面分析Kafka
- Linux動態列印kernel日誌Linux
- 「Kafka應用」PHP實現生產者與消費者KafkaPHP
- 從消費者角度比較Kafka 與 RabbitMQ - OpenCredoKafkaMQ
- Kafka中消費者延遲處理訊息Kafka
- [20160119]日誌頻繁切換.txt
- 多維分析模型頻繁變動的解決方案有哪些?模型
- 使用代理IP時頻繁掉線如何解決?
- 插曲:Kafka的生產者案例和消費者原理解析Kafka
- GoLang中生產者消費者模式解決併發問題Golang模式
- 告警日誌頻繁出現Restarting dead background process QMNC資訊REST
- 阿里雲 KAFKA 消費者接收不到訊息阿里Kafka
- Kafka之消費與心跳Kafka
- Kafka實戰-實時日誌統計流程Kafka
- mysqld啟動失敗時日誌檢視命令MySql