无法从外部机器连接到 kafka [英] cant connect to kafka from external machine

查看:30
本文介绍了无法从外部机器连接到 kafka的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 Apache Kafka 开始,当我尝试从外部机器连接时遇到问题.

I´m starting with Apache Kafka and i´m facing problems when i try to conect from an external machine.

使用下面的配置,如果应用程序和 docker 在同一台机器上运行,一切正常.

With this configuration bellow, all works fine if the application and the docker are running at the same machine.

但是当我把应用程序放在机器 A 和机器 B 的 docker 上时,应用程序无法连接.

but when i put the application in machine A and docker at machine B, the application cant connect.

我的 spring Kafka @Configuration 有这条线到 @Bean consumerFactory 和 producerFactory(想象一下我的机器的 docker ip = 10.10.10.10)

My spring Kafka @Configuration have this line to @Bean consumerFactory and producerFactory (imagine my machine with docker ip = 10.10.10.10)

props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "10.10.10.10:9092");

我的 docker 文件是这样的:

And my docker file is this:

version: '2'
services:
zookeeper:
    image: wurstmeister/zookeeper:3.4.6
    ports:
      - 2181:2181
kafka:
    image: wurstmeister/kafka:0.10.1.1
    environment:
        KAFKA_ADVERTISED_HOST_NAME: 0.0.0.0
        KAFKA_ADVERTISED_PORT: 9092
        KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
        KAFKA_CREATE_TOPICS: "topic-jhipster:1:1,PROCESS_ORDER:1:1, PROCESS_CHANNEL:1:1"
        JMX_PORT: 9999
        KAFKA_JMX_OPTS: "-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.rmi.port=9999"
    ports:
        - 9092:9092
        - 9999:9999
kafka-manager:
    image: sheepkiller/kafka-manager
    ports:
        - 9000:9000
    links:
        - zookeeper
    environment:
        ZK_HOSTS: zookeeper:2181

我收到此错误:

org.springframework.kafka.core.KafkaProducerException: Failed to send;
nested exception is org.apache.kafka.common.errors.TimeoutException: 
Expiring 1 record(s) for

编辑,添加一些信息..

Edit, add some information..

我认为它有关我缺少的zookeeper的任何配置..因为如果我只有zookeeper在我的机器A上启动..和机器B中的kafka..有效..我只是不知道如何:(

I think its any configuration about the zookeeper i´m missing .. because if i have only the zookeeper started at my machine A .. and the kafka in machine B.. that works.. i only don´t know how :(

推荐答案

@Krishas 和 @Hans Jespersen 的一些混合

Some mix of @Krishas and @Hans Jespersen

这是我的 docker yml 的代码:

Here is the code of my docker yml:

version: '2'
services:
    zookeeper:
        image: wurstmeister/zookeeper:3.4.6
        ports:
          - 2181:2181
    kafka:
        image: wurstmeister/kafka:0.10.1.1
        environment:
            KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://10.10.10.10:9092
            KAFKA_ADVERTISED_HOST_NAME: 10.10.10.10
            KAFKA_ADVERTISED_PORT: 9092
            KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181

那需要PLAINTEXT://前缀!并配置host_name"+port",或listeners"

That needs the "PLAINTEXT:// prefix ! And config the "host_name" + "port", or "listeners"

下一步是发现我将如何配置另一个节点

这篇关于无法从外部机器连接到 kafka的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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