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 http://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
Chat Client
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.
messaging-config.xml
<?xml version=”1.0″ encoding=”UTF-8″?>
<service id=”message-service”
class=”flex.messaging.services.MessageService”>
<adapters>
<adapter-definition id=”actionscript” class=”flex.messaging.services.messaging.adapters.ActionScriptAdapter” default=”true” />
</adapters>
<default-channels>
<channel ref=”my-polling-amf”/>
</default-channels>
<destination id=”chat-application”>
<properties>
<network>
<session-timeout>0</session-timeout>
<throttle-inbound policy=”ERROR” max-frequency=”50″/>
<throttle-outbound policy=”REPLACE” max-frequency=”500″/>
</network>
<server>
<max-cache-size>1000</max-cache-size>
<message-time-to-live>0</message-time-to-live>
<durable>true</durable>
<durable-store-manager>flex.messaging.durability.FileStoreManager</durable-store-manager>
</server>
</properties>
</destination>
</service>
That’s it. Your chat application is ready for use.
Adobe ROCKS
Posted by Sujit Reddy G 

