The BlazeDS messaging capability is based on established messaging standards and terminology. BlazeDS messaging provides a client-side API and a corresponding server-side Message Service (BlazeDS Message Service) for creating BlazeDS messaging applications. BlazeDS messaging also enables participation in Java Message Service (JMS) messaging.
There are two components available in the Flex frame work for messaging, mx:Producer and mx:Consumer. Producer is the component which is used for producing messages to a destination and Consumer is used for subscribing to a destination and receiving messages published to that destination. Consumer also gives option to filter the messages based on user defined constraints.
I have created a chat application using Flex and Blaze DS. Flex application will use the publish-subscribe messaging mechanism. Flex application checks for new messages using polling mechanism.
This chat application will send messages to selected users only. I have not included any error handling stuff to keep the code as simple as possible.🙂
We just need to create the client, the server side message handling is provided by Blaze DS. We create an mxml file, which will handle the client logic and configure a destination on the server.
BlazeDS should be setup and running to execute this sample. Please follow the steps in https://sujitreddyg.wordpress.com/2008/01/14/invoking-java-methods-from-adobe-flex/ to set up the BlazeDS and setting up a Flex application, which is mapped to BlazeDS root directory.
Chat application snapshots
Please download the mxml file from this URL: http://sujitreddy.g.googlepages.com/ChatApplication.mxml
Configuring destination on the server
Navigate to tomcat/webapps/blazeds/WEB-INF/flex under BlazeDS Setup folder and open the file messaging-config.xml. Replace the XML file content with the content below. The ID of the destination added below will be used by the components at the client side.
<?xml version=”1.0″ encoding=”UTF-8″?>
<adapter-definition id=”actionscript” class=”flex.messaging.services.messaging.adapters.ActionScriptAdapter” default=”true” />
<throttle-inbound policy=”ERROR” max-frequency=”50″/>
<throttle-outbound policy=”REPLACE” max-frequency=”500″/>
That’s it. Your chat application is ready for use.🙂 Adobe ROCKS🙂