PHPackages                             bref/symfony-messenger-sqs - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. bref/symfony-messenger-sqs

Abandoned → [bref/symfony-messenger](/?search=bref%2Fsymfony-messenger)ArchivedLibrary[Queues &amp; Workers](/categories/queues)

bref/symfony-messenger-sqs
==========================

Symfony Messenger bridge to run with SQS on AWS Lambda with Bref

0.2.0(6y ago)162.9k3[1 issues](https://github.com/brefphp/symfony-messenger-sqs/issues)[1 PRs](https://github.com/brefphp/symfony-messenger-sqs/pulls)MITPHPPHP ^7.3

Since Dec 4Pushed 6y ago1 watchersCompare

[ Source](https://github.com/brefphp/symfony-messenger-sqs)[ Packagist](https://packagist.org/packages/bref/symfony-messenger-sqs)[ RSS](/packages/bref-symfony-messenger-sqs/feed)WikiDiscussions master Synced yesterday

READMEChangelog (3)Dependencies (10)Versions (4)Used By (0)

**This package is deprecated in favor of the more generic [bref/symfony-messenger](https://github.com/brefphp/symfony-messenger).**

---

Bridge to use Symfony Messenger with SQS on AWS Lambda with [Bref](https://bref.sh).

Installation
------------

[](#installation)

This guide assumes that:

- Symfony is installed
- Symfony Messenger is installed
- Bref is installed and [configured to deploy Symfony](https://bref.sh/docs/frameworks/symfony.html)
- a SQS queue has already been created

First, install this package:

```
composer require bref/symfony-messenger-sqs

```

Next, register the bundle in `config/bundles.php`:

```
return [
    ...
    Bref\Messenger\BrefMessengerBundle::class => ['all' => true],
];
```

Next, configure Symfony Messenger to dispatch a message via SQS:

```
# config/packages/messenger.yaml

framework:
    messenger:
        transports:
            async: '%env(MESSENGER_TRANSPORT_DSN)%'
        routing:
             'App\Message\MyMessage': async
```

Here, the `MyMessage` class will be dispatch to the `async` transport. We can now configure the `async` transport to use our SQS queue.

To do that, let's configure the `MESSENGER_TRANSPORT_DSN` environment variable to contain the URL of the queue:

```
MESSENGER_TRANSPORT_DSN=https://sqs.us-east-1.amazonaws.com/123456789101/my-queue
```

### Sending messages

[](#sending-messages)

Now that Messenger is configured with SQS, we can send messages using the `MessageBusInterface`. For example, in a controller:

```
class DefaultController extends AbstractController
{
    public function index()
    {
        $this->dispatchMessage(new App\Message\MyMessage());
    }
}
```

Read [the Symfony documentation to learn more](https://symfony.com/doc/current/messenger.html#dispatching-the-message).

### Processing message

[](#processing-message)

Messages are sent to SQS, we now need to process those messages asynchronously.

We can create a Lambda to do that in `serverless.yml`:

```
functions:
    worker:
        handler: consumer.php
        timeout: 120 # in seconds
        reservedConcurrency: 5 # max. 5 messages processed in parallel
        layers:
            - ${bref:layer.php-73}
        events:
            -   sqs:
                    arn: arn:aws:sqs:us-east-1:123456789101:my-queue
                    # Only 1 item at a time to simplify error handling
                    batchSize: 1
```

The Lambda handler will be `consumer.php`, a file we must create:

```
