A message is composed of several parts, or properties. The most important property is the message data. All parts of a message can be accessed directly with the SmartSockets API. Almost all parts of a message can be specified using the API. With the exception of the message create method, which belongs to the TipcSvc factory class, all methods for working with messages are members of the TipcMsg class. Messages can be created with TipcSvc.createMsg and copied with TipcMsg.clone.
Figure 5 shows an example of the message that you constructed and sent in the previous lesson (Lesson 2: Publish-Subscribe). This message was a standard SmartSockets message type, INFO
, and was sent to the /ss/tutorial/lesson2
subject. The data part of the message consisted of a single string field containing the string "Hello World!
".
There are SmartSockets methods to get (access) and set (write) each part of the message.
A message is composed of several properties. The SmartSockets Java Class Library methods for setting and getting the message property are enclosed in parentheses.
There are a large number of SmartSockets methods to build the data part of a message (TipcMsg.append*) and access the data part of a message (TipcMsg.next*). See the online Java documentation for a complete description of these methods.
Figure 6 shows an example of a more complex message. It is a SmartSockets standard NUMERIC_DATA message, and the data part of this message is a series of variable name-value pairs (voltage = 33.4534
, switch_pos = 0
). You construct a message similar to this one later in this lesson.
One of the key features of SmartSockets is that it has structured messages. There is no need for you to figure out how to encode your messages. SmartSockets takes care of that for you and provides robust methods that allow you access to any part of the structure of a message. Because the messages are structured, SmartSockets knows how to automatically convert different data types when delivering the message across a heterogeneous network. This is all done transparently for you, using a receiver-makes-right approach in which the final receiver of the message does the translation. This is most efficient, as data translation is only done once.
Many other messaging products do not have the concept of a structured message type. They simply move a block of memory across the network. There is no API to help build and access the different fields of the message, and there is no automatic conversion of data. They leave these tasks up to you, increasing the amount of time it takes to build your application.
TIBCO SmartSockets™ Java Library User’s Guide and Tutorial Software Release 6.8, July 2006 Copyright © TIBCO Software Inc. All rights reserved www.tibco.com |