1

It seems json is the default way for serialization data in nameko rpc. If I call rpc.my_service.send(b'\x01\'), it will raise exception kombu.exceptions.EncodeError: Object of type 'bytes' is not JSON serializable

Is there a way to send binary data in nameko rpc? eg, pickle. Would please give me a short example? Thank you in advance.

ShenLei
  • 567
  • 1
  • 5
  • 17

1 Answers1

4

You can serialize with pickle by specifying it in your config file. Simply:

# config.yaml
serializer: pickle

And

nameko run my_service --config config.yaml

If you need something more advanced you can build your own serializer and again configure the service to use it with your config file:

# config.yaml
serializer: my_serializer
SERIALIZERS:
    my_serializer:
        encoder: 'path.to.encode.function'
        decoder: 'path.to.decode.function'
        content_type: 'application/x-my-serializer'

The encode and decode functions simply take a value and return a transformed version.

Matt
  • 2,153
  • 1
  • 18
  • 29