【发布时间】:2019-08-20 14:12:56
【问题描述】:
我正在使用 Winscp 和 Putty 在 Linux 服务器上运行 Confluent 5.0。我在 Windows 中有 Kafka (Java/Eclipse) 应用程序。
当我运行 Java 应用程序时,它无法识别 Linux 上运行的 Confluent 中的 Kafka 代理。
我通过在 MAC 终端中运行 Confluent 5.0 测试了我的 Java 应用程序,该应用程序将数据发送到 MACBook 中的 Kafka 主题。现在我正在尝试在 Windows 中实现相同的 Kafka 应用程序。由于 Windows 不支持 Confluent,所以我在 Linux 服务器上运行。
我使用 Confluent 而不是 Apache Kafka,因为我在我的应用程序中使用了 Schema-registry。
通过使用 netstat -tupln & curl -v http://localhost:port no。发现 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 主题的数据。
实际: WARN 无法建立到节点 -1 的连接。经纪人可能不可用。 (org.apache.kafka.clients.NetworkClient:589)
【问题讨论】:
标签: java apache-kafka confluent-platform