Understanding Messages Objects
So far, we have seen that subscribing to a topic involves working with
objects of the Message type. A Message represents a single
message from an AMPS server, while a Command is sent to a server.
Commands are sent and messages are received for every client/server
operation in AMPS.
Header Properties
There are two parts of each message in AMPS: a set of headers that
provide metadata for the message, and the data that the message
contains. Every AMPS message has one or more header fields defined. The
precise headers present depend on the type and context of the message.
There are many possible fields in any given message, but only a few are
used for any given message. For each header field, the Message object
contains a distinct method that allows for retrieval of that field.
For example, the Message.header.commandId() corresponds to the
CommandId header field, the Message.header.batchSize() corresponds
to the BatchSize header field, and so on. For more information on these
header fields, consult the AMPS User Guide and AMPS Command Reference.
Message class represents messages received from an AMPS server. When
creating a message to be sent, the Command class is used. To work with
header fields, a Command contains a set of <propertyName>() methods,
which work as both setters and getters, allowing to chain command properties
when creating a new command.
Message Data
Received message data is contained in the Message.data property.
The data property will contain the parsed data of the message.
The AMPS JavaScript client contains a collection of helper classes for working with message types that are specific to AMPS (for example, JSON, FIX, NVFIX, and AMPS composite message types). You can replace default parsers to implement required specific behavior, as well as add new helpers.
Message Field Reference
The AMPS Command Reference contains a full description of which fields are available and which fields are returned in response to specific commands.