Guaranteed Delivery of Client Messages

Consider the following scenario. A Wall Street trader clicks the Buy button. A Flex message producer sends a message to the remote server over the Internet. You can’t afford to lose even one such message, so the rest of this chapter is devoted to implementing guaranteed delivery of messages initiated on the client in the Flash Player.

Because Flex provides an mx.messaging.events.MessageAckEvent for every client message, you do not have to worry about acknowledgment. You do still need to take care of the content of the acknowledgment. As you would expect, we are going to enumerate the messages with the seqNo header by extending the standard endpoint class to return this information inside the MessageAckEvent in the form of the lastProcessedNo header. This will be a responsibility of the custom AcknowledgingEndpoint Java class.

To guarantee message delivery, we will memorize messages as unconfirmed prior to sending them out. As soon as the server acknowledgment message comes, we will remove the message from the unconfirmed pool. In parallel, a timer “thread” will be in charge of resending unconfirmed messages in configured intervals. These will be the tasks of the custom ActionScript class ResendingChannel. The corresponding design is presented in Figure 5-10.

The top portion of Figure 5-10 represents the client side, and the bottom part is about the server.

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.