我正在开发一个应用程序,它从 sqs 队列中读取消息,对该数据执行一些操作,然后获取结果并发布到 kafka 主题。为了在本地进行测试,我想在我的 docker 版本中设置一个 kafka 映像。我目前可以使用 docker-compose 在本地启动 aws-cli、localstack 和我的应用程序的容器。另外,我也可以毫无问题地启动 kafka 和 Zookeper。我无法让我的应用程序与 kafka 通信。
我尝试过使用两个单独的撰写文件,并且还摆弄了网络。最后,我引用了:https://rmoff.net/2018/08/02/kafka-listeners-explained/。
这是我的 docker-compose 文件:
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
我希望发布到该主题时不会出现任何错误。相反,我得到:
kafka: client has run out of available brokers to talk to (Is your cluster reachable?)
有什么想法我可能做错了吗?感谢您的帮助。
绝地无双
相关分类