java - Apache Kafka 生产者看不到代理
问题描述
我已经在 PC 上设置了 Apache Kafka 并添加了新主题。当我运行 Kafka 和 Zookeeper 时,它运行没有问题,但是当我尝试发布消息时,没有发送消息,并且我看到以下日志:
WARN 18004 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : [Producer clientId=producer-1] Connection to node -1 (/127.0.0.1:9092) could not be established. Broker may not be available.
WARN 18004 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : [Producer clientId=producer-1] Bootstrap broker 127.0.0.1:9092 (id: -1 rack: null) disconnected
我的卡夫卡配置是:
@Configuration
public class KafkaProducerConfig {
private final static String SERVER_ADDRESS = "127.0.0.1:9092";
@Bean
public ProducerFactory<String, String> producerFactory() {
Map<String, Object> configProps = new HashMap<>();
configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, SERVER_ADDRESS);
configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
return new DefaultKafkaProducerFactory<>(configProps);
}
@Bean
public KafkaTemplate<String, String> kafkaTemplate() {
return new KafkaTemplate<>(producerFactory());
}
}
我的 server.properties 是:
############################# Server Basics #############################
broker.id=0
############################# Socket Server Settings #############################
listeners=PLAINTEXT://127.0.0.1:9092
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
############################# Log Basics #############################
log.dirs=./tmp/kafka-logs
num.partitions=1
num.recovery.threads.per.data.dir=1
############################# Internal Topic Settings #############################
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
############################# Log Retention Policy #############################
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
############################# Zookeeper #############################
zookeeper.connect=localhost:2181
# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=18000
############################# Group Coordinator Settings #############################
group.initial.rebalance.delay.ms=0
问题是什么?我该如何解决?
解决方案
推荐阅读
- node.js - 身份验证在招摇中工作正常,但在前端应用程序中响应为未经授权,尽管它将 jwt 令牌存储在 cookie 中
- azure - 如何在 Linux Azure App Service 上安装数据包
- list - 从多个数字列表中返回最高平均值的函数
- reactjs - 如何在 Victory (ReactJS) 中使用分组数据创建直方图?
- laravel - 从源“https://.....r.in”访问“https://......login”处的 XMLHttpRequest 已被 CORS 策略阻止
- css - vscode中的SvelteKit未使用的CSS选择器警告
- javascript - 重新定义和范围之间的相关性
- python - 在 kivymd GUI 框架中显示 openCV 实时流
- reactjs - 输入复选框没有按我的预期工作
- android - 为什么我在 Android Studio 中启动几次模拟器后总是失去真正的手机皮肤?