dongyuan9149 2019-07-18 22:07
浏览 328

如何修复`kafka:客户端用尽了可用的代理进行对话(您的群集是否可以访问?)错误

I am developing an application which reads a message off of an sqs queue, does some stuff with that data, and takes the result and publishes to a kafka topic. In order to test locally, I'd like to set up a kafka image in my docker build. I am currently able to spin up aws-cli, localstack, and my app's containers locally using docker-compose. Separately, I am able to spin up kafka and zookeper without a problem as well. I am unable to get my application to communicate with kafka.

I've tried using two separate compose files, and also fiddled with the networks. Finally, I've referenced: https://rmoff.net/2018/08/02/kafka-listeners-explained/.

Here is my docker-compose file:

version: '3.7'
services:
  localstack:
    image: localstack/localstack:latest
    container_name: localstack
    env_file: .env
    ports:
      # Localstack endpoints for various API. Format is localhost:container
      - '4563-4584:4563-4584'
      - '8080:8080'
    environment:
      - SERVICES=sns:4575,sqs:4576
      - DATA_DIR=/tmp/localstack/data
    volumes:
      # store data locally in 'localstack' folder
      - './localstack:/tmp/localstack'
    networks:
      - my_network

  aws:
    image: mesosphere/aws-cli
    container_name: aws-cli
    # copy local JSON_DATA folder contents into aws-cli container's app folder
    #volumes:
    #  - ./JSON_DATA:/app
    env_file: .env
    # bash entrypoint needed for multiple commands
    entrypoint: /bin/sh -c
    command: >
      " sleep 10;
        aws --endpoint-url=http://localstack:4576 sqs create-queue --queue-name input_queue;
        aws --endpoint-url=http://localstack:4575 sns create-topic --name input_topic;
        aws --endpoint-url=http://localstack:4575 sns subscribe --topic-arn arn:aws:sns:us-east-2:123456789012:example_topic --protocol sqs --notification-endpoint http://localhost:4576/queue/input_queue; "
    networks:
      - my_network
    depends_on:
      - localstack

  my_app:
    build: .
    image: my_app
    container_name: my_app
    env_file: .env
    ports:
      - '9000:9000'
    networks:
      - my_network
    depends_on:
      - localstack
      - aws

  zookeeper:
    image: confluentinc/cp-zookeeper:5.0.0
    container_name: zookeeper
    ports:
      - 2181:2181
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
    networks:
      - my_network

  kafka:
    image: confluentinc/cp-kafka:5.0.0
    ports:
      - 9092:9092
    depends_on:
      - zookeeper
    environment:
      # For more details see See https://rmoff.net/2018/08/02/kafka-listeners-explained/
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_ADVERTISED_LISTENERS: INSIDE://localhost:9092
      KAFKA_LISTENERS: INSIDE://localhost:9092
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT
      KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE
      KAFKA_CREATE_TOPICS: "output_topic:2:2"
    networks:
      - my_network

networks:
  my_network:

I would hope to see no errors as a result of publishing to this topic. Instead, I'm getting:

kafka: client has run out of available brokers to talk to (Is your cluster reachable?)

Any ideas what I may be doing wrong? Thank you for your help.

  • 写回答

1条回答 默认 最新

  • duanleixun2439 2019-09-10 19:51
    关注

    You've made the broker only resolvable within the Kafka container itself (or from your host to the container) by setting the listeners only to localhost.

    If you want another Docker service to be able to reach that container, you'll have to add <some protocol>://kafka:<some port> to the advertised listeners, and make the listeners as not localhost

    Where the protocol is also added to KAFKA_LISTENER_SECURITY_PROTOCOL_MAP

    FWIW, That blog should cover all those bases.

    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献