When Message Order Matters

Our guaranteed server message delivery is neglecting the order of the messages, which may be an important factor in some business applications. In wide area networks (WANs), messages can be routed in any random way and arrive in any order.

If the order matters in your application, mark the messages with sequence numbers as they get sent and hold on to the “premature” ones on the receiving end. This QoS technique pertains to both server- and client-originated messages. First consider the messages originated on the server; this workflow is shown in Figure 5-8.

Server log of the test illustrated in

Figure 5-7. Server log of the test illustrated in Figure 5-6

Guaranteeing the order of the incoming messages

Figure 5-8. Guaranteeing the order of the incoming messages

SerializingChannel

The cornerstone of our design is the SerializingChannel class. In addition to the array of received message digests described earlier, the channel has to maintain the dictionary of incoming messages for order restoration purposes:

private var incoming:Dictionary ;

Should a message arrive out of order, the receive() method will store it along with the ...rest arguments:

override public function receive( msg:IMessage, ...rest:Array ) : void { if (msg is ReliableServerMessage) { . . . // If message is out of order: incoming[msg.clientId + '|' + seqNo] = { msg:msg, rest:rest }; ...

Get Agile Enterprise Application Development with Flex now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.