设为首页 加入收藏

TOP

Kafka 远程消费者读不到数据
2019-02-16 02:33:15 】 浏览:224
Tags:Kafka 远程 消费者 不到 数据

问题描述

服务器上使用脚本测试 producer & consumer 可生产 & 消费信息,但在使用 Java 代码远程作为消费者时,代码却卡在 comsumer.poll(long timeout) 不往下进行。

解决方式

编辑 Kafka 目录下 config/server.properties,主要是添加advertised.listeners项:

# The address the socket server listens on. It will get the value returned from 
# java.net.InetAddress.getCanonicalHostName() if not configured.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092
# 如下,经测均可使用
listeners=PLAINTEXT://:9092
# listeners = PLAINTEXT://0.0.0.0:9092
# listeners=PLAINTEXT://server1:9092
# listeners=PLAINTEXT://192.168.78.101:9092

# Hostname and port the broker will advertise to producers and consumers. If not set, 
# it uses the value for "listeners" if configured.  Otherwise, it will use the value
# returned from java.net.InetAddress.getCanonicalHostName().
#advertised.listeners=PLAINTEXT://your.host.name:9092
# 如下,经测hostname 和 ip 均可以
# advertised.listeners = PLAINTEXT://192.168.78.101:9092
advertised.listeners = PLAINTEXT://server1:9092

官方定义

listeners

Listener List - Comma-separated list of URIs we will listen on and the listener names. If the listener name is not a security protocol, listener.security.protocol.map must also be set. Specify hostname as 0.0.0.0 to bind to all interfaces. Leave hostname empty to bind to default interface. Examples of legal listener lists: PLAINTEXT://myhost:9092,SSL://:9091 CLIENT://0.0.0.0:9092,REPLICATION://localhost:9093

advertised.listeners

Listeners to publish to ZooKeeper for clients to use, if different than the listeners config property. In IaaS environments, this may need to be different from the interface to which the broker binds. If this is not set, the value for listeners will be used. Unlike listeners it is not valid to advertise the 0.0.0.0 meta-address.

待填坑,需结合源码理解

其他

1. 除 advertised.listeners 外,也可一同配置 advertised.host.nameadvertised.port,不过这两个配置项已废弃,仅在 advertised.listenerslisteners 均未设置时使用。
2. 当未配置时,默认使用java.net.InetAddress.getCanonicalHostName(),写了个小文件在服务器上直接执行得到server1,即配置过的 hostname,这样的话远程是可以连通的,但却出现了此问题。

待填坑,需结合源码理解

参考

  1. Kafka Broker Configs
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Kafka's Metadata In ZooKeep.. 下一篇kafka问题排查之 Java代码不进行..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目