Bridge to use Symfony Messenger on AWS Lambda with Bref

Overview

Bridge to use Symfony Messenger on AWS Lambda with Bref.

This bridge allows messages to be dispatched to SQS, SNS or EventBridge, while workers handle those messages on AWS Lambda.

Installation

This guide assumes that:

First, install this package:

composer require bref/symfony-messenger

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

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

SQS, SNS and EventBridge can now be used with Symfony Messenger.

Usage

Symfony Messenger dispatches messages. To create a message, follow the Symfony Messenger documentation.

To configure where messages are dispatched, all the examples in this documentation are based on the example from the Symfony documentation:

# config/packages/messenger.yaml

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

SQS

The SQS service is a queue that works similar to RabbitMQ. To use it, set its URL in the environment variable MESSENGER_TRANSPORT_DSN:

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

That's it, messages will be dispatched to that queue.

The implementation uses the SQS transport provided by Symfony Amazon SQS Messenger, so all those features are supported. If you already use that transport, the transition to AWS Lamdba is very easy and should not require any change for dispatching messages.

Create the SQS queue

You can create the Queue yourself in the Console, write custom Cloudformation or use Lift's Queue construct that will handle that for you.

Here is a simple example with Lift, make sure to install the plugin first and check out the full documentation for more details.

# serverless.yml

service: my-app
provider:
    name: aws
    environment:
        ...
        MESSENGER_TRANSPORT_DSN: ${construct:jobs.queueUrl}

constructs:
    jobs:
        type: queue
        worker:
            handler: bin/consumer.php
            timeout: 20 # in seconds
            reservedConcurrency: 5 # max. 5 messages processed in parallel
            layers:
                - ${bref:layer.php-80}

plugins:
    - serverless-lift

In all cases, you would want to disable auto_setup to avoid extra requests and permission issues.

# config/packages/messenger.yaml

framework:
    messenger:
        transports:
            async: 
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
                options:
                    auto_setup: false

Add permissions

When running Symfony on AWS Lambda, it is not necessary to configure credentials. The AWS client will read them from environment variables automatically.

You just have to provide the correct role statements in serverless.yml and Lambda will take care of the rest. The required IAM permission to publish to SQS using Messenger is sqs:SendMessage on the given queue.

If you use Lift, this is done automatically for you.

Consume messages from SQS

  1. If you don't use Lift, create the function that will be invoked by SQS in serverless.yml:
functions:
    worker:
        handler: bin/consumer.php
        timeout: 20 # in seconds
        reservedConcurrency: 5 # max. 5 messages processed in parallel
        layers:
            - ${bref:layer.php-80}
        events:
            # Read more at https://www.serverless.com/framework/docs/providers/aws/events/sqs/
            - sqs:
                arn: arn:aws:sqs:us-east-1:1234567890:my_sqs_queue
                # Only 1 item at a time to simplify error handling
                batchSize: 1
  1. Create the handler script (for example bin/consumer.php):
<?php declare(strict_types=1);

use Bref\Symfony\Messenger\Service\Sqs\SqsConsumer;

require dirname(__DIR__) . '/config/bootstrap.php';

$kernel = new \App\Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$kernel->boot();

// Return the Bref consumer service
return $kernel->getContainer()->get(SqsConsumer::class);

If you are using Symfony 5.1, use this instead:

<?php declare(strict_types=1);

use Bref\Symfony\Messenger\Service\Sqs\SqsConsumer;
use Symfony\Component\Dotenv\Dotenv;

require dirname(__DIR__).'/vendor/autoload.php';

(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');

$kernel = new \App\Kernel($_SERVER['APP_ENV'], (bool)$_SERVER['APP_DEBUG']);
$kernel->boot();

// Return the Bref consumer service
return $kernel->getContainer()->get(SqsConsumer::class);
  1. Register and configure the SqsConsumer service:
# config/services.yaml
services:
    Bref\Symfony\Messenger\Service\Sqs\SqsConsumer:
        public: true
        autowire: true
        arguments:
            # Pass the transport name used in config/packages/messenger.yaml
            $transportName: 'async'

Now, anytime a message is dispatched to SQS, the Lambda function will be called. The Bref consumer class will put back the message into Symfony Messenger to be processed.

FIFO Queue

The FIFO queue guarantees exactly once delivery, and has a mandatory queue name suffix .fifo:

# config/packages/messenger.yaml

framework:
    messenger:
        transports:
            async: 
                dsn: 'https://sqs.us-east-1.amazonaws.com/123456789/my-queue.fifo'
# serverless.yml
resources:
    Resources:
        Queue:
            Type: AWS::SQS::Queue
            Properties:
                QueueName: my-queue.fifo
                FifoQueue: true

Symfony Amazon SQS Messenger will automatically calculate/set the MessageGroupId and MessageDeduplicationId parameters required for FIFO queues, but you can set them explicitly:

use Symfony\Component\Messenger\MessageBus;
use Symfony\Component\Messenger\Bridge\AmazonSqs\Transport\AmazonSqsFifoStamp;

/* @var MessageBus $messageBus */
$messageBus->dispatch(new MyAsyncMessage(), [new AmazonSqsFifoStamp('my-group-message-id', 'my-deduplication-id')]);

Everything else is identical to the normal SQS queue.

SNS

AWS SNS is "notification" instead of "queues". Messages may not arrive in the same order as sent, and they might arrive all at once. To use it, create a SNS topic and set it as the DSN:

MESSENGER_TRANSPORT_DSN=sns://arn:aws:sns:us-east-1:1234567890:foobar

That's it, messages will be dispatched to that topic.

Note: when running Symfony on AWS Lambda, it is not necessary to configure credentials. The AWS client will read them from environment variables automatically.

To consume messages from SNS:

  1. Create the function that will be invoked by SNS in serverless.yml:
functions:
    worker:
        handler: bin/consumer.php
        timeout: 20 # in seconds
        reservedConcurrency: 5 # max. 5 messages processed in parallel
        layers:
            - ${bref:layer.php-80}
        events:
            # Read more at https://www.serverless.com/framework/docs/providers/aws/events/sns/
            - sns:
                arn: arn:aws:sns:us-east-1:1234567890:my_sns_topic
  1. Create the handler script (for example bin/consumer.php):
<?php declare(strict_types=1);

use Bref\Symfony\Messenger\Service\Sns\SnsConsumer;

require dirname(__DIR__) . '/config/bootstrap.php';

$kernel = new \App\Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$kernel->boot();

// Return the Bref consumer service
return $kernel->getContainer()->get(SnsConsumer::class);
  1. Register and configure the SnsConsumer service:
# config/services.yaml
services:
    Bref\Symfony\Messenger\Service\Sns\SnsConsumer:
        public: true
        autowire: true
        arguments:
            # Pass the transport name used in config/packages/messenger.yaml
            $transportName: 'async'

Now, anytime a message is dispatched to SNS, the Lambda function will be called. The Bref consumer class will put back the message into Symfony Messenger to be processed.

EventBridge

AWS EventBridge is a message routing service. It is similar to SNS, but more powerful. To use it, configure the DSN like so:

# "myapp" is the EventBridge "source", i.e. a namespace for your application's messages
# This source name will be reused in `serverless.yml` later.
MESSENGER_TRANSPORT_DSN=eventbridge://myapp

Optionally you can add set the EventBusName via a event_bus_name query parameter, either the name or the ARN:

MESSENGER_TRANSPORT_DSN=eventbridge://myapp?event_bus_name=custom-bus
MESSENGER_TRANSPORT_DSN=eventbridge://myapp?event_bus_name=arn:aws:events:us-east-1:123456780912:event-bus/custom-bus

That's it, messages will be dispatched to EventBridge.

Note: when running Symfony on AWS Lambda, it is not necessary to configure credentials. The AWS client will read them from environment variables automatically.

To consume messages from EventBridge:

  1. Create the function that will be invoked by EventBridge in serverless.yml:
functions:
    worker:
        handler: bin/consumer.php
        timeout: 20 # in seconds
        reservedConcurrency: 5 # max. 5 messages processed in parallel
        layers:
            - ${bref:layer.php-80}
        events:
            # Read more at https://www.serverless.com/framework/docs/providers/aws/events/event-bridge/
            -   eventBridge:
                    # This filters events we listen to: only events from the "myapp" source.
                    # This should be the same source defined in config/packages/messenger.yaml
                    pattern:
                        source:
                            - myapp
  1. Create the handler script (for example bin/consumer.php):
<?php declare(strict_types=1);

use Bref\Symfony\Messenger\Service\EventBridge\EventBridgeConsumer;

require dirname(__DIR__) . '/config/bootstrap.php';

$kernel = new \App\Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$kernel->boot();

// Return the Bref consumer service
return $kernel->getContainer()->get(EventBridgeConsumer::class);
  1. Register and configure the EventBridgeConsumer service:
# config/services.yaml
services:
    Bref\Symfony\Messenger\Service\EventBridge\EventBridgeConsumer:
        public: true
        autowire: true
        arguments:
            # Pass the transport name used in config/packages/messenger.yaml
            $transportName: 'async'

Now, anytime a message is dispatched to EventBridge for that source, the Lambda function will be called. The Bref consumer class will put back the message into Symfony Messenger to be processed.

Error handling

AWS Lambda has error handling mechanisms (retrying and handling failed messages). Because of that, this package does not integrates Symfony Messenger's retry mechanism. Instead, it works with Lambda's retry mechanism.

This section is work in progress, feel free to contribute to improve it.

When a message fails with SQS, by default it will go back to the SQS queue. It will be retried until the message expires. Here is an example to setup retries and "dead letter queue" with SQS:

# serverless.yml
resources:
    Resources:
        Queue:
            Type: AWS::SQS::Queue
            Properties:
                # This needs to be at least 6 times the lambda function's timeout
                # See https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html
                VisibilityTimeout: '960'
                RedrivePolicy:
                    deadLetterTargetArn: !GetAtt DeadLetterQueue.Arn
                    # Jobs will be retried 5 times
                    # The number needs to be at least 5 per https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html
                    maxReceiveCount: 5
        # The dead letter queue is a SQS queue that receives messages that failed to be processed
        DeadLetterQueue:
            Type: AWS::SQS::Queue
            Properties:
                # Messages are stored up to 14 days (the max)
                MessageRetentionPeriod: 1209600

When using SNS and EventBridge, messages will be retried by default 2 times.

Configuration

Configuring AWS clients

By default, AWS clients (SQS, SNS, EventBridge) are preconfigured to work on AWS Lambda (thanks to environment variables populated by AWS Lambda).

However, it is possible customize the AWS clients, for example to use them outside of AWS Lambda (locally, on EC2…) or to mock them in tests. These clients are registered as Symfony services under the keys:

  • bref.messenger.sqs_client
  • bref.messenger.sns_client
  • bref.messenger.eventbridge_client

For example to customize the SQS client:

services:
    bref.messenger.sqs_client:
        class: AsyncAws\Sqs\SqsClient
        public: true # the AWS clients must be public
        arguments:
            # Apply your own config here
            -
                region: us-east-1

Disabling transports

By default, this package registers Symfony Messenger transports for SQS, SNS and EventBridge.

If you want to disable some transports (for example in case of conflict), you can remove BrefMessengerBundle from config/bundles.php and reconfigure the transports you want in your application's config. Take a look at Resources/config/services.yaml to copy the part that you want.

Customizing the serializer

If you want to change how messages are serialized, for example to use Happyr message serializer, you need to add the serializer on both the transport and the consumer. For example:

# config/packages/messenger.yaml
framework:
    messenger:
        transports:
            async: 
                dsn: 'https://sqs.us-east-1.amazonaws.com/123456789/my-queue'
                serializer: 'Happyr\MessageSerializer\Serializer'

# config/services.yaml
services:
    Bref\Symfony\Messenger\Service\Sqs\SqsConsumer:
        public: true
        autowire: true
        arguments:
            $transportName: 'async'
            $serializer: '@Happyr\MessageSerializer\Serializer'
Comments
  • Support partial batch failure

    Support partial batch failure

    This allows the Symfony Messenger integration to benefit from "partial batch failures" with SQS.

    This is done via a new argument in the service declaration (and proper SQS config ofc).

    Bref\Symfony\Messenger\Service\Sqs\SqsConsumer:
            public: true
            autowire: true
            arguments:
                # Pass the transport name used in config/packages/messenger.yaml
                $transportName: 'async'
    +           $partialBatchFailure: true
    
    If you want to try this, in `composer.json`
    {
        "require": {
            ...
            "bref/symfony-messenger": "dev-partial"
        },
        "repositories": [
            {
                "type": "vcs",
                "url": "https://github.com/t-richard/symfony-messenger"
            }
        ]
    }
    

    Closes #57

    opened by t-richard 11
  • Sending message to a custom event bus

    Sending message to a custom event bus

    Looking through EventBridgeTransport.php it appears it does not allow you to send events to a custom event bus.
    [ 'Detail' => json_encode($encodedMessage, JSON_THROW_ON_ERROR), // Ideally here we could put the class name of the message, but how to retrieve it? 'DetailType' => 'Symfony Messenger message', 'Source' => $this->source, ]

    Is this the case...or am I missing something.

    opened by kodjobaah 11
  • Replace Sqs implementation with symfony/amazon-sqs-messenger

    Replace Sqs implementation with symfony/amazon-sqs-messenger

    Fixes #29, replaces #31 (because it was easier to apply the changes again, instead of handling merge conflicts)

    I have some questions, see my comments below. Also, the build failed, what do I need to fix?

    opened by starred-gijs 11
  • Message handler does not seem to be working

    Message handler does not seem to be working

    Hi,

    Thanks for this package and the brefphp bundle in general, it's magical !

    I do have an issue to make the consumer work on my lambda though.

    My setup works fine when using the doctrine queue, but when I switch in order to use the SQS queue, the message is sent to the SQS and then the lambda seems to 'consume' the message, based on the logs, but my process (sending a message) is not happening.

    I tried debugging my MessageHandler using var_dump and the Psr\Logger but nothing is being logged.

    All I know is that the lambda run for about ~6s each time but nothing more :/

    I checked the lambda timeout (15min), vpc, env varibales and the sqs config but I can't seem to find why it's not working.

    An interesting fact is that one of my other message type is working when using the same sqs + lambda.

    Any idea what I could be missing ?

    Thanks in advance for your help, Julien Pessey

    P.S : I did not know what config file to include (I basically followed the doc) so please feel free to ask me for any !

    opened by pesseyjulien 8
  • Invoke error

    Invoke error

    With a setup using a function to use SNS, I am getting the following error:

    {
        "errorType": "Symfony\\Component\\Messenger\\Exception\\MessageDecodingFailedException",
        "errorMessage": "Could not decode message using PHP serialization: {\"notificationType\":\"Bounce\",\"bounce\":{\"feedbackId\":\"01070177b7c56aa1-117088ce-e70c-42c6-9120-42aacdde7907-000000\",\"bounceType\":\"Permanent\",\"bounceSubType\":\"General\",\"bouncedRecipients\":[{\"emailAddress\":\"[email protected]\",\"action\":\"failed\",\"status\":\"5.1.1\",\"diagnosticCode\":\"smtp; 550 5.1.1 user unknown\"}],\"timestamp\":\"2021-02-19T00:51:44.000Z\",\"remoteMtaIp\":\"3.226.40.239\",\"reportingMTA\":\"dsn; b224-13.smtp-out.eu-central-1.amazonses.com\"},\"mail\":{\"timestamp\":\"2021-02-19T00:51:42.822Z\",\"source\":\"[email protected]\",\"sourceArn\":\"arn:aws:ses:eu-central-1:544387708820:identity/[email protected]\",\"sourceIp\":\"178.132.211.234\",\"sendingAccountId\":\"544387708820\",\"messageId\":\"01070177b7c56466-279ebebc-6da2-4a1c-af23-b78eac23a6da-000000\",\"destination\":[\"[email protected]\"]}}.",
        "stack": [
            "#0 /var/task/vendor/symfony/messenger/Transport/Serialization/PhpSerializer.php(38): Symfony\\Component\\Messenger\\Transport\\Serialization\\PhpSerializer->safelyUnserialize()",
            "#1 /var/task/vendor/bref/symfony-messenger/src/Service/Sns/SnsConsumer.php(40): Symfony\\Component\\Messenger\\Transport\\Serialization\\PhpSerializer->decode()",
            "#2 /var/task/vendor/bref/bref/src/Event/Sns/SnsHandler.php(18): Bref\\Symfony\\Messenger\\Service\\Sns\\SnsConsumer->handleSns()",
            "#3 /var/task/vendor/bref/bref/src/Runtime/Invoker.php(29): Bref\\Event\\Sns\\SnsHandler->handle()",
            "#4 /var/task/vendor/bref/bref/src/Runtime/LambdaRuntime.php(102): Bref\\Runtime\\Invoker->invoke()",
            "#5 /opt/bref/bootstrap.php(43): Bref\\Runtime\\LambdaRuntime->processNextEvent()",
            "#6 {main}"
        ]
    }
    

    Any clue of what I'm doing wrong?

    Here's some more information about the application:

    config/packages/messenger.yaml:

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

    src/Message/SesMessage.php

    <?php
    namespace App\Message;
    
    class SesMessage
    {
        private $content;
    
        public function __construct(string $content)
        {
            $this->content = $content;
        }
    
        public function getContent(): string
        {
            return $this->content;
        }
    }
    

    src/MessageHandler/SesNotificationHandler.php

    <?php
    
    namespace App\MessageHandler;
    
    use App\Message\SesMessage;
    use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
    
    class SesNotificationHandler implements MessageHandlerInterface
    {
        public function __invoke(SesMessage $message)
        {
    
        }
    }
    

    bin/consumer.php

    <?php declare(strict_types=1);
    
    use App\Kernel;
    use Bref\Symfony\Messenger\Service\Sns\SnsConsumer;
    use Symfony\Component\Dotenv\Dotenv;
    
    require dirname(__DIR__) . '/vendor/autoload.php';
    
    (new Dotenv())->bootEnv(dirname(__DIR__) . '/.env');
    
    $kernel = new Kernel($_SERVER['APP_ENV'], (bool)$_SERVER['APP_DEBUG']);
    $kernel->boot();
    
    // Return the Bref consumer service
    return $kernel->getContainer()->get(SnsConsumer::class);
    

    serverless.yml

    ...
    
    functions:
      worker:
        handler: bin/consumer.php
        timeout: 20
        reservedConcurrency: 5 
        layers:
          - ${bref:layer.php-74}
        events:
          - sns:
              arn: arn:aws:sns:eu-central-1:1234567890:Test
    
    question 
    opened by JKetelaar 8
  • SQS queue : Connection setup error

    SQS queue : Connection setup error

    Hi ! :hand:

    I'm trying to use SQS queue and I keep getting the same error :

    I'm using API platform based on symfony then i'm using bref configuration for symfony.

    The Amazon SQS queue "heroad-sqs-dev-Queue-10KLY4X240HKO" does not exists (or you don't have permissions on it), and can't be created when an account is provided.'

    To explain what i want to do :

    I have my main app ' web ' wich is an API i want to call a SQS queue to do a long task because the 29 second timeout is not suffisent for my task.

    What i'm expecting is when i call my API from this special endpoint my worker will do the job in background without that 29 second timeout and sending me a notification when the task is finished.

    here is my simple configuration in my serverless.yml :

    provider:
        name: aws
        region: eu-west-3
        runtime: provided.al2
        environment:
            APP_ENV: stagging
            
    resources:
        Resources:
            Queue:
                Type: AWS::SQS::Queue
                Properties:
                    # This needs to be at least 6 times the lambda function's timeout
                    # See https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html
                    VisibilityTimeout: '960'
                    RedrivePolicy:
                        deadLetterTargetArn: !GetAtt DeadLetterQueue.Arn
                        # Jobs will be retried 5 times
                        # The number needs to be at least 5 per https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html
                        maxReceiveCount: 5
            # The dead letter queue is a SQS queue that receives messages that failed to be processed
            DeadLetterQueue:
                Type: AWS::SQS::Queue
                Properties:
                    # Messages are stored up to 14 days (the max)
                    MessageRetentionPeriod: 1209600
    
    plugins:
        - ./vendor/bref/bref
    
    package:
        exclude:
            - node_modules/**
            - tests/**
            - var/**
            - public/build/**'
                
    functions:
        # This function runs the Symfony website/API
        web:
            handler: public/index.php
            timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds)
            layers:
                - ${bref:layer.php-74-fpm}
            events:
                -   httpApi: '*'
    
        worker:
            handler: bin/consumer.php
            timeout: 20 # in seconds
            reservedConcurrency: 5 # max. 5 messages processed in parallel
            layers:
                - ${bref:layer.php-74}
            events:
                # Read more at https://www.serverless.com/framework/docs/providers/aws/events/sqs/
                - sqs:
                      arn: arn:aws:sqs:eu-west-3:508623790554:heroad-sqs-dev-Queue-10KLY4X240HKO
                      # Only 1 item at a time to simplify error handling
                      batchSize: 1
    
    

    I'm using the same worker for symfony 5.1 because I'm on 5.3

    My messenger.yaml :

    framework:
        messenger:
            transports:
                async: '%env(MESSENGER_TRANSPORT_DSN)%'
            routing:
                # async is whatever name you gave your transport above
                'App\Message\GeneratePlanning': async
    
    

    in my .env.stagging I've

    MESSENGER_TRANSPORT_DSN=https://sqs.eu-west-3.amazonaws.com/508623790554/heroad-sqs-dev-Queue-10KLY4X240HKO

    And finaly my bus dispatch in an API endpoint controller

        /**
         * @Route("/generate", methods={"GET"})
         * @return JsonResponse|Response
         * @throws \Exception
         */
        public function generate(MessageBusInterface $bus)
        {
            $bus->dispatch(new GeneratePlanning('hello world'));
    
            return new JsonResponse(['success' => 'success'], 201);
    
        }
    
    

    First break at : vendor/symfony/amazon-sqs-messenger/Transport/Connection.php (line 276)

    opened by Aikoze 7
  • Switching from 0.2 to 0.3.1 handle a

    Switching from 0.2 to 0.3.1 handle a "Access to the resource https://sqs.eu-west-3.amazonaws.com"

    Hi all,

    Thx all for the job you do.

    I got a problem by using the bref/symfony-messenger on version 0.3.1, i got this return :

    "HTTP 403 returned for \u0022https://sqs.eu-west-3.amazonaws.com/\u0022."

    I solved this problem by using the 0.2.0 version.

    Any idea why i got this error ? Something to change in configuration ?

    Didn't see anything in changlog ;)

    Thx for advance.

    opened by christophe-mailfert 6
  • Use symfony/amazon-sqs-messenger Transport for sending messages

    Use symfony/amazon-sqs-messenger Transport for sending messages

    I was wondering if it is an idea now symfony/amazon-sqs-messenger is released, to use the Transport from that package so this package handles only the serverless consumer side? Does that make sense?

    I doesn't seem right to keep that functionality in 2 places?

    opened by tomcoonen 6
  • Implement partial failure on SqsConsumer

    Implement partial failure on SqsConsumer

    Since brefphp has now support for partial batch failure, (https://github.com/brefphp/bref/pull/1113) I was pretty confident to implement it into the SqsConsumer.

    Except I'm not sure about the behavior we want.

    Decorates the whole loop iteration of SqsConsumer with a try cach and markAsFailed $record in catch block looks a good idea at the first glance. But doing this will prevent to reach the stopfailure method that currently log the exception. So it will lead to losing this log.

    I'm available to make the implementation but if anyone comes with a better idea how handle it, it would be great.

    opened by tyx 4
  • Not found bootstrap.php file

    Not found bootstrap.php file

    In the document says consumer.php has this require require dirname(__DIR__) . '/config/bootstrap.php';

    But I can't find bootstrap.php file in config folder.

    question 
    opened by henryonsoftware 4
  • Replace Sqs implementation with symfony/amazon-sqs-messenger.

    Replace Sqs implementation with symfony/amazon-sqs-messenger.

    Fixes #29

    Some observations:

    • the dsn must start with sqs://
    • If using the Symfony Serializer, you need this fix (scheduled for symfony/amazon-sqs-messenger next release) see #31
    opened by starred-gijs 4
  • Road to 1.0

    Road to 1.0

    The package is stable now, for 1.0 let's cleanup the docs and focus the package on 1 main way:

    • SQS and Lift by default
    • document alternative approaches (e.g. EventBridge, SNS…), possibly in separate pages

    Could we cleanup options and enable a few things by default too? (like partial batch failures)

    Also might be worth exploring possibilities of respecting Symfony Messenger features (like retries) instead of relying on SQS retry config?

    opened by mnapoli 0
  • Using with Monolog results in no mail?

    Using with Monolog results in no mail?

    Maybe some of you already know this "issue". I'm wondering why I got no error message of the messenger worker. But in the log of CloudWatch I can see all of this.

    My monolog.yaml looks like:

    monolog:
        handlers:
            main:
                type: fingers_crossed
                action_level: error
                handler: grouped
                excluded_http_codes: [404, 405, 409]
                buffer_size: 50
            grouped:
                type:    group
                members: [nested, deduplicated]
            deduplicated:
                type:    deduplication
                handler: swift
            swift:
                type:       swift_mailer
                from_email: '[email protected]'
                to_email:   ['[email protected]']
                subject:    'Error! %%message%%'
                level:      debug
                formatter:  monolog.formatter.html
                content_type: text/html
            nested:
                type: stream
                path: "php://stderr"
                level: debug
            console:
                type: console
                process_psr_3_messages: false
                channels: ["!event", "!doctrine"]
    

    And the exception is:

    {
        "errorType": "Symfony\\Component\\Messenger\\Exception\\HandlerFailedException",
        "errorMessage": "Handling \"App\\Message\\PaymentCapturedMessage\" failed: Call to undefined method",
        "stack": [
            "#0 /var/task/vendor/symfony/messenger/Middleware/SendMessageMiddleware.php(74): Symfony\\Component\\Messenger\\Middleware\\HandleMessageMiddleware->handle()",
            "#1 /var/task/vendor/symfony/messenger/Middleware/FailedMessageProcessingMiddleware.php(34): Symfony\\Component\\Messenger\\Middleware\\SendMessageMiddleware->handle()",
            "#2 /var/task/vendor/symfony/messenger/Middleware/DispatchAfterCurrentBusMiddleware.php(68): Symfony\\Component\\Messenger\\Middleware\\FailedMessageProcessingMiddleware->handle()",
            "#3 /var/task/vendor/symfony/messenger/Middleware/RejectRedeliveredMessageMiddleware.php(48): Symfony\\Component\\Messenger\\Middleware\\DispatchAfterCurrentBusMiddleware->handle()",
            "#4 /var/task/vendor/symfony/messenger/Middleware/AddBusNameStampMiddleware.php(37): Symfony\\Component\\Messenger\\Middleware\\RejectRedeliveredMessageMiddleware->handle()",
            "#5 /var/task/vendor/symfony/messenger/MessageBus.php(77): Symfony\\Component\\Messenger\\Middleware\\AddBusNameStampMiddleware->handle()",
            "#6 /var/task/vendor/bref/symfony-messenger/src/Service/SimpleBusDriver.php(24): Symfony\\Component\\Messenger\\MessageBus->dispatch()",
            "#7 /var/task/vendor/bref/symfony-messenger/src/Service/Sqs/SqsConsumer.php(58): Bref\\Symfony\\Messenger\\Service\\SimpleBusDriver->putEnvelopeOnBus()",
            "#8 /var/task/vendor/bref/bref/src/Event/Sqs/SqsHandler.php(24): Bref\\Symfony\\Messenger\\Service\\Sqs\\SqsConsumer->handleSqs()",
            "#9 /var/task/vendor/bref/bref/src/Runtime/Invoker.php(29): Bref\\Event\\Sqs\\SqsHandler->handle()",
            "#10 /var/task/vendor/bref/bref/src/Runtime/LambdaRuntime.php(91): Bref\\Runtime\\Invoker->invoke()",
            "#11 /opt/bref/bootstrap.php(43): Bref\\Runtime\\LambdaRuntime->processNextEvent()",
            "#12 {main}"
        ]
    }
    
    opened by patrickbussmann 0
  • Allow to stop retrying an SQS message

    Allow to stop retrying an SQS message

    Hey there,

    By browsing the code source around the SqsConsumer and the SqsTransport I could not find a way to "cancel" an event (delete it or send it to a dead letter queue).

    Symfony messenger allow to throw an UnrecoverableMessageHandlingException exception to stop to stop retrying a message. It could be nice to have this behaviour implemented in the bref SQS bridge.

    What did you think?

    opened by armandabric 7
Releases(0.5.2)
  • 0.5.2(Dec 23, 2022)

    What's Changed

    • Update doc for SF 5.1+ & add EventBridge config informations by @jdalmas in https://github.com/brefphp/symfony-messenger/pull/69
    • allow bref v2 and run tests with newer php versions by @smoench in https://github.com/brefphp/symfony-messenger/pull/70

    New Contributors

    • @jdalmas made their first contribution in https://github.com/brefphp/symfony-messenger/pull/69
    • @smoench made their first contribution in https://github.com/brefphp/symfony-messenger/pull/70

    Full Changelog: https://github.com/brefphp/symfony-messenger/compare/0.5.1...0.5.2

    Source code(tar.gz)
    Source code(zip)
  • 0.5.1(Oct 27, 2022)

    What's Changed

    • fix partial batch failure on fifo queue by @tyx in https://github.com/brefphp/symfony-messenger/pull/68

    New Contributors

    • @tyx made their first contribution in https://github.com/brefphp/symfony-messenger/pull/68

    Full Changelog: https://github.com/brefphp/symfony-messenger/compare/0.5.0...0.5.1

    Source code(tar.gz)
    Source code(zip)
  • 0.5.0(Aug 30, 2022)

    This release brings the support for Partial Batch Failure inside the Symfony Messenger bridge :tada:

    To enable it, there's two easy steps:

    1. Change your SqsConsumer service definition
    Bref\Symfony\Messenger\Service\Sqs\SqsConsumer:
            public: true
            autowire: true
            arguments:
                # Pass the transport name used in config/packages/messenger.yaml
                $transportName: 'async'
    +           $partialBatchFailure: true
    
    1. Configure a batch size greater than 1 and add ReportBatchItemFailures to the FunctionResponseTypes of your Lambda worker function. Lift does it for you automatically since v1.12.0 :sunglasses:

    What's Changed

    • Support partial batch failure by @t-richard in https://github.com/brefphp/symfony-messenger/pull/58

    Full Changelog: https://github.com/brefphp/symfony-messenger/compare/0.4.4...0.5.0

    Source code(tar.gz)
    Source code(zip)
  • 0.4.4(Aug 11, 2022)

    What's Changed

    • Update PHPStan and new fix errors by @t-richard in https://github.com/brefphp/symfony-messenger/pull/61
    • Feature(sqs): Add xray trace id to enveloppe stamps by @hadeli in https://github.com/brefphp/symfony-messenger/pull/63

    New Contributors

    • @hadeli made their first contribution in https://github.com/brefphp/symfony-messenger/pull/63

    Full Changelog: https://github.com/brefphp/symfony-messenger/compare/0.4.3...0.4.4

    Source code(tar.gz)
    Source code(zip)
  • 0.4.3(Jan 7, 2022)

    What's Changed

    • Allow Symfony 6.0 by @ddeboer in https://github.com/brefphp/symfony-messenger/pull/54

    Full Changelog: https://github.com/brefphp/symfony-messenger/compare/0.4.2...0.4.3

    Source code(tar.gz)
    Source code(zip)
  • 0.4.2(Dec 15, 2021)

    What's Changed

    • Rework SQS documentation to be clearer by @t-richard in https://github.com/brefphp/symfony-messenger/pull/50
    • Add support for EventBusName with EventBridgeTransport by @starred-gijs in https://github.com/brefphp/symfony-messenger/pull/52 #55

    New Contributors

    • @t-richard made their first contribution in https://github.com/brefphp/symfony-messenger/pull/50

    Full Changelog: https://github.com/brefphp/symfony-messenger/compare/0.4.1...0.4.2

    Source code(tar.gz)
    Source code(zip)
  • 0.4.1(Jun 8, 2021)

  • 0.4.0(Dec 14, 2020)

  • 0.3.4(Nov 26, 2020)

  • 0.3.3(Nov 14, 2020)

  • 0.3.2(Sep 21, 2020)

  • 0.3.1(May 24, 2020)

  • 0.3.0(May 22, 2020)

  • 0.2.0(Mar 13, 2020)

  • 0.1.1(Feb 19, 2020)

Owner
bref
Running PHP made simple.
bref
PHP Runtime Layer for AWS Lambda

PHP Layer For AWS Lambda Ever wanted to run PHP websites in AWS Lambda? It's your lucky day! This Lambda Runtime Layer runs the PHP 7.3/7.1 webserver

Stackery 319 Nov 30, 2022
A tool to create php lambda's in AWS via custom runtime api

Getting Started This composer library assists in the creation, configuration, and testing of an AWS Lambda function. It utilizes the AWS Lambda custom

Mike McGrath 0 Jul 13, 2022
This component, based on the Symfony serializer and async-aws, is a human-readable and quick abstraction to easily store serialized objects in DynamoDB 🚀.

DynamoDB Storable This component, based on the Symfony serializer and async-aws, is a human-readable and quick abstraction to easily store serialized

Matthieu W. 2 Jun 19, 2022
Lambda calculus interpreter in PHP.

lambda-php Lambda calculus interpreter in PHP. Lambda calculus Lambda calculus is a very minimal programming language that was invented in 1936 by Alo

Igor 22 Feb 28, 2022
Behat Messenger Context

Behat Messenger Context Version Build Status Code Coverage master develop Installation Step 1: Install Context Open a command console, enter your proj

MacPaw Inc. 13 Jan 29, 2022
You have just downloaded "Messenger-app" [A lightweight, minimalistic real-time chat application]

MESSENGER-APP You have just downloaded "Messenger-app" [A lightweight, minimalistic real-time chat application] Setup To get it working, follow these

Chr1st0ph3r SAB 1 Oct 29, 2021
Because every Wedding RSVP website needs to follow DDD, CQRS, Hexagonal Architecture, Event Sourcing, and be deployed on Lambda.

Our Wedding Website Because every Wedding RSVP website needs to follow DDD, CQRS, Hexagonal Architecture, Event Sourcing, and be deployed on Lambda. ?

Edd Mann 3 Aug 21, 2022
Simple Symfony API-Platform Template which you can use to start to develop with symfony and api-platform

symfony-api-platform-skeleton Simple Template for Symfony API You can fork it and change the git remote to your Repo git remote set-url <your-git-remo

null 1 Jan 23, 2022
This repository contains the codebase PHP bridge using RoadRunner Jobs plugin.

RoadRunner Jobs Plugin This repository contains the codebase PHP bridge using RoadRunner Jobs plugin. Installation To install application server and J

Spiral Scout 15 Nov 9, 2022
A fast, reliable, and secure NPM/Yarn bridge for Composer

Foxy is a Composer plugin to automate the validation, installation, updating and removing of PHP libraries asset dependencies (javaScript, stylesheets

Fxp 160 Dec 2, 2022
Sandbox for figuring out why the Alpine + Turbo bridge is broken

Podcaster A Turn-Key Podcasting Starter Kit for Statamic 3 Features This kit is deceptively simple – it may look like a 3 page site but there's a whol

Jack McDade 1 Mar 25, 2022
CDK patterns for serverless container with AWS Fargate

cdk-fargate-patterns CDK patterns for serverless container with AWS Fargate DualAlbFargateService Inspired by Vijay Menon from the AWS blog post intro

Pahud Hsieh 48 Sep 1, 2021
WHMCS Automation Module For AWS EC2 Instances.

使用方法 把AWSEC2目录直接扔到 WHMCS/modules/servers 下即可 自定义字段 cloudinit (文本框 textarea 在订单页面显示) pem (文本框 textarea 仅管理员可见) data (文本框 textarea 仅管理员可见) 特性 动态IP (关机再开

CoiaPrant 9 Jan 28, 2022
Lumen on Docker - Skeleton project with Nginx, MySQL & PHP 8 | Aws ECS, Google Kubernates, Azure Container Engine

Docker infrastructure for Lumen Description Microservice Lumen is a starting skeleton based on Docker and Lumen Framework. This project helps to devel

Fabrizio Cafolla 218 Sep 25, 2022
Private Composer registry for private PHP packages on AWS Serverless

Tug Tug is a Composer private registry for private PHP packages installable with Composer (1 and 2). The main idea of this project is to have an inter

Fxp 33 Oct 5, 2022
AWS DynamoDB session handler for Magento (experimental!)

Magento Session Handler for AWS DynamoDB Author: Fabrizio Branca TODO: disable automatic gc create cron that does gc how does it keep track of lifetim

AOE 5 Apr 6, 2017
This demo app shows you how to run a simple PHP application on AWS Elastic Beanstalk.

Elastic Beanstalk + PHP Demo App - "Share Your Thoughts" This demo app shows you how to run a simple PHP application on AWS Elastic Beanstalk. Run the

AWS Samples 143 Nov 26, 2022
A Laravel artisan based package to create the AWS (SES + SNS) infrastructure to receive email event notifications with Http/Https endpoint.

Laravel SES Tracking Setup the AWS infrastructure to handle email events using SES/SNS and http/s endpoints with a single Laravel artisan command. Thi

null 11 Apr 26, 2022
Simple, single-file and dependency-free AWS S3 client.

Simple, single-file and dependency-free AWS S3 client. Why? In some scenarios we want the simplest and lightest S3 client possible. For example in Bre

Matthieu Napoli 28 Nov 15, 2022