Protobuf
Protocol Buffers (Protobuf) is a free and open-source cross-platform data format used to serialize structured data, Initially released on July 7, 2008. It is useful in developing programs to communicate with each other over a network or for storing data. The method involves an interface description language that describes the structure of some data and a program that generates source code from that description for generating or parsing a stream of bytes that represents the structured data.
Supported versions
proto2
proto3
Supported Features
Retrieve compiled protobuf schemas (Produce messages without .proto files)
Versioning
Embedded serialization
Live evolution
Import packages (soon)
Import types (soon)
Getting started
How to produce a message
Memphis abstracts the need for external serialization functions and embeds them within the SDK.
In node.js, we can simply produce an object. Behind the scenes, the object will be serialized based on the attached schema and data format - protobuf.
Example schema: (No need to compile)
syntax = "proto3";
message Test {
string field1 = 1;
string field2 = 2;
int32 field3 = 3;
}Producing a message without a local .proto file:
const { memphis } = require("memphis-dev");
(async function () {
let memphisConnection
try {
memphisConnection = await memphis.connect({
host: "MEMPHIS_BROKER_URL",
username: "APPLICATION_USER",
password: "PASSWORD",
accountId: ACCOUNT_ID //*optional* In case you are using Memphis.dev cloud
});
const producer = await memphisConnection.producer({
stationName: "STATION_NAME",
producerName: "PRODUCER_NAME"
});
var payload = {
field1: "AwesomeString",
field2: "AwesomeString",
field3: 54
};
await producer.produce({
message: payload
})
memphisConnection.close();
} catch (ex) {
console.log(ex);
if (memphisConnection) memphisConnection.close();
}
})();Memphis abstracts the need for external serialization functions and embeds them within the SDK. Example proto file:
To compile the proto file, run the following command:
Producing a message without a local .proto file:
Producing a message with a local .proto file:
Memphis abstracts the need for external serialization functions and embeds them within the SDK.
Example schema:
To compile the proto file, run the following command:
Producing a message with a local .proto file:
Memphis abstracts the need for external serialization functions and embeds them within the SDK.
Example schema:
Producing a message without a local .proto file:
Memphis abstracts the need for external serialization functions and embeds them within the SDK.
Example schema:
Producing a message without a local .proto file:
In REST, you can simply produce an object. Behind the scenes, the object will be serialized based on the attached schema and data format - protobuf.
Example schema:
Producing a message without a local .proto file:
How to consume a message (Deserialization)
Example schema:
Consumption
Last updated
Was this helpful?

