Flex supports publish and subscribe messaging through the open source BlazeDS Message Service. The Message Service manages a set of destinations that Flex clients can publish and subscribe to. Flex provides two components, Producer and Consumer, that you use to publish and subscribe to a destination. To subscribe to a destination, you use the subscribe() method of the Consumer class. When a message is published to a destination to which you subscribe, the message event is triggered on the Consumer.
Using the BlazeDS publish/subscribe capability is easy. Here is an example of a simple chat application:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="consumer.subscribe()">
<mx:Script>
<![CDATA[
import mx.messaging.messages.AsyncMessage;
import mx.messaging.messages.IMessage;
private function send():void
{
var message:IMessage = new AsyncMessage();
message.body.chatMessage = msg.text;
producer.send(message);
msg.text = "";
}
private function messageHandler(message:IMessage):void
{
log.text += message.body.chatMessage + "\n";
}
]]>
</mx:Script>
<mx:Producer id="producer" destination="chat"/>
<mx:Consumer id="consumer" destination="chat" message="messageHandler(event.message)"/>
<mx:Panel title="Chat" width="100%" height="100%">
<mx:TextArea id="log" width="100%" height="100%"/>
<mx:ControlBar>
<mx:TextInput id="msg" width="100%" enter="send()"/>
<mx:Button label="Send" click="send()"/>
</mx:ControlBar>
</mx:Panel>
</mx:Application>
Messaging destinations are configured in a messaging-config.xml in the root of your Flex application. A key element of a destination configuration is the channel used to exchange data between the client and the server. Using BlazeDS, a messaging destination typically uses a streaming or a polling channel.
- Using a streaming channel, the server response is left open until the channel connection is closed, allowing the server to send down incremental chunks of data to the client. HTTP connections are not duplex. This means that a single streaming AMF or HTTP channel actually requires two browser HTTP connections in order to send data in both directions. One for the streamed response from the server to the client that the channel hangs on to, and a second transient connection, drawn from the browser pool only when data needs to be sent to the server. This second transient connection is immediately released back to the browser’s connection pool.
- A polling channel can be configured with a simple interval or with a sever wait if data is not immediately available (long polling). In either case, each poll response completes the request. Browser HTTP 1.1 connections are persistent by default, so the browser will likely recycle existing HTTP connections to send subsequent poll requests, which lowers the overhead for polling.
This article i got as an email from Adobe as adobe flex information..
Hi!
I am trying to make a simple peer-to-peer chat application using flex builder 3. Is it possible to do it without using BlazeDS?
Can i use XML or binary sockets? which are better?
Hi!
I am trying to make a simple private chat application using flex builder 3. Is it possible to do it using BlazeDS or RED5?
Priya,yeah it is possible to build a private chat app wiv flex3 and blazeds,i currently workin on it though am nt done,one way is 2 make us of d producer and consumer components,using d consumer selector property,u can determine who u want 2 recieve a particular message,wat i did is 2 obtain the id of the two people who engaged in a chat at runtime and combine them to form d value for d selector property so that mesages cn b exchangd only btw d 2 people involved.there is more to it though,sure you can figure it out,good luck
Hello webmaster
I would like to share with you a link to your site
write me here preonrelt@mail.ru
kK6BHZ dkyrqqvzrijg, [url=http://pxulppzizgnf.com/]pxulppzizgnf[/url], [link=http://hiojkmqfarjr.com/]hiojkmqfarjr[/link], http://vlsodbvqanlu.com/
Hi! I was surfing and found your blog post… nice! I love your blog.
Cheers! Sandra. R.