This version has reached end-of-life. It is no longer maintained. For the latest stable version, click here.

Serializers

Transporter needs a serializer module which serializes & deserializes the transferred packets.

Example

const { ServiceBroker } = require("moleculer");

const broker = new ServiceBroker({
nodeID: "server-1",
transporter: "NATS",
serializer: "ProtoBuf"
});

Built-in serializers

JSON serializer

This is the built-in default serializer. It serializes the packets to JSON string and deserializes the received data to packet.

const broker = new ServiceBroker({
// serializer: "JSON" // don't need to set, because it is the default
});

Avro serializer

Built-in Avro serializer.

const broker = new ServiceBroker({
serializer: "Avro"
});
Dependencies

To use this serializer install the avsc module with npm install avsc --save command.

MsgPack serializer

Built-in MsgPack serializer.

const broker = new ServiceBroker({
serializer: "MsgPack"
});
Dependencies

To use this serializer install the msgpack5 module with npm install msgpack5 --save command.

ProtoBuf serializer

Built-in Protocol Buffer serializer.

const broker = new ServiceBroker({
serializer: "ProtoBuf"
});
Dependencies

To use this serializer install the protobufjs module with npm install protobufjs --save command.

Custom serializer

You can also create your custom serializer module. We recommend to copy the source of JSONSerializer and implement the serialize and deserialize methods.

Use custom serializer

const { ServiceBroker } = require("moleculer");
const MyAwesomeSerializer = require("./my-serializer");

const broker = new ServiceBroker({
serializer: new MyAwesomeSerializer()
});