我尝试使用Kafka版本0.9.0和端口9092。如果我使用telnet,我成功地连接到这个地址,但是我无法使用javaapi连接到kafka服务器
下面是我的java示例,完全使用官方提供的文档:
Properties props = new Properties();
props.put("bootstrap.servers", "192.168.174.128:9092");
props.put("acks", "all");
props.put("retries", 0);
props.put("batch.size", 16384);
props.put("linger.ms", 1);
props.put("buffer.memory", 33554432);
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
Producer<String, String> producer = new KafkaProducer(props);
for(int i = 1; i < 10; i++) {
producer.send(new ProducerRecord<String, String>("test", Integer.toString(i), Integer.toString(i)));
}
producer.close();
我使用vmware虚拟机构建kafka服务器和zookeeper。我的虚拟机ip地址是192.168.174.128。我成功地创建和使用kafka客户端的消息。
这是一个异常完整的堆栈
2016-01-03 09:44:38.049 [kafka-producer-network-thread | producer-1] DEBUG [] [] Selector - Connection with localhost/127.0.0.1 disconnected
java.net.ConnectException: Connection refused: no further information
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:1.7.0_51]
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739) ~[na:1.7.0_51]
at org.apache.kafka.common.network.PlaintextTransportLayer.finishConnect(PlaintextTransportLayer.java:54) ~[kafka-clients-0.9.0.0.jar:na]
at org.apache.kafka.common.network.KafkaChannel.finishConnect(KafkaChannel.java:79) ~[kafka-clients-0.9.0.0.jar:na]
at org.apache.kafka.common.network.Selector.poll(Selector.java:274) ~[kafka-clients-0.9.0.0.jar:na]
at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:270) [kafka-clients-0.9.0.0.jar:na]
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:216) [kafka-clients-0.9.0.0.jar:na]
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:141) [kafka-clients-0.9.0.0.jar:na]
at java.lang.Thread.run(Thread.java:744) [na:1.7.0_51]
2016-01-03 09:44:38.049 [kafka-producer-network-thread | producer-1] DEBUG [] [] NetworkClient - Node 0 disconnected.
2016-01-03 09:44:38.078 [kafka-producer-network-thread | producer-1] DEBUG [] [] NetworkClient - No node found. Trying previously-seen node with ID 0
2016-01-03 09:44:38.078 [kafka-producer-network-thread | producer-1] DEBUG [] [] NetworkClient - Give up sending metadata request since no node is available
2016-01-03 09:44:38.099 [kafka-producer-network-thread | producer-1] DEBUG [] [] NetworkClient - Initiating connection to node 0 at localhost:9092.
2016-01-03 09:44:38.681 [kafka-producer-network-thread | producer-1] DEBUG [] [] Metrics - Removed sensor with name connections-closed:client-id-producer-1
2016-01-03 09:44:38.681 [kafka-producer-network-thread | producer-1] DEBUG [] [] Metrics - Removed sensor with name connections-created:client-id-producer-1
2016-01-03 09:44:38.681 [kafka-producer-network-thread | producer-1] DEBUG [] [] Metrics - Removed sensor with name bytes-sent-received:client-id-producer-1
2016-01-03 09:44:38.681 [kafka-producer-network-thread | producer-1] DEBUG [] [] Metrics - Removed sensor with name bytes-received:client-id-producer-1
2016-01-03 09:44:38.682 [kafka-producer-network-thread | producer-1] DEBUG [] [] Metrics - Removed sensor with name bytes-sent:client-id-producer-1
2016-01-03 09:44:38.682 [kafka-producer-network-thread | producer-1] DEBUG [] [] Metrics - Removed sensor with name select-time:client-id-producer-1
2016-01-03 09:44:38.682 [kafka-producer-network-thread | producer-1] DEBUG [] [] Metrics - Removed sensor with name io-time:client-id-producer-1
2016-01-03 09:44:38.682 [kafka-producer-network-thread | producer-1] DEBUG [] [] Metrics - Removed sensor with name node--1.bytes-sent
2016-01-03 09:44:38.683 [kafka-producer-network-thread | producer-1] DEBUG [] [] Metrics - Removed sensor with name node--1.bytes-received
2016-01-03 09:44:38.683 [kafka-producer-network-thread | producer-1] DEBUG [] [] Metrics - Removed sensor with name node--1.latency
2016-01-03 09:44:38.683 [kafka-producer-network-thread | producer-1] DEBUG [] [] Metrics - Removed sensor with name node-0.bytes-sent
2016-01-03 09:44:38.683 [kafka-producer-network-thread | producer-1] DEBUG [] [] Metrics - Removed sensor with name node-0.bytes-received
2016-01-03 09:44:38.683 [kafka-producer-network-thread | producer-1] DEBUG [] [] Metrics - Removed sensor with name node-0.latency
2016-01-03 09:44:38.683 [kafka-producer-network-thread | producer-1] DEBUG [] [] Sender - Shutdown of Kafka producer I/O thread has completed.
2016-01-03 09:44:38.683 [main] DEBUG [] [] KafkaProducer - The Kafka producer has closed.
2条答案
按热度按时间yrwegjxp1#
这发生在我身上是因为另一个问题:
0.10.1.0javaapi似乎与0.10.0.1服务器不兼容。
我希望这能解决别人的问题。
djmepvbi2#
我有这个问题。要解决此问题,您应该取消对server.properties文件中的以下配置的注解,并用zookeeper的ip填充它。
advised.host.name=zookeeper ip
正如Kafka的文件所说,这个配置是
要发布到zookeeper以供客户端使用的主机名
因为在新的kafka中,消费者(0.9)向代理请求zookeeper ip。