We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Data Serialization

So far we've been using JSON to serialize our messages. "Serialization" is a fancy way to say "convert our data into a format to be sent over the network". JSON is often a great choice because it's human-readable, easy to work with, and widely supported.

When you run into a problem, you can view the raw message in the Rabbit UI and read it. However, AMQP doesn't require you to use JSON, it works with raw bytes.

JSON isn't the most efficient way to serialize data, so when you're sending massive amounts of data, you might want to consider a more efficient format.

MessagePack

With TypeScript, we can use MessagePack to serialize our data. MessagePack is a binary format that is more efficient than JSON. It's faster to encode and decode, and it uses less space.

MessagePack is a binary format, so it's not human-readable. However, it is widely supported in many programming languages

Assignment

npm install @msgpack/msgpack
export function publishMsgPack<T>(
  ch: ConfirmChannel,
  exchange: string,
  routingKey: string,
  value: T,
): Promise<void>;