问题描述
我有一个休息服务,在port 5000上的docker容器中运行,用于生成从docker容器运行的kafka主题消息。
I've a rest service running in docker container on port 5000 which is used to produce message over kafka topic running out of docker container.
我配置了以下属性的生产者客户: -
I've configure my producer client with below properties :-
bootstrap.servers=localhost:9093
我已经开始包含以下命令: -
And I've started my contained with below command:-
docker run -d -p 127.0.0.1:5000:5000 <contained id>
我也做了下面的配置来宣传kafka主机和端口
I've also made below configuration to advertise kafka host and port
advertised.host.name=localhost
advertised.port=9093
尽管我尝试制作一个kafka主题,但是我收到以下错误: -
Despite of having all configuration when I try to produce to a kafka topic then I get below error:-
org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.
有人可以指出实际问题的位置吗?
Can someone please point where the actual problem is?
推荐答案
在现实生活中, advertised.host.name
不应该是 localhost
。
In real life, advertised.host.name
should never be localhost
.
在您的情况下,您以桥接网络模式运行Docker容器,因此无法通过 localhost
,因为它将指向容器网络,而不是主机。
In your case, you run your Docker container in bridge networking mode, so it won't be able to reach the broker via localhost
, as it will point to the container network, not the host machine.
为了使其工作,您应该设置广告的对于
和返回的IP地址,ifconfig docker0
(.host.name bootstrap.servers
在你的情况下可能不是docker0,但是你得到了点)。
To make it work you should set the advertised.host.name
and bootstrap.servers
to the IP address returned by ifconfig docker0
(might be not docker0 in your case but you get the point).
或者,您可能运行您的容器 - net = host
,但我认为你最好正确配置广告主机名。
Alternatively, you may probably run your container with --net=host
, but I think you'd better properly configure the advertised host name.
这篇关于不能从停泊运营的服务器向kafka发出消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!