Understanding Message Objects
So far, we have seen that subscribing to a topic involves working with objects of AMPS.Message
type. A Message
represents a single message to or from an AMPS server. Messages are received or sent 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
class contains a distinct property that allows for retrieval and setting of that field. For example, the Message.get_command_id()
function corresponds to the commandId
header field, the Message.get_batch_size()
function 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.
To work with header fields, a Message
contains get_xxx()
/ set_xxx()
methods corresponding to the header fields, as well as a number of getXXX()
/ setXXX()
methods for compatibility with previous implementations of the AMPS Python client. 60East does not recommend attempting to parse header fields from the raw data of the message.
get_data() Method
Access to the data section of a message is provided via the get_data()
method. The data
property will contain the unparsed data of the message. Your application code parses and works with the data.
The AMPS Python client contains a collection of helper classes for working with message types that are specific to AMPS (for example, FIX, NVFIX, and AMPS composite message types). For message types that are widely used, such as JSON or XML, you can use the standard Python facilities or the library you typically use in your environment.
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.
Last updated