无法从 docker 中运行的服务向 kafka 生成消息 [英] Cannot produce message to kafka from service running in docker

查看:25
本文介绍了无法从 docker 中运行的服务向 kafka 生成消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在端口 5000 上的 docker 容器中运行了一个 rest 服务,该服务用于通过 kafka 主题生成消息,该主题用完 docker 容器.

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.

要使其工作,您应该将 advertised.host.namebootstrap.servers 设置为 ifconfig docker0 返回的 IP 地址(在您的情况下可能不是 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.

这篇关于无法从 docker 中运行的服务向 kafka 生成消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆