gpt4 book ai didi

java - 如何将 Kafka (Java) 应用程序从 Windows 连接到 Linux 中的 Confluence

转载 作者:行者123 更新时间:2023-12-02 10:04:19 25 4
gpt4 key购买 nike

我正在使用 Winscp 和 Putty 在 Linux 服务器中运行 Confluence 5.0。我在 Windows 中有 Kafka (Java/Eclipse) 应用程序。

当我运行 Java 应用程序时,它无法识别 Linux 上运行的 Confluence 中的 Kafka 代理。

我已经测试了我的 Java 应用程序,通过在 MAC 终端中运行 Confluence 5.0,将数据发送到 MACBook 中的 Kafka 主题。现在我正在尝试在 Windows 中实现相同的 Kafka 应用程序。由于 Windows 不支持 Confluence,因此我在 Linux 服务器上运行。

我使用 Confluence 而不是 Apache Kafka,因为我在应用程序中使用 Schema-registry。

通过使用 netstat -tupln 和curl -v http:/localhost:端口号。弄清楚 Kafka 在 8082 上运行,架构注册表在 8081 上运行 details of ports 。下面是我的 Java 应用程序中的 Kafka Properties。

public static Properties producerProperties() {

// normal producer
properties.setProperty("bootstrap.servers", "127.0.0.1:8082");
properties.setProperty("acks", "all");
properties.setProperty("retries", "10");
// avro part
properties.setProperty("key.serializer", StringSerializer .class.getName());
properties.setProperty("value.serializer", KafkaAvroSerializer .class.getName());
properties.setProperty("schema.registry.url", "http://127.0.0.1:8081");

return properties;

}

public static Properties consumerProperties() {

// Properties properties = new Properties();
// normal consumer
properties.setProperty("bootstrap.servers", "127.0.0.1:8082");
//different for consumer
properties.setProperty("group.id", "Avro-consumer");
properties.setProperty("enable.auto.commit", "false");
properties.setProperty("auto.offset.reset", "earliest");

// avro part
properties.setProperty("key.deserializer", StringDeserializer.class.getName());
properties.setProperty("value.deserializer", KafkaAvroDeserializer.class.getName());
properties.setProperty("schema.registry.url", "http://127.0.0.1:8081");
properties.setProperty("specific.avro.reader", "true");

return properties;
}

public static Properties streamsProperties() {

// normal consumer
properties.put(StreamsConfig.APPLICATION_ID_CONFIG, "com.github.ptn006");
properties.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "127.0.0.1:8082");
properties.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");

properties.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass());
properties.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());

return properties;
}

预计:写入 Kafka 主题的数据。

实际:警告 无法建立与节点 -1 的连接。经纪人可能不可用。 (org.apache.kafka.clients.NetworkClient:589)

最佳答案

您需要确保advertised.listeners of the server.properties file in Kafka is resolvable由 Windows 机器。例如,还要确保防火墙允许访问 (netstat -tupln | grep LIST),并查找监听 0.0.0.0 的 Kafka 端口。

关于java - 如何将 Kafka (Java) 应用程序从 Windows 连接到 Linux 中的 Confluence,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55420778/

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