我已经通过maven docker plugin https://dmp.fabric8.io/配置了Kafka + ZooKeeper:
$$childTail
在这种配置下,一切正常。
现在我需要将Kafka端口(主机系统的转发端口)从<image>
<name>wurstmeister/zookeeper:latest</name>
<alias>zookeeper</alias>
<run>
<ports>
<port>2181:2181</port>
</ports>
</run>
</image>
<image>
<name>wurstmeister/kafka:1.0.0</name>
<alias>kafka</alias>
<run>
<ports>
<port>9092:9092</port>
</ports>
<links>
<link>zookeeper:zookeeper</link>
</links>
<env>
<KAFKA_ADVERTISED_HOST_NAME>127.0.0.1</KAFKA_ADVERTISED_HOST_NAME>
<KAFKA_ZOOKEEPER_CONNECT>zookeeper:2181</KAFKA_ZOOKEEPER_CONNECT>
</env>
</run>
</image>
更改为9092
。
在我的Spring Boot应用程序的9093
中,我添加了以下行:
application.properties
并且还将Kafka图像的配置更改为:
spring.kafka.bootstrap-servers=127.0.0.1:9093
并遇到以下错误:
<image>
<name>wurstmeister/kafka:1.0.0</name>
<alias>kafka</alias>
<run>
<ports>
<port>9093:9092</port>
</ports>
<links>
<link>zookeeper:zookeeper</link>
</links>
<env>
<KAFKA_ADVERTISED_HOST_NAME>127.0.0.1</KAFKA_ADVERTISED_HOST_NAME>
<KAFKA_ZOOKEEPER_CONNECT>zookeeper:2181</KAFKA_ZOOKEEPER_CONNECT>
</env>
</run>
</image>
我做错了什么以及如何解决?
为什么NetworkClient仍在尝试连接2017-11-22 18:18:16.453 DEBUG 17532 --- [ad | producer-1] o.a.k.clients.producer.internals.Sender : Starting Kafka producer I/O thread.
2017-11-22 18:18:16.453 DEBUG 17532 --- [ main] o.a.k.clients.producer.KafkaProducer : Kafka producer started
2017-11-22 18:18:16.456 DEBUG 17532 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : Initialize connection to node -1 for sending metadata request
2017-11-22 18:18:16.456 DEBUG 17532 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : Initiating connection to node -1 at 127.0.0.1:9093.
2017-11-22 18:18:16.457 DEBUG 17532 --- [ad | producer-1] org.apache.kafka.common.metrics.Metrics : Added sensor with name node--1.bytes-sent
2017-11-22 18:18:16.457 DEBUG 17532 --- [ad | producer-1] org.apache.kafka.common.metrics.Metrics : Added sensor with name node--1.bytes-received
2017-11-22 18:18:16.458 DEBUG 17532 --- [ad | producer-1] org.apache.kafka.common.metrics.Metrics : Added sensor with name node--1.latency
2017-11-22 18:18:16.458 DEBUG 17532 --- [ad | producer-1] o.apache.kafka.common.network.Selector : Created socket with SO_RCVBUF = 32768, SO_SNDBUF = 131072, SO_TIMEOUT = 0 to node -1
2017-11-22 18:18:16.458 DEBUG 17532 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : Completed connection to node -1. Fetching API versions.
2017-11-22 18:18:16.458 DEBUG 17532 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : Initiating API versions fetch from node -1.
2017-11-22 18:18:16.470 DEBUG 17532 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : Recorded API versions for node -1: (Produce(0): 0 to 5 [usable: 3], Fetch(1): 0 to 6 [usable: 5], Offsets(2): 0 to 2 [usable: 2], Metadata(3): 0 to 5 [usable: 4], LeaderAndIsr(4): 0 to 1 [usable: 0], StopReplica(5): 0 [usable: 0], UpdateMetadata(6): 0 to 4 [usable: 3], ControlledShutdown(7): 0 to 1 [usable: 1], OffsetCommit(8): 0 to 3 [usable: 3], OffsetFetch(9): 0 to 3 [usable: 3], FindCoordinator(10): 0 to 1 [usable: 1], JoinGroup(11): 0 to 2 [usable: 2], Heartbeat(12): 0 to 1 [usable: 1], LeaveGroup(13): 0 to 1 [usable: 1], SyncGroup(14): 0 to 1 [usable: 1], DescribeGroups(15): 0 to 1 [usable: 1], ListGroups(16): 0 to 1 [usable: 1], SaslHandshake(17): 0 to 1 [usable: 0], ApiVersions(18): 0 to 1 [usable: 1], CreateTopics(19): 0 to 2 [usable: 2], DeleteTopics(20): 0 to 1 [usable: 1], DeleteRecords(21): 0 [usable: 0], InitProducerId(22): 0 [usable: 0], OffsetForLeaderEpoch(23): 0 [usable: 0], AddPartitionsToTxn(24): 0 [usable: 0], AddOffsetsToTxn(25): 0 [usable: 0], EndTxn(26): 0 [usable: 0], WriteTxnMarkers(27): 0 [usable: 0], TxnOffsetCommit(28): 0 [usable: 0], DescribeAcls(29): 0 [usable: 0], CreateAcls(30): 0 [usable: 0], DeleteAcls(31): 0 [usable: 0], DescribeConfigs(32): 0 [usable: 0], AlterConfigs(33): 0 [usable: 0], UNKNOWN(34): 0, UNKNOWN(35): 0, UNKNOWN(36): 0, UNKNOWN(37): 0)
2017-11-22 18:18:16.471 DEBUG 17532 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : Sending metadata request (type=MetadataRequest, topics=boot.test) to node -1
2017-11-22 18:18:16.477 DEBUG 17532 --- [ad | producer-1] org.apache.kafka.clients.Metadata : Updated cluster metadata version 2 to Cluster(id = I2vTDIF_RYacc2xxU2iAyQ, nodes = [127.0.0.1:9092 (id: 1001 rack: null)], partitions = [Partition(topic = boot.test, partition = 0, leader = 1001, replicas = [1001], isr = [1001])])
2017-11-22 18:18:16.492 DEBUG 17532 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : Initiating connection to node 1001 at 127.0.0.1:9092.
2017-11-22 18:18:17.115 DEBUG 17532 --- [ntainer#0-0-C-1] org.apache.kafka.common.metrics.Metrics : Added sensor with name node-2147482646.bytes-sent
2017-11-22 18:18:17.115 DEBUG 17532 --- [ntainer#0-0-C-1] org.apache.kafka.common.metrics.Metrics : Added sensor with name node-2147482646.bytes-received
2017-11-22 18:18:17.115 DEBUG 17532 --- [ntainer#0-0-C-1] org.apache.kafka.common.metrics.Metrics : Added sensor with name node-2147482646.latency
2017-11-22 18:18:17.119 DEBUG 17532 --- [ntainer#0-0-C-1] o.apache.kafka.common.network.Selector : Connection with /127.0.0.1 disconnected
java.net.ConnectException: Connection refused: no further information
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:1.8.0_152]
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717) ~[na:1.8.0_152]
at org.apache.kafka.common.network.PlaintextTransportLayer.finishConnect(PlaintextTransportLayer.java:50) ~[kafka-clients-0.11.0.0.jar:na]
at org.apache.kafka.common.network.KafkaChannel.finishConnect(KafkaChannel.java:95) ~[kafka-clients-0.11.0.0.jar:na]
at org.apache.kafka.common.network.Selector.pollSelectionKeys(Selector.java:359) [kafka-clients-0.11.0.0.jar:na]
at org.apache.kafka.common.network.Selector.poll(Selector.java:326) [kafka-clients-0.11.0.0.jar:na]
at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:432) [kafka-clients-0.11.0.0.jar:na]
at org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient.poll(ConsumerNetworkClient.java:232) [kafka-clients-0.11.0.0.jar:na]
at org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient.poll(ConsumerNetworkClient.java:208) [kafka-clients-0.11.0.0.jar:na]
at org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient.poll(ConsumerNetworkClient.java:168) [kafka-clients-0.11.0.0.jar:na]
at org.apache.kafka.clients.consumer.internals.AbstractCoordinator.joinGroupIfNeeded(AbstractCoordinator.java:358) [kafka-clients-0.11.0.0.jar:na]
at org.apache.kafka.clients.consumer.internals.AbstractCoordinator.ensureActiveGroup(AbstractCoordinator.java:310) [kafka-clients-0.11.0.0.jar:na]
at org.apache.kafka.clients.consumer.internals.ConsumerCoordinator.poll(ConsumerCoordinator.java:297) [kafka-clients-0.11.0.0.jar:na]
at org.apache.kafka.clients.consumer.KafkaConsumer.pollOnce(KafkaConsumer.java:1078) [kafka-clients-0.11.0.0.jar:na]
at org.apache.kafka.clients.consumer.KafkaConsumer.poll(KafkaConsumer.java:1043) [kafka-clients-0.11.0.0.jar:na]
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.run(KafkaMessageListenerContainer.java:571) [spring-kafka-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_152]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_152]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_152]
2017-11-22 18:18:17.119 DEBUG 17532 --- [ntainer#0-0-C-1] org.apache.kafka.clients.NetworkClient : Node 2147482646 disconnected.
2017-11-22 18:18:17.120 WARN 17532 --- [ntainer#0-0-C-1] org.apache.kafka.clients.NetworkClient : Connection to node 2147482646 could not be established. Broker may not be available.
2017-11-22 18:18:17.120 DEBUG 17532 --- [ntainer#0-0-C-1] o.a.k.c.c.i.ConsumerNetworkClient : Cancelled JOIN_GROUP request {api_key=11,api_version=2,correlation_id=3,client_id=consumer-1} with correlation id 3 due to node 2147482646 being disconnected
2017-11-22 18:18:17.120 INFO 17532 --- [ntainer#0-0-C-1] o.a.k.c.c.internals.AbstractCoordinator : Marking the coordinator 127.0.0.1:9092 (id: 2147482646 rack: null) dead for group boot
2017-11-22 18:18:17.221 DEBUG 17532 --- [ntainer#0-0-C-1] o.a.k.c.c.internals.AbstractCoordinator : Sending GroupCoordinator request for group boot to broker 127.0.0.1:9092 (id: 1001 rack: null)
2017-11-22 18:18:17.221 DEBUG 17532 --- [ntainer#0-0-C-1] org.apache.kafka.clients.NetworkClient : Initiating connection to node 1001 at 127.0.0.1:9092.
2017-11-22 18:18:17.494 DEBUG 17532 --- [ad | producer-1] org.apache.kafka.common.metrics.Metrics : Added sensor with name node-1001.bytes-sent
2017-11-22 18:18:17.494 DEBUG 17532 --- [ad | producer-1] org.apache.kafka.common.metrics.Metrics : Added sensor with name node-1001.bytes-received
2017-11-22 18:18:17.494 DEBUG 17532 --- [ad | producer-1] org.apache.kafka.common.metrics.Metrics : Added sensor with name node-1001.latency
2017-11-22 18:18:17.495 DEBUG 17532 --- [ad | producer-1] o.apache.kafka.common.network.Selector : Connection with /127.0.0.1 disconnected
?
9092
已更新
我还尝试了以下2017-11-22 18:18:16.492 DEBUG 17532 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : Initiating connection to node 1001 at 127.0.0.1:9092.
属性:
env
这样我又出现了<env>
<KAFKA_ADVERTISED_HOST_NAME>127.0.0.1</KAFKA_ADVERTISED_HOST_NAME>
<KAFKA_ADVERTISED_PORT>9093</KAFKA_ADVERTISED_PORT>
<KAFKA_ZOOKEEPER_CONNECT>zookeeper:2181</KAFKA_ZOOKEEPER_CONNECT>
</env>
错误:
LEADER_NOT_AVAILABLE
这是Kafka容器日志:
2017-11-22 22:11:54.482 DEBUG 8988 --- [ad | producer-1] o.a.k.clients.producer.internals.Sender : Starting Kafka producer I/O thread.
2017-11-22 22:11:54.482 INFO 8988 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka commitId : cb8625948210849f
2017-11-22 22:11:54.482 DEBUG 8988 --- [ main] o.a.k.clients.producer.KafkaProducer : Kafka producer started
2017-11-22 22:11:54.484 DEBUG 8988 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : Initialize connection to node -1 for sending metadata request
2017-11-22 22:11:54.484 DEBUG 8988 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : Initiating connection to node -1 at 127.0.0.1:9093.
2017-11-22 22:11:54.485 DEBUG 8988 --- [ad | producer-1] org.apache.kafka.common.metrics.Metrics : Added sensor with name node--1.bytes-sent
2017-11-22 22:11:54.485 DEBUG 8988 --- [ad | producer-1] org.apache.kafka.common.metrics.Metrics : Added sensor with name node--1.bytes-received
2017-11-22 22:11:54.485 DEBUG 8988 --- [ad | producer-1] org.apache.kafka.common.metrics.Metrics : Added sensor with name node--1.latency
2017-11-22 22:11:54.485 DEBUG 8988 --- [ad | producer-1] o.apache.kafka.common.network.Selector : Created socket with SO_RCVBUF = 32768, SO_SNDBUF = 131072, SO_TIMEOUT = 0 to node -1
2017-11-22 22:11:54.486 DEBUG 8988 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : Completed connection to node -1. Fetching API versions.
2017-11-22 22:11:54.486 DEBUG 8988 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : Initiating API versions fetch from node -1.
2017-11-22 22:11:54.488 DEBUG 8988 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : Recorded API versions for node -1: (Produce(0): 0 to 5 [usable: 3], Fetch(1): 0 to 6 [usable: 5], Offsets(2): 0 to 2 [usable: 2], Metadata(3): 0 to 5 [usable: 4], LeaderAndIsr(4): 0 to 1 [usable: 0], StopReplica(5): 0 [usable: 0], UpdateMetadata(6): 0 to 4 [usable: 3], ControlledShutdown(7): 0 to 1 [usable: 1], OffsetCommit(8): 0 to 3 [usable: 3], OffsetFetch(9): 0 to 3 [usable: 3], FindCoordinator(10): 0 to 1 [usable: 1], JoinGroup(11): 0 to 2 [usable: 2], Heartbeat(12): 0 to 1 [usable: 1], LeaveGroup(13): 0 to 1 [usable: 1], SyncGroup(14): 0 to 1 [usable: 1], DescribeGroups(15): 0 to 1 [usable: 1], ListGroups(16): 0 to 1 [usable: 1], SaslHandshake(17): 0 to 1 [usable: 0], ApiVersions(18): 0 to 1 [usable: 1], CreateTopics(19): 0 to 2 [usable: 2], DeleteTopics(20): 0 to 1 [usable: 1], DeleteRecords(21): 0 [usable: 0], InitProducerId(22): 0 [usable: 0], OffsetForLeaderEpoch(23): 0 [usable: 0], AddPartitionsToTxn(24): 0 [usable: 0], AddOffsetsToTxn(25): 0 [usable: 0], EndTxn(26): 0 [usable: 0], WriteTxnMarkers(27): 0 [usable: 0], TxnOffsetCommit(28): 0 [usable: 0], DescribeAcls(29): 0 [usable: 0], CreateAcls(30): 0 [usable: 0], DeleteAcls(31): 0 [usable: 0], DescribeConfigs(32): 0 [usable: 0], AlterConfigs(33): 0 [usable: 0], UNKNOWN(34): 0, UNKNOWN(35): 0, UNKNOWN(36): 0, UNKNOWN(37): 0)
2017-11-22 22:11:54.489 DEBUG 8988 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : Sending metadata request (type=MetadataRequest, topics=boot.test) to node -1
2017-11-22 22:11:54.493 WARN 8988 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : Error while fetching metadata with correlation id 1 : {boot.test=LEADER_NOT_AVAILABLE}
2017-11-22 22:11:54.523 DEBUG 8988 --- [ntainer#0-0-C-1] org.apache.kafka.clients.NetworkClient : Sending metadata request (type=MetadataRequest, topics=boot.test) to node -1
2017-11-22 22:11:54.528 WARN 8988 --- [ntainer#0-0-C-1] org.apache.kafka.clients.NetworkClient : Error while fetching metadata with correlation id 5 : {boot.test=LEADER_NOT_AVAILABLE}
2017-11-22 22:11:54.593 DEBUG 8988 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : Sending metadata request (type=MetadataRequest, topics=boot.test) to node -1
2017-11-22 22:11:54.600 WARN 8988 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : Error while fetching metadata with correlation id 2 : {boot.test=LEADER_NOT_AVAILABLE}
2017-11-22 22:11:54.628 DEBUG 8988 --- [ntainer#0-0-C-1] org.apache.kafka.clients.NetworkClient : Sending metadata request (type=MetadataRequest, topics=boot.test) to node -1
2017-11-22 22:11:54.633 WARN 8988 --- [ntainer#0-0-C-1] org.apache.kafka.clients.NetworkClient : Error while fetching metadata with correlation id 6 : {boot.test=LEADER_NOT_AVAILABLE}
2017-11-22 22:11:54.700 DEBUG 8988 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : Sending metadata request (type=MetadataRequest, topics=boot.test) to node -1
2017-11-22 22:11:54.705 WARN 8988 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : Error while fetching metadata with correlation id 3 : {boot.test=LEADER_NOT_AVAILABLE}
那里有什么问题?
答案 0 :(得分:1)
尝试将localhost替换为主机的实际IP地址。 Localhost表示容器内部不同的东西。领导者不可用意味着由于某种原因它无法到达经纪人。