Acknowledging the Endpoint

Now let’s switch to the server side and create a custom endpoint. We need it to beef up the acknowledgment message sent from the server. When the client gets a message, it needs to know the seqNo of its last message that was successfully delivered to the server. For now, it will be used only in the testing application. Later, when the order of client messages will be guaranteed, we will use it to determine which ones to put aside and which ones to forward for server processing. As shown in Example 5-26, the proper overloading of the serviceMessage() method does the job.

Example 5-26. AcknowledgingRTMPEndpoint.java

package com.farata.messaging.endpoints; import org.apache.log4j.Logger; import com.farata.messaging.messages.ReliableClientMessage; import flex.messaging.endpoints.RTMPEndpoint; import flex.messaging.messages.AcknowledgeMessage; import flex.messaging.messages.Message; public class AcknowledgingRTMPEndpoint extends RTMPEndpoint { private final String LAST_SERVED_NUMBER="lastServedNumber"; private final String SEQUENCE_NUMBER="seqNo"; public Message serviceMessage(Message message) { Message m = super.serviceMessage(message); if (message instanceof ReliableClientMessage) { int sequenceNumber = (Integer)message.getHeader(SEQUENCE_NUMBER) ; int lastServedNumber = sequenceNumber; String duplicate = (String)message.getHeader("duplicate"); if (logger.isDebugEnabled()) logger.debug( "Received message "+ sequenceNumber + ((duplicate!=null)?" (duplicate)":"") ...

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.