4

I have integrated symfony messenger bundle and i am trying to encode that message . It was working in Symfony 3.4.4 version . However it is giving above error in Symfony 3.4.28 version. I have traced in symfony serialzer component , it seems that jsonEncoder is not listing in serialzer.php and which is causing this issue.

What is the reason for excluding json encoder in symfony serializer component. See below DoctrineTransportSender:

public function send(Envelope $envelope)
{
    $encodedMessage = $this->encoder->encode($envelope);
}

//messenger configuration:
messenger:
  transports:
    # DSN: doctrine://$repository_alias/$queue_name
    # most likely we do not need more repositories (unless there's a need for splitting MySQL table with messages)
    main: "doctrine://default/test"

  routing:
    # message type to transport routes
    Bundle\QueueBundle\Message\TestMessage: [ main ]

  serializer:
    enabled: true
Madhuri Mane
  • 41
  • 1
  • 3
  • I am a bit baffled, because this configuration should not be available in the FrameworkBundle in version 3.4. Could you maybe run `composer show` in your cli and then copy & paste the symfony packages it returns? Could you also run `bin/console debug:config framework messenger.serializer` to see what the full serializer config (with included default values) returns? – dbrumann Sep 09 '19 at 14:02

2 Answers2

1

Symfony Messenger switched to PHP's native serialization/deserialization by default. Using php serialization prevents problems, e.g. accidentally omitting properties from being serialized. It will also ensure the component can be used without Symfony Serializer, which is less of an issue with Symfony 3.4, but with Symfony 4 and Flex or when using the messenger outside of Symfony you would have to install this dependency manually leading to errors.

You can still use Symfony Serializer, but it has to be configured. Considering you are on Symfony 3.4 you will likely have to do this manually by providing an appropriate Serializer-instance to the TransportFactory, see:

https://github.com/symfony/symfony/blob/4.4/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L1751-L1757

In Symfony 4 you can use the configuration instead, see:

https://symfony.com/doc/current/messenger.html#serializing-messages

dbrumann
  • 16,803
  • 2
  • 42
  • 58
  • Thanks for your response. I observed one more thing, it works fine for other type i.e. xml/csv . It only excludes json Encoder. As we are already using one third party tool which is build in symfony 3.4.28 , i cannot upgrade it to 4. So Do i need to override serializer here? as Messenger component serializer is using symfony's serializer. – Madhuri Mane Sep 09 '19 at 05:23
  • I am using same symfony messenger bundle's version (i.e. 4.1.7) which was working with symfony 3.4.4. So it should not change its behaviour. – Madhuri Mane Sep 09 '19 at 06:09
  • The messenger itself should work with 3.4, but as far as I know the FrameworkBundle integration is not there, which makes things a bit complicated. I am assuming you configured the messenger manually, somewhere. Maybe you can add your setup (configured services both for the messenger and the serializer) to the question? That would help. – dbrumann Sep 09 '19 at 06:22
  • Updated configuration for messenger in question – Madhuri Mane Sep 09 '19 at 11:55
0

Thanks for the response. I have resolved above issue by adding customized serializer instead of calling messenger serializer(Which includes encoding as well decoding) and it works fine

Madhuri Mane
  • 41
  • 1
  • 3