Skip to content

Function: messagePackQueueCodec() ​

messagePackQueueCodec(): QueueCodec

The MessagePack codec of the queues, the default codec of a Queue, the same as the default codec of @lakutata/nats: the value is first normalized through JSON (JSON.parse(JSON.stringify(value))), so that the services written in other languages read plain data. A Date arrives as its ISO string (an input DTO converts it back, a result stays a string), a Buffer as {type: 'Buffer', data: [...]}, a class instance as a plain object, undefined as null (dropped from the objects); a bigint or a circular value fails the encoding (a QueueInvalidMessageException from the queue).

Returns ​

QueueCodec

The codec.

Example ​

typescript
import {messagePackQueueCodec} from '@lakutata/queue'

const codec = messagePackQueueCodec()
console.log(codec.decode(codec.encode({id: 7, at: new Date(0)}))) //{id: 7, at: '1970-01-01T00:00:00.000Z'}

Released under the MIT License.