Closed JKetelaar closed 3 years ago
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?
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?
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?
I'm confused: is your Symfony Lambda worker handling events that were created by the Symfony application?
The principle is like this:
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?
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?
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);
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.
Please do!
With a setup using a function to use SNS, I am getting the following error:
Any clue of what I'm doing wrong?
Here's some more information about the application:
config/packages/messenger.yaml
:src/Message/SesMessage.php
src/MessageHandler/SesNotificationHandler.php
bin/consumer.php
serverless.yml