Messages are used by nodes to communicate with one another and exchange data over the network.
- constructor
- methods
options
:id
: String (Optional, will be generated, only set it when responding) The message identifier, useful when responding to a request (Response ID should be the same as the Request ID).- Request
method
: String The name of the remote method to be invoked.params
: Object The parameter values to be used during the invocation of the remote method.
- Response
result
: Any The result of the invoked method.error
: Error (Optional) If any error occurs during the execution of the invoked method.
Creates a new Message to be sent over the network.
const plexus = require("plexus");
// Create a request
const request = new plexus.Message({ method: "remote method", params: {} });
// Create a response
const response = new plexus.Message({ result: "response", id: request.id });
Creates a new ID for the message (request) to be used when responding.
// Create a new message request ID
message.id = message.create_id();
Converts the message into a new buffer to be sent over the network.
// Serialize the message before sending
const serialized = message.serialize();
specs
: Object The message's options.
Returns the type of the message (REQUEST, RESPONSE or UNKNOWN).
const specs = { method: "remote method", params: {} }
const type = message.message_type(specs);