返回到文章

采纳

编辑于

java客户端生产消息,但是服务端不消费消息,求帮助。

kafka

提问说明

三个集群配置如下:(zk用的自带的)

s1.properties
broker.id=1
port=9093
zookeeper.connect=127.0.0.1:2181

s2.properties
broker.id=2
port=9094
zookeeper.connect=127.0.0.1:2181

s3.properties
broker.id=3
port=9095
zookeeper.connect=127.0.0.1:2181

没有报错信息,直接卡住不动了!


 Properties props = new Properties();
        props.put("bootstrap.servers", "111.231.54.216:9093,111.231.54.216:9094,111.231.54.216:9095");
                props.put("acks", "all");
                props.put("retries", 0);
                props.put("batch.size", 16384);
                props.put("linger.ms", 1);
                props.put("buffer.memory", 33554432);
        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);
        for (int i = 0; i < 100; i++)
            try {
                 producer.send(new ProducerRecord<String, String>("my-topic", Integer.toString(i), Integer.toString(i)));
            } catch (Exception e) {
                System.out.println(e);
            }


        producer.close();

运行 kafka-console-consumer.sh --bootstrap-server localhost:9093 --from-beginning --topic my-topic
没有任何反应!