Giter Site home page Giter Site logo

Invoke error about symfony-messenger HOT 8 CLOSED

brefphp avatar brefphp commented on June 14, 2024
Invoke error

from symfony-messenger.

Comments (8)

mnapoli avatar mnapoli commented on June 14, 2024 1

Could not decode message using PHP serialization

It seems like Symfony is trying to use unserialize() (the PHP serialization format) over the message content, but the message content is JSON.

Maybe it's a matter of configuring Symfony Messenger so that it uses JSON as a format?

from symfony-messenger.

mnapoli avatar mnapoli commented on June 14, 2024 1

In that case I would recommend using a typed handler: https://bref.sh/docs/function/handlers.html#sns-events

Note that this typed handler can be a Symfony service, you can use the same trick to load a symfony service:

<?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 $kernel->getContainer()->get(MySnsHandlerService::class);

from symfony-messenger.

JKetelaar avatar JKetelaar commented on June 14, 2024

Thanks so much, you put me in the right direction!
Since Symfony 4.3 Symfony has moved from its serializer (JSON) to the PhpSerializer.

Symfony 4.3 & 4.4:

framework:
    messenger:
        serializer:
            id: 'messenger.transport.symfony_serializer'

Though this doesn't work yet on Symfony 5, there you need to make the change as follows:

framework:
    messenger:
        serializer:
            default_serializer: messenger.transport.symfony_serializer
            symfony_serializer:
                format: json
                context: { }

Should I make a PR with this and add it to the readme?

from symfony-messenger.

JKetelaar avatar JKetelaar commented on June 14, 2024

After this, a lot more errors occur that have to do with the old integration of this module and the latest Symfony.
In the meantime, I've also written my own SnsConsumer and created my own Serializer. This works (sketchy) as of now, though am I doing something completely wrong, or is the integration with Symfony 5.x not fully tested yet?

from symfony-messenger.

mnapoli avatar mnapoli commented on June 14, 2024

I'm confused: is your Symfony Lambda worker handling events that were created by the Symfony application?

The principle is like this:

  • Symfony emits a message to SQS, SNS or EventBridge
  • SQS/SNS/EventBridge triggers Lambda -> Symfony processes the message

So the format of the message is defined by Symfony: if you publish it as JSON, your app will receive it as JSON. If you publish it as serialized, then your app will receive it as serialized.

Are you using another architecture?

from symfony-messenger.

JKetelaar avatar JKetelaar commented on June 14, 2024

Ah... That would explain a lot... My bad, sorry.

So the approach I'm taking and using this bridge/bundle for is to receive SES messages in SNS and process them with a Lambda function.
So in my case Symfony isn't creating a message in SNS, but SES is (or anything else I want to hook SES on).

Would you recommend another module/approach for this? Or is this uncommon and does it indeed require custom built software?

from symfony-messenger.

JKetelaar avatar JKetelaar commented on June 14, 2024

This explains a lot, thanks so much!

I'll probably write a blog post about it or something, in case others ever have the same situation.

from symfony-messenger.

mnapoli avatar mnapoli commented on June 14, 2024

Please do!

from symfony-messenger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.