Server Messages: Shooting in the Dark

Sending messages from an LCDS or BlazeDS server to a Flex client starts with getting a reference to the MessageBroker, which is a Java object deployed in the servlet container where you’ve installed BlazeDS or LCDS. Then, create an instance of the AsyncMessage object, and set the client ID (specific sender) and the destination (an equivalent of a topic in the publish/subscribe messaging terminology). When this is done, place your business-related object inside (e.g., myOrderInfo) and call the function routeMessageToService(). This process can go like this:

MessageBroker msgBroker = MessageBroker.getMessageBroker(null);
String clientID = UUIDUtils.createUUID(false);

AsyncMessage msg = new AsyncMessage();
msg.setDestination("myDestination");
msg.setClientId(clientID);
msg.setMessageId(UUIDUtils.createUUID(false));
msg.setTimestamp(System.currentTimeMillis());

myOrderInfo = new OrderInfo();
// Populate myOrderInfo with some data

msg.setBody(myOrderInfo);
msgBroker.routeMessageToService(msg, null);

Here comes the million-dollar question: did the message reach the recipient? Remember, we are talking about the Java server-side code here, not a conventional use of Flex Producer/Consumer objects that come with acknowledgment event MessageAckEvent. This uncertainty explains the need to implement some kind of a client heartbeat. A connected client sends a small message to the server, say, every 500 milliseconds. These heartbeats contain delivery confirmations ...

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.