Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache kafka 服务器不接受Kafka消息(仅来自远程IP?) 我的卡夫卡服务器工作良好,如果我从C++应用程序或命令行中生成和消费,从本地机器。p>_Apache Kafka_Kafka Producer Api - Fatal编程技术网

Apache kafka 服务器不接受Kafka消息(仅来自远程IP?) 我的卡夫卡服务器工作良好,如果我从C++应用程序或命令行中生成和消费,从本地机器。p>

Apache kafka 服务器不接受Kafka消息(仅来自远程IP?) 我的卡夫卡服务器工作良好,如果我从C++应用程序或命令行中生成和消费,从本地机器。p>,apache-kafka,kafka-producer-api,Apache Kafka,Kafka Producer Api,但是从外部IP地址来看,它不能很好地工作:创建主题时,我看到网络流量使用tcpdump和ACKs(这意味着kafka正在应答),但我在队列中没有发现消息,java也没有给出错误。在日志上找不到任何内容。或者谷歌。这是我的应用程序: public class KafkaPBJProducer { private static String KAFKA_TOPIC = "test"; public static void main(String[] args) {

但是从外部IP地址来看,它不能很好地工作:创建主题时,我看到网络流量使用tcpdump和ACKs(这意味着kafka正在应答),但我在队列中没有发现消息,java也没有给出错误。在日志上找不到任何内容。或者谷歌。这是我的应用程序:

public class KafkaPBJProducer {
    private static String KAFKA_TOPIC = "test";

    public static void main(String[] args) {
        Properties properties = new Properties();
        properties.put("bootstrap.servers", "192.168.1.131:9092");
        properties.put("acks", "all");
        properties.put("retries", 0);
        properties.put("batch.size", 16384);
        properties.put("linger.ms", 1);
        properties.put("buffer.memory", 33554432);
        properties.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        properties.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");

        properties.put("kafka.topic", KAFKA_TOPIC);
        runMainLoop(properties);
    }

    static void runMainLoop(Properties properties) {
        @SuppressWarnings("resource")
        KafkaProducer<String, String> producer = new KafkaProducer<String, String>(properties);
        for (int count = 0; count < 10; count++) {
            String msg = getMsg(String.valueOf(count));
            System.out.println("Producing message: " + msg);
            producer.send(new ProducerRecord<String, String>(KAFKA_TOPIC, 0, "dev-" + count, msg));
            producer.flush();
        }
    }

    public static String getMsg(String id) {
        JsonObject obj = new JsonObject();
        try {
            obj.addProperty("id", id);
            obj.addProperty("timestamp", new Timestamp(System.currentTimeMillis()).toString());
            obj.addProperty("data", Base64.getEncoder().encodeToString("Hello, World!".getBytes("utf-8")));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return new Gson().toJson(obj);
    }
}
我可以看到主题已创建:

> bin/kafka-topics.sh --list --zookeeper localhost:2181
__consumer_offsets
test
我可以使用命令行手动向主题添加内容:

$ bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
>one
>two
>four
但如果我选中该主题,则仅列出手动发送的消息:

$ bin/kafka-console-consumer.sh --bootstrap-server 192.168.1.131:9092 --topic test --from-beginning
one
two
four

(after several minutes, I press CTRL-C)
^CProcessed a total of 3 messages
这里发生了什么?为什么创建了主题,但服务器上不接受任何消息?为什么卡夫卡不报告任何错误

蒂亚

找到了。根据,问题出在配置文件conf/servers.properties上;需要取消对此行的注释:

advertised.listeners=PLAINTEXT://192.168.1.131:9092

无论如何,谢谢。

是的-正如您所发现的,
广告。侦听器需要设置。如果您对更多信息感兴趣,请参阅此处:
advertised.listeners=PLAINTEXT://192.168.1.131:9092