我有 2 个应用程序:
1 个应用程序使用ElasticMq
队列来收听消息。第二个应用程序发布有关SNS
主题的消息。
我可以订阅该主题的ElasticMq
队列。SNS
但是,当我在主题上发布时,即使订阅成功local stack
,也无法将消息发送给。elasticmq
awslocal sns list-subscriptions-by-topic --topic-arn arn:aws:sns:us-east-1:123456789012:classification-details-topic
{
"Subscriptions": [
{
"SubscriptionArn": "arn:aws:sns:us-east-1:123456789012:classification-details-topic:ea470c5a-c352-472e-9ae0-a1386044b750",
"Owner": "",
"Protocol": "sqs",
"Endpoint": "http://elasticmq-service:9324/queue/test",
"TopicArn": "arn:aws:sns:us-east-1:123456789012:classification-details-topic"
}
]
}
以下是我收到的错误消息:
awslocal sns 发布 --topic-arn arn:aws:sns:us-east-1:123456789012:classification-details-topic --message "我的消息"
调用 Publish 操作时出错 (InvalidParameter):调用 SendMessage 操作时出错 (AWS.SimpleQueueService.NonExistentQueue):AWS.SimpleQueueService.NonExistentQueue; 请参阅 SQS 文档。
我elasticmq
在本地堆栈上订阅错了吗?
我正在使用 docker-compose 文件运行 localstack
version: '2.1'
services:
localstack:
image: localstack/localstack
ports:
- "4567-4584:4567-4584"
- "${PORT_WEB_UI-8001}:${PORT_WEB_UI-8080}"
environment:
- SERVICES=${SERVICES- }
- DEBUG=${DEBUG- }
- DATA_DIR=${DATA_DIR- }
- PORT_WEB_UI=${PORT_WEB_UI- }
- LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR- }
- KINESIS_ERROR_PROBABILITY=${KINESIS_ERROR_PROBABILITY- }
- DOCKER_HOST=unix:///var/run/docker.sock
volumes:
- "${TMPDIR:-/tmp/localstack}:/tmp/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
networks:
default:
external:
name: my_network
我使用相同的 docker 网络“my_network”将 elasticmq 和其他服务作为不同 docker-compose 的一部分
以下是完整的 docker-compose。我尝试通过将条目组合到一个 docker-compose 文件中来复制它。
重现步骤
version: '3'
services:
elasticmq:
build: ./elasticmq
ports:
- '9324:9324'
networks:
- my_network
dns:
- 172.16.198.101
localstack:
image: localstack/localstack
ports:
- "4567-4584:4567-4584"
- "${PORT_WEB_UI-8001}:${PORT_WEB_UI-8080}"
environment:
- SERVICES=${SERVICES- }
- DEBUG=${DEBUG- }
- DATA_DIR=${DATA_DIR- }
- PORT_WEB_UI=${PORT_WEB_UI- }
- LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR- }
- KINESIS_ERROR_PROBABILITY=${KINESIS_ERROR_PROBABILITY- }
- DOCKER_HOST=unix:///var/run/docker.sock
volumes:
- "${TMPDIR:-/tmp/localstack}:/tmp/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
links:
- elasticmq:elasticmq-service
networks:
- my_network
dns:
- 172.16.198.101
networks:
my_network:
driver: bridge
ipam:
config:
- subnet: 172.16.198.0/24
在此之后可以运行以下一组命令
awslocal sqs create-queue --queue-name test --endpoint http://elasticmq:9324/
awslocal sns create-topic --name test-topic
awslocal sns subscribe --topic-arn arn:aws:sns:us-east-1:123456789012:test-topic --protocol sqs --notification-endpoin http://elasticmq-service:9324/queue/test