Issue subscribing the same queue to the same topic multiple times
Using the latest Docker image:
aws-local:
image: localstack/localstack
environment:
- SERVICES=s3,sns,sqs
ports:
- "4572:4572"
- "4575:4575"
- "4576:4576"
I think I'm seeing and issue with subscribing queues to topics that doesn't match the behaviour in the actual AWS services. My test creates a queue and topic, then subscribes the queue to the topic and publishes messages to the topic. Starting with a clean restart of the localstack services (no persistence) I run my test which logs the different steps along with how many messages were received:
created queue test-queue
got queue ARN arn:aws:sqs:elasticmq:000000000000:test-queue
created topic test-topic
subscribed queue to topic
first receive 0
first published message
second receive 1
delete message
third receive 0
second published message
fourth receive 1
delete message
fifth receive 0
This all looks correct. However, if I run the same test immediately again without changing anytning or restarting localstack:
created queue test-queue
got queue ARN arn:aws:sqs:elasticmq:000000000000:test-queue
created topic test-topic
subscribed queue to topic
first receive 0
first published message
second receive 2
delete message
third receive 0
second published message
fourth receive 2
delete message
fifth receive 1
The numbers (the count of messages) should not be increasing like that. I have confirmed it's the "subscribe" that's the problem. I can restart localstack and then run the test again but this time subscribing the same queue twice to the same topic:
created queue test-queue
got queue ARN arn:aws:sqs:elasticmq:000000000000:test-queue
created topic test-topic
subscribed queue to topic
subscribed queue to topic again
first receive 0
first published message
second receive 2
delete message
third receive 0
second published message
fourth receive 2
delete message
fifth receive 1
The problem starts to manifest simply because I subscribed twice. Running the same tests against AWS, I can run it multiple times and subscribe more than once and I never see the extra messages- the results are the same as the first run above. So I figure there must be a bug in the subscription logic.
I'm running into the same problem. Run the program once, everything looks good. Run it X times, and each published message will be handled X times.
Do the same on live AWS - each message is still only handled once.