Let’s checkout how to connect Symfony with Amazon SQS and SNS Services by using a Symfony component.
Github repo for this article:
This is a Symfony example how to use a AWS SQS Queue to dispatch and consume messages async. One consumption handler…
What is the Symfony Messenger?
It’s a Message-Bus that can be used for the following design patterns:
We are going to use a Command-Bus pattern that seperates the description, what needs to be done, from where it’s going to happen. It’s like getting an order in a restaurant that gets prepared in the kitchen. In our case we will create a TestMessage object, that gets send and consumed by a handler.
Setup the Symfony project:
Create a Symfony CLI skeleton:
docker run — rm -it -v $PWD:/app composer create-project symfony/skeleton symfony_messenger
Install Symfony Messenger component:
docker run --rm -it -v $PWD:/app composer require messenger
To enable the support of AWS SQS install these two packages:
docker run --rm -it -v $PWD:/app composer require sroze/messenger-enqueue-transport enqueue/sqs
Create a SQS Queue in your AWS account:
What is SQS?
- Fully managed queuing service
- Asynchronous communication and decouple processes via messages / events from a sender and receiver(producer and consumer)
- Not reactive you have to pull messages, no real-time
- Messages get deleted once they got acknowledged
- Temporary repository for messages that await to be processed
- Message size can be between 1 byte and 256 KB
- Default message retention is 4 days, 60 secs minimum…