Search code examples
amazon-web-servicesamazon-sqs

AWS SQS: how to use 1 publisher->N receivers?


How to create in AWS SQS something like 'direct' exchange in RabbitMQ: 1 message -> N receivers queues.

Each client app connects to server and creates its own queue, a publisher sends one messages to exchange (direct+routing key) and its sent to all N queues, then each user reads its own queue and the queue is emptied.


Solution

  • This can be done with a 'fan-out' pattern combining Amazon SNS and Amazon SQS:

    • Create all desired Amazon SQS queues
    • Create an Amazon SNS Topic
    • Subscribe all of the Amazon SQS queues to the Amazon SNS Topic
    • Send a message to the Amazon SNS topic -- this will be sent to all subscribing queues. Each queue will have its own copy of the message.

    Make sure you use Amazon SNS raw message delivery to preserve the format of the initial message as it goes from Amazon SNS to the SQS queues.

    See also: How to Fan-Out to Different SQS Queues Using SNS Message Filtering | by Lorenz Vanthillo | Better Programming