The Messenger cycle is the XML processing cycle that consists of the processing of an input message within a single database transaction. The input in a messenger cycle comes from an XML message and the output includes a response XML message. The Messenger cycle also includes framework methods that are used to include user-defined logic. In a Messenger cycle steps, such as initialization, validation, parsing message, and serialization are automatic.
Defining the Processing Logic
A special type of serializable class is used to define the processing logic to be executed for an input XML message. This class is called a Messenger class and is defined with Stereotype=Messenger. The Messenger class defines the format of an XML message and the processing logic to handle the message when it is input to the system. The Messenger class is an entry point for processing an input XML message. An XML message is passed to an instance of the corresponding Messenger class for processing.
In a Messenger cycle a Messenger class is defined to implement the Serialization that defines the structure and layout of the input XML message. Then, the class implements an automatic processing cycle to receive an XML message and execute user-defined processing logic.
Basic Steps in a Messenger Class
The basic steps in a messenger class are as follows:
Parsing the input message and populating an instance of the Messenger class with the data from the message.
Validating the input data from the message.
Executing user-defined logic.
Returning a response XML message (optional).
Including User-Defined Logic
Built-in framework methods are available in which user-written logic can be included to perform any user-defined business rules or processing including reading from and writing to the database.
The framework methods are
Receive()– Intended for any logic to process the input message. This method can include validating input data, storing data in the database, reading data from the database, and so on.
Respond() – Intended for any logic to formulate a response message. This method typically includes logic to read data from the database, populate a serializable class instance (that is, a class that implements the Serialization), and then return that instance. A returned serializable instance is automatically serialized into the corresponding XML message and included in the response.
The Respond() method is unique, that is, it is defined with a ReturnType of ‘String’. The String return value contains the XML message stream. To return the XML message you must use the Return command to return a serializable class instance that is cast to the Serialization through the ‘AsA’ command option. The returned instance is implicitly converted to a string value by serializing the instance according to the interface definition.
The syntax of the Return command when used in this context is
Return <instance> AsA <interface>
Where, <instance> is the serializable class instance and <interface> is the Serialization that is implemented by the class.
The following image shows the Messenger cycle:
The Messenger Cycle is similar to the Ispec cycle, except that the input comes from an XML message instead of a client form and the output can include a response XML message.