在 apache Kafka 中禁用 SLF4J 日志记录

Disable SLF4J Logging in apache Kafka

我在 Apache Kafka 上记录 SLF4J 时遇到问题。我想将 Tomcats Servlet Container Catalina 与 Apache Kafka 结合使用。我的 Java 应用程序必须集成到 Camunda 的 BPM 流程中。 Java 编码的集成到目前为止也有效——没有集成 Apache Kafka Producer。如果我将其集成到 Camunda 流程中,我会收到此错误:

java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/apache/catalina/loader/ParallelWebappClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of java/net/URLClassLoader) for the method's defining class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type org/slf4j/ILoggerFactory used in the signature
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:418)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
at org.apache.kafka.clients.CommonClientConfigs.<clinit>(CommonClientConfigs.java:32)
at org.apache.kafka.clients.producer.ProducerConfig.<clinit>(ProducerConfig.java:305)
at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:304)

据我了解错误,Camunda 和 Apache Kafka 正在尝试调用 SLF4J 记录器,不是吗? 但就我而言,我需要 Camunda 记录器。所以我想禁用 Apache Kafka 日志记录来解决这个问题。 到目前为止,我的简单 Kafka Producer 看起来像这样:

        String topicName = "camunda";
    String test = "test123";
     Properties props = new Properties();
      props.put("bootstrap.servers", "localhost:9092,localhost:9093");
      props.put("key.serializer","org.apache.kafka.common.serialization.StringSerializer");         
      props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");

      Producer<String, String> producer = new KafkaProducer <>(props);
      ProducerRecord<String, String> record = new ProducerRecord<>(topicName,test);
      producer.send(record);
      producer.close();

有没有办法解决这个问题?不幸的是,我找不到任何关于如何禁用 Kafka 记录器的条目,或者问题出在其他地方?

非常感谢

为 Maven 对 apache Kafka 的依赖禁用 SFL4J-Logger 的方法对我来说效果很好。我按如下方式更改了我的 pom 文件:

<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka-clients</artifactId>
    <version>2.0.0</version>
      <exclusions>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
        </exclusion>
     </exclusions>
</dependency>