Understanding Message Objects

Understanding Messages

So far, we have seen that subscribing to a topic involves working with objects of type com.crankuptheamps.client.Message. 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.getCommandId() function corresponds to the commandId header field, the Message.getBatchSize() 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 getXxx() / setXxx() methods corresponding to the header fields. 60East does not recommend attempting to parse header fields from the raw data of the message.

In AMPS, fields sometimes need to be set to a unique identifier value. For example, when creating a new subscription, or sending a manually constructed message, you'll need to assign a new unique identifier to multiple fields such as CommandId and SubscriptionId. For this purpose, Message provides newXxx() methods for each field that generates a new unique identifier and sets the field to that new value.

getData() Method

Access to the data section of a message is provided via the getData() method. The data contains the unparsed data in the message. The getData() method returns the data as a Java string, which is suitable for message formats that can be represented as Unicode text, such as JSON, XML, FIX, or NVFIX. For binary data, the AMPS Java client provides a getDataRaw() method to allow you to work with the underlying byte array in the message. See the Working with Messages and Byte Buffers section for details.

The AMPS Java 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 whichever 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