http://blog.sina.com.cn/s/blog_998c49430102x49o.html


java kafka 连接错误

  (2017-01-05 13:28:11)
标签: 

java

 

kafka

分类: java
linux kafka server 192.168.0.141 hostname  bogon
在windows
java 代码

package myzookeeper;

import java.util.Properties;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;

public class myCustomer {

public static void  main(String[] args) {
Properties props = new Properties();  
        props.put("bootstrap.servers", "192.168.0.141:9092");  
        props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");  
        props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");  
        Producer producer = new KafkaProducer<>(props);  
        producer.send(new ProducerRecord<>("mytopic", "axxxx", "axxxx"));
        System.out.println("1");
        producer.close();  
}
}


报错 Error connecting to node 0 at bogon:9092:
不能解析bogon
kafka 连接原理
首先连接  192.168.0.141:9092
再连接返回的host.name =  bogon ,
最后继续连接advertised.host.name= bogon
解决办法
添加window解析
hosts 文件增加 
192.168.0.141  bogon
用cmd ping  bogon 试试如果可以ping通即可。


[main] INFO  org.apache.kafka.clients.producer.ProducerConfig  - ProducerConfig values:
acks = 1
batch.size = 16384
block.on.buffer.full = false
bootstrap.servers = [192.168.0.141:9092]
buffer.memory = 33554432
client.id = producer-1
compression.type = none
connections.max.idle.ms = 540000
interceptor.classes = null
key.serializer = class org.apache.kafka.common.serialization.StringSerializer
linger.ms = 0
max.block.ms = 60000
max.in.flight.requests.per.connection = 5
max.request.size = 1048576
metadata.fetch.timeout.ms = 60000
metadata.max.age.ms = 300000
metric.reporters = []
metrics.num.samples = 2
metrics.sample.window.ms = 30000
partitioner.class = class org.apache.kafka.clients.producer.internals.DefaultPartitioner
receive.buffer.bytes = 32768
reconnect.backoff.ms = 50
request.timeout.ms = 30000
retries = 0
retry.backoff.ms = 100
sasl.kerberos.kinit.cmd = /usr/bin/kinit
sasl.kerberos.min.time.before.relogin = 60000
sasl.kerberos.service.name = null
sasl.kerberos.ticket.renew.jitter = 0.05
sasl.kerberos.ticket.renew.window.factor = 0.8
sasl.mechanism = GSSAPI
security.protocol = PLAINTEXT
send.buffer.bytes = 131072
ssl.cipher.suites = null
ssl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1]
ssl.endpoint.identification.algorithm = null
ssl.key.password = null
ssl.keymanager.algorithm = SunX509
ssl.keystore.location = null
ssl.keystore.password = null
ssl.keystore.type = JKS
ssl.protocol = TLS
ssl.provider = null
ssl.secure.random.implementation = null
ssl.trustmanager.algorithm = PKIX
ssl.truststore.location = null
ssl.truststore.password = null
ssl.truststore.type = JKS
timeout.ms = 30000
value.serializer = class org.apache.kafka.common.serialization.StringSerializer

92   [main] DEBUG org.apache.kafka.common.metrics.Metrics  - Added sensor with name bufferpool-wait-time
95   [main] DEBUG org.apache.kafka.common.metrics.Metrics  - Added sensor with name buffer-exhausted-records
98   [main] DEBUG org.apache.kafka.clients.Metadata  - Updated cluster metadata version 1 to Cluster(id = null, nodes = [192.168.0.141:9092 (id: -1 rack: null)], partitions = [])
178  [main] DEBUG org.apache.kafka.common.metrics.Metrics  - Added sensor with name connections-closed:
178  [main] DEBUG org.apache.kafka.common.metrics.Metrics  - Added sensor with name connections-created:
178  [main] DEBUG org.apache.kafka.common.metrics.Metrics  - Added sensor with name bytes-sent-received:
178  [main] DEBUG org.apache.kafka.common.metrics.Metrics  - Added sensor with name bytes-sent:
179  [main] DEBUG org.apache.kafka.common.metrics.Metrics  - Added sensor with name bytes-received:
179  [main] DEBUG org.apache.kafka.common.metrics.Metrics  - Added sensor with name select-time:
180  [main] DEBUG org.apache.kafka.common.metrics.Metrics  - Added sensor with name io-time:
184  [main] DEBUG org.apache.kafka.common.metrics.Metrics  - Added sensor with name batch-size
184  [main] DEBUG org.apache.kafka.common.metrics.Metrics  - Added sensor with name compression-rate
184  [main] DEBUG org.apache.kafka.common.metrics.Metrics  - Added sensor with name queue-time
184  [main] DEBUG org.apache.kafka.common.metrics.Metrics  - Added sensor with name request-time
185  [main] DEBUG org.apache.kafka.common.metrics.Metrics  - Added sensor with name produce-throttle-time
185  [main] DEBUG org.apache.kafka.common.metrics.Metrics  - Added sensor with name records-per-request
185  [main] DEBUG org.apache.kafka.common.metrics.Metrics  - Added sensor with name record-retries
185  [main] DEBUG org.apache.kafka.common.metrics.Metrics  - Added sensor with name errors
185  [main] DEBUG org.apache.kafka.common.metrics.Metrics  - Added sensor with name record-size-max
187  [kafka-producer-network-thread | producer-1] DEBUG org.apache.kafka.clients.producer.internals.Sender  - Starting Kafka producer I/O thread.
189  [main] INFO  org.apache.kafka.common.utils.AppInfoParser  - Kafka version : 0.10.1.1
189  [main] INFO  org.apache.kafka.common.utils.AppInfoParser  - Kafka commitId : f10ef2720b03b247
190  [main] DEBUG org.apache.kafka.clients.producer.KafkaProducer  - Kafka producer started
198  [kafka-producer-network-thread | producer-1] DEBUG org.apache.kafka.clients.NetworkClient  - Initialize connection to node -1 for sending metadata request
198  [kafka-producer-network-thread | producer-1] DEBUG org.apache.kafka.clients.NetworkClient  - Initiating connection to node -1 at 192.168.0.141:9092.
201  [kafka-producer-network-thread | producer-1] DEBUG org.apache.kafka.common.metrics.Metrics  - Added sensor with name node--1.bytes-sent
202  [kafka-producer-network-thread | producer-1] DEBUG org.apache.kafka.common.metrics.Metrics  - Added sensor with name node--1.bytes-received
202  [kafka-producer-network-thread | producer-1] DEBUG org.apache.kafka.common.metrics.Metrics  - Added sensor with name node--1.latency
203  [kafka-producer-network-thread | producer-1] DEBUG org.apache.kafka.common.network.Selector  - Created socket with SO_RCVBUF = 32768, SO_SNDBUF = 131072, SO_TIMEOUT = 0 to node -1
203  [kafka-producer-network-thread | producer-1] DEBUG org.apache.kafka.clients.NetworkClient  - Completed connection to node -1
230  [kafka-producer-network-thread | producer-1] DEBUG org.apache.kafka.clients.NetworkClient  - Sending metadata request {topics=[mytopic]} to node -1
280  [kafka-producer-network-thread | producer-1] DEBUG org.apache.kafka.clients.Metadata  - Updated cluster metadata version 2 to Cluster(id = xCTLtVIiQ8iFaaTTmtsqig, nodes = [bogon:9092 (id: 0 rack: null)], partitions = [Partition(topic = mytopic, partition = 0, leader = 0, replicas = [0,], isr = [0,])])
1
293  [main] INFO  org.apache.kafka.clients.producer.KafkaProducer  - Closing the Kafka producer with timeoutMillis = 9223372036854775807 ms.
293  [kafka-producer-network-thread | producer-1] DEBUG org.apache.kafka.clients.NetworkClient  - Initiating connection to node 0 at bogon:9092.
11572 [kafka-producer-network-thread | producer-1] DEBUG org.apache.kafka.clients.NetworkClient  - Error connecting to node 0 at bogon:9092:
java.io.IOException: Can't resolve address: bogon:9092
at org.apache.kafka.common.network.Selector.connect(Selector.
at org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.
at org.apache.kafka.clients.NetworkClient.ready(NetworkClient.
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.
at java.lang.Thread.run(Unknown Source)
Caused by: java.nio.channels.UnresolvedAddressException
at sun.nio.ch.Net.checkAddress(Unknown Source)
at sun.nio.ch.SocketChannelImpl.connect(Unknown Source)
at org.apache.kafka.common.network.Selector.connect(Selector.
... 5 more
11574 [kafka-producer-network-thread | producer-1] DEBUG org.apache.kafka.clients.producer.internals.Sender  - Beginning shutdown of Kafka producer I/O thread, sending remaining records.
11574 [kafka-producer-network-thread | producer-1] DEBUG org.apache.kafka.clients.NetworkClient  - Initiating connection to node 0 at bogon:9092.
11574 [kafka-producer-network-thread | producer-1] DEBUG org.apache.kafka.clients.NetworkClient  - Error connecting to node 0 at bogon:9092:
java.io.IOException: Can't resolve address: bogon:9092
at org.apache.kafka.common.network.Selector.connect(Selector.
at org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.
at org.apache.kafka.clients.NetworkClient.ready(NetworkClient.
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.
at java.lang.Thread.run(Unknown Source)
Caused by: java.nio.channels.UnresolvedAddressException
at sun.nio.ch.Net.checkAddress(Unknown Source)
at sun.nio.ch.SocketChannelImpl.connect(Unknown Source)
at org.apache.kafka.common.network.Selector.connect(Selector.
... 5 more
11575 [kafka-producer-network-thread | producer-1] DEBUG org.apache.kafka.clients.NetworkClient  - Give up sending metadata request since no node is available
11624 [kafka-producer-network-thread | producer-1] DEBUG org.apache.kafka.clients.NetworkClient  - Initiating connection to node 0 at bogon:9092.
11624 [kafka-producer-network-thread | producer-1] DEBUG org.apache.kafka.clients.NetworkClient  - Error connecting to node 0 at bogon:9092:
java.io.IOException:  Can't resolve address: bogon:9092
at org.apache.kafka.common.network.Selector.connect(Selector.
at org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.
at org.apache.kafka.clients.NetworkClient.ready(NetworkClient.
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.
at java.lang.Thread.run(Unknown Source)
Caused by: java.nio.channels.UnresolvedAddressException
at sun.nio.ch.Net.checkAddress(Unknown Source)
at sun.nio.ch.SocketChannelImpl.connect(Unknown Source)
at org.apache.kafka.common.network.Selector.connect(Selector.
... 5 more


GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐