Structured Data

The payload is set by using the appendBodyTuple method of the JadeGenericMessage class.

Before content is added, the message object must be initialized for sending. Do this by calling the createMessage method of the JadeGenericQueue class with the forPUT parameter set to true, or by calling the initializeForPut method of the JadeGenericMessage class on an existing message object.

The body property contains a series of named values (tuples). The name of a tuple is case-sensitive and must start with a letter. The subsequent characters (up to a maximum of 89 characters) can be letters, digits, underscores, or periods; for example, valid tuple names could be cust.name, cust.address, and so on.

One of the main uses of tuples is to make it easy to serialize an object by copying its properties into a message. Most primitive type property values are converted to UTF8 text apart from Binary values, which do not need to be converted and are sent as is. References are handled by serializing the oid value.

The following code fragment shows a message being constructed from name-value tuples.

// initialize the message
message := queue.createMessage(true);
// describe the type of data in the payload
message.format := "JadeTpls";
// set message payload
message.appendBodyTuple("color", "Green");
message.appendBodyTuple("height", 200);
message.appendBodyTuple("width", 300);
message.appendBodyTuple("new", false);
// insert message in queue
message.inspectModal;
queue.putMessage(message, null);
queue.putMessage(message, null);

The first time the appendBodyTuple method is called, the format property is automatically set to JadeTpls.

When the message is retrieved and the value of the format property is set to JadeTpls, the getBodyTuple method of the JadeGenericMessage class can be used to scan the text in the message body for a tuple with the specified name, as shown in the following code fragment. The method returns false if there is no tuple with the specified name.

reply.getBodyTuple("color", any);
// value of 'color' tuple is any.String
reply.getBodyTuple("height", any);
// value of 'height' tuple any.Integer
reply.getBodyTuple("new", any);
// value of 'new' tuple any.Boolean