gpt4 book ai didi

apache-kafka - Apache Kafka 示例错误 : Failed to send message after 3 tries

转载 作者:行者123 更新时间:2023-12-03 22:07:06 25 4
gpt4 key购买 nike

我正在运行其网站中提到的这个 kafka 生产者示例

编码:

public class TestProducer {

public static void main(String[] args) {
long events = Long.parseLong(args[0]);
Random rnd = new Random();
Properties props = new Properties();
props.put("metadata.broker.list", "host.broker-1:9093, host.broker-2:9093, host.broker-3:9095");
props.put("serializer.class", "kafka.serializer.StringEncoder");
props.put("partitioner.class", "test.app.SimplePartitioner");
props.put("request.required.acks", "1");
ProducerConfig config = new ProducerConfig(props);
Producer<String, String> producer = new Producer<String, String>(config);
for (long nEvents = 0; nEvents < events; nEvents++) {
long runtime = new Date().getTime();
String ip = "192.168.2." + rnd.nextInt(255);
String msg = runtime + ",www.example.com," + ip;
KeyedMessage<String, String> data = new KeyedMessage<String, String>("page_visits", ip, msg);
producer.send(data);
}
producer.close();
}
}

public class SimplePartitioner implements Partitioner{
public SimplePartitioner (VerifiableProperties props) {

}

public int partition(Object key, int a_numPartitions) {
int partition = 0;
String stringKey = (String) key;
int offset = stringKey.lastIndexOf('.');
if (offset > 0) {
partition = Integer.parseInt( stringKey.substring(offset+1)) % a_numPartitions;
}
return partition;
}

}

更多细节:

我在主机(调用是生产者)上运行这个应用程序,它是远程主机代理[1-3]
  • 我可以从生产者主机 ping 和 ssh 代理主机。
  • 在server.properties 中提供了advertised.host.name(它们在brokers 中分别命名为server[1-3].properties

  • 属性:
    broker.id=1
    port=9093
    host.name=host.broker.internal.name
    advertised.host.name=host-broker1
    num.network.threads=3
    num.io.threads=8
    socket.send.buffer.bytes=102400
    socket.receive.buffer.bytes=102400
    socket.request.max.bytes=104857600
    log.dirs=/data/1/kafka-logs-1,/data/2/kafka-logs-2
    num.partitions=1
    num.recovery.threads.per.data.dir=1
    log.retention.hours=168
    log.segment.bytes=1073741824
    log.retention.check.interval.ms=300000
    log.cleaner.enable=false
    zookeeper.connect=zk1:2181,zk2:2181,zk3:2181
    zookeeper.connection.timeout.ms=6000

    关于如何解决此错误的任何想法?

    最佳答案

    我在运行 Kafka 生产者时遇到这些错误:

    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.

    找到解决办法:

    在我的 Mac 盒子上,下载 scala-2.10 后和 kafka_2.10-0.8.1 ,在kafka_2.10-0.8.1目录下,启动zookeeper,kafka server,创建test topic,一切正常。然后我需要为测试主题启动一个生产者。但有一个错误:
    yhuangMac:kafka_2.10-0.8.1 yhuang$ ./bin/kafka-console-producer.sh –broker-list localhost:9092 –topic test
    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.

    原因是kafka libs目录下,kafka release zip文件只包含slf4j-api的jar文件,漏掉了一个jar文件:slf4j-nop.jar,所以我们要去 http://www.slf4j.org , 下载 slf4j-1.7.7.zip ,然后解压,将slf4j-api-1.7.7、slf4j-nop-1.7.7.jar复制到kafka的libs目录下。

    再次重启kafka producer,现在没有报错了。

    来源: SOLUTION

    关于apache-kafka - Apache Kafka 示例错误 : Failed to send message after 3 tries,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23903843/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com