Skip to content

Latest commit

 

History

History
68 lines (51 loc) · 1.89 KB

message.md

File metadata and controls

68 lines (51 loc) · 1.89 KB

Message

Messages are used by nodes to communicate with one another and exchange data over the network.

Contents

Constructor

new Message(options)

  • 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 });

Methods

message.create_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();

message.serialize()


Converts the message into a new buffer to be sent over the network.

//  Serialize the message before sending
const serialized = message.serialize();

message.message_type(specs)

  • 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);