Apache kafka 无法建立到节点-1的连接。经纪人可能不在。Windows和WSL
下面是一个超级简单的教程,其中包含了最少的配置编辑。 当我尝试在Java应用程序中创建生产者时,它找不到代理。但是,当我设置控制台生产者时,我可以通过同一个代理进行生产和消费 这是我的设置Apache kafka 无法建立到节点-1的连接。经纪人可能不在。Windows和WSL,apache-kafka,Apache Kafka,下面是一个超级简单的教程,其中包含了最少的配置编辑。 当我尝试在Java应用程序中创建生产者时,它找不到代理。但是,当我设置控制台生产者时,我可以通过同一个代理进行生产和消费 这是我的设置 服务器程序: offsets.topic.replication.factor=1 transaction.state.log.replication.factor=1 transaction.state.log.min.isr=1 log.retention.hours=168 log.segment.
服务器程序:
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
log.retention.hours=168
log.segment.bytes=1073741824
zookeeper.connect=localhost:2181
zookeeper.connection.timeout.ms=18000
group.initial.rebalance.delay.ms=0
dataDir=/mnt/c/Users/majaxing/Downloads/kafka_2.13-2.6.0/data/zookeeper
clientPort=2181
# disable the per-ip limit on the number of connections since this is a non-production config
maxClientCnxns=0
# Disable the adminserver by default to avoid port conflicts.
# Set the port to something non-conflicting if choosing to enable this
admin.enableServer=false
动物园管理员。权限:
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
log.retention.hours=168
log.segment.bytes=1073741824
zookeeper.connect=localhost:2181
zookeeper.connection.timeout.ms=18000
group.initial.rebalance.delay.ms=0
dataDir=/mnt/c/Users/majaxing/Downloads/kafka_2.13-2.6.0/data/zookeeper
clientPort=2181
# disable the per-ip limit on the number of connections since this is a non-production config
maxClientCnxns=0
# Disable the adminserver by default to avoid port conflicts.
# Set the port to something non-conflicting if choosing to enable this
admin.enableServer=false
运行这两个命令可以设置消费者/生产者,他们可以通过kafka发送消息kafka-console-consumer.sh--引导服务器本地主机:9092--主题优先\u主题--将我的第三个应用程序分组
kafka-console-producer.sh--引导服务器本地主机:9092--主题优先\u主题
以下是我创建简单生产者的java代码:
package com.github.jaxing.kafka.tutorial1;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringSerializer;
import java.util.Properties;
public class ProducerDemo {
public static void main(String[] args) {
String bootstrapServers = "localhost:9092";
// create Producer properties
Properties properties = new Properties();
properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
// create the producer
KafkaProducer<String, String> producer = new KafkaProducer<>(properties);
// create prducer recoder
ProducerRecord<String, String> record =
new ProducerRecord<>("first_topic", "hello world");
// send data
producer.send(record);
producer.flush();
producer.close();
}
}
我在windows计算机上,但正在WSL2中运行kafka。我曾尝试使用WindowsJavaVersion15和LinuxJava11来运行上述代码,但得到了相同的输出
有人有什么想法吗
谢谢
因为卡夫卡可以在Windows中运行,所以您应该这样做。或者从WSL2运行Java代码