如何将Kafka(Java)应用程序从Windows连接到Linux中的Confluent
我正在Linux服务器上使用Winscp和Putty运行Confluent 5.0。我在Windows中有Kafka(Java/Eclipse)应用程序 当我运行Java应用程序时,它并没有识别在Linux上合流运行的Kafka代理 我在MAC终端上运行Confluent 5.0,测试了我的Java应用程序,该应用程序将数据发送到MACBook中的Kafka主题。现在我尝试在Windows中实现相同的Kafka应用程序。由于Windows不支持Confluent,所以我在Linux服务器上运行 我使用Confluent而不是ApacheKafka,因为我在应用程序中使用模式注册表如何将Kafka(Java)应用程序从Windows连接到Linux中的Confluent,java,apache-kafka,confluent-platform,Java,Apache Kafka,Confluent Platform,我正在Linux服务器上使用Winscp和Putty运行Confluent 5.0。我在Windows中有Kafka(Java/Eclipse)应用程序 当我运行Java应用程序时,它并没有识别在Linux上合流运行的Kafka代理 我在MAC终端上运行Confluent 5.0,测试了我的Java应用程序,该应用程序将数据发送到MACBook中的Kafka主题。现在我尝试在Windows中实现相同的Kafka应用程序。由于Windows不支持Confluent,所以我在Linux服务器上运行
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;
}
通过使用netstat-tupln&curl-vhttp:/localhost:port-no,我们发现Kafka在8082上运行,schema registry在8081上运行。
下面是我在Java应用程序中的Kafka属性
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;
}
预期:
写入卡夫卡主题的数据
实际:
无法建立到节点-1的警告连接。经纪人可能不在。(org.apache.kafka.clients.NetworkClient:589)您需要确保由Windows计算机执行。另外,请确保防火墙允许访问(
netstat-tupln | grep LIST
),例如,在0.0.0
上查找卡夫卡端口 用java代码更新了我的文章,详细介绍了linux和kafka prop的端口。如果我还遗漏了什么,请告诉我。127.0.0.1
是您的Windows机器,而不是linux One谢谢!!通过指出linux服务器地址和端口号,它工作得很好!