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


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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.