ObjectMessage
Basic message object
Message objects are compatible withmqEach module can be used to build a custom message processing system. The creation method is:
1
2var mq = require("mq");
var m = new mq.Message();
inheritance relationship
Constructor
Message
Message object constructor
1new Message();
constant
TEXT
Specify message type 1, which represents a text type
1const Message.TEXT = 1;
BINARY
Specify message type 2, representing a binary type
1const Message.BINARY = 2;
member properties
value
String, the basic content of the message
1String Message.value;
params
NArray, the basic parameters of the message
1readonly NArray Message.params;
type
Integer, message type
1Integer Message.type;
data
Value, query the data of the message. This attribute will return different data according to the content-type. When it is text, the text will be returned.jsonreturn whenjson, otherwise it returns binary
1readonly Value Message.data;
body
SeekableStream, a stream object containing the data portion of the message
1SeekableStream Message.body;
length
Long, the length of the message data part
1readonly Long Message.length;
stream
Stream, the stream object when querying the message readFrom
1readonly Stream Message.stream;
lastError
String, query and set the last error of message processing
1String Message.lastError;
member function
read
Read data of specified size from the stream. This method is an alias of the corresponding method of body.
1Buffer Message.read(Integer bytes = -1) async;
Call parameters:
- bytes: Integer, specifies the amount of data to be read. The default is to read data blocks of random size. The size of the data read depends on the device.
Return results:
- Buffer, returns the data read from the stream. If there is no data to read or the connection is interrupted, null is returned.
readAll
Read all remaining data from the stream. This method is an alias of the corresponding method of body.
1Buffer Message.readAll() async;
Return results:
- Buffer, returns the data read from the stream. If there is no data to read or the connection is interrupted, null is returned.
write
Write the given data. This method is an alias of the corresponding method in body.
1Message.write(Buffer data) async;
Call parameters:
- data:Buffer, given the data to be written
json
Writes the given data in JSON encoding
1Value Message.json(Value data);
Call parameters:
- data: Value, given the data to be written
Return results:
- Value, this method does not return data
Parse the data in the message as JSON encoding
1Value Message.json();
Return results:
- Value, returns the parsed result
pack
bymsgpackEncoding writes the given data
1Value Message.pack(Value data);
Call parameters:
- data: Value, given the data to be written
Return results:
- Value, this method does not return data
bymsgpackEncoding and parsing the data in the message
1Value Message.pack();
Return results:
- Value, returns the parsed result
end
Set the end of current message processing,ChainThe processor does not continue with subsequent transactions
1Message.end();
isEnded
Query whether the current message has ended
1Boolean Message.isEnded();
Return results:
- Boolean, returns true when finished
clear
Clear message content
1Message.clear();
sendTo
Sends a formatted message to the given stream object
1Message.sendTo(Stream stm) async;
Call parameters:
- stm:Stream, specifies the stream object that receives the formatted message
readFrom
Reads the formatted message from the given cache stream object and parses the populated object
1Message.readFrom(Stream stm) async;
Call parameters:
- stm:Stream, specifies the stream object for reading formatted messages
toString
Returns the string representation of the object. Generally, "[Native Object]" is returned. The object can be re-implemented according to its own characteristics.
1String Message.toString();
Return results:
- String, returns the string representation of the object
toJSON
Returns a JSON format representation of the object, generally returning a collection of readable properties defined by the object.
1Value Message.toJSON(String key = "");
Call parameters:
- key: String, not used
Return results:
- Value, returns a value containing JSON serializable