Flex Data Services – Part 2 Messaging
DIGG IT!
3
Comments
Published
Monday, June 19, 2006
at
4:58 PM
.
Messaging is a new feature of Flex Data Services and it happens to be one of my favorites. Messaging allows many clients and many servers to exchange messages in real-time. For me, messaging provides a simple distributed event model that allows to make applications work seamlessly together.
Messaging is simple to understand. Your application publishes messages (objects) to the server and the server delivers the message(object) to any application subscribed. So lets get started.
First some definitions:
Consumer – A Class Instance that:
a. Subscribes to messages at a destination
b. Processes messages when they arrive from the destination.
Producer – A Class Instance that:
a. Sends messages to a destination.
Destination – The location on the server where messages are processed.
<mx:Consumer
id=”myConsumer”
destination=”MyFirstDestination” />
<mx:Producer
id=”myProducer” destination=”MyFirstDestination” />
Step 1: Subscribing to a destination with a Consumer
myConsumer.subscribe()
Step 2: Listening for messages on a Consumer
myConsumer.addEventListener( MessageEvent.MESSAGE , messageHandler )
or
<mx:Consumer
id=”myConsumer”
destination=”MyFirstDestination”
message=”messageProcessor(event)”
fault=”faultProcessor(event)” />
Step 3: Sending a message with a Producer:
var message:AsyncMessage = new AsyncMessage();
message.body = “My First Message”;
myProducer.send( message );
The pattern of messaging is very easy to understand, messages are sent and delivered. Where this gets interesting is when objects are used within the message body like so:
var message:AsyncMessage = new AsyncMessage();
message.body = { a:1 , b:’Hello’ , c:true };
myProducer.send( message );
In this case, we send a complex object to the destination and whoever is listening with a Consumer will get the message.
FDS Messaging also supports durable messaging. Durability makes sure that messages are delivered. It works like certified mail, where the every client must confirm that they received the message to make sure everyone got it. You do not need to do anything but change the durability property on the Consumer Class.
FDS Messaging supports 2 types of messaging on the server side where each type is simply exposed as a destination. The server supports ActionScript Messaging and JMS Messaging. ActionScript Messaging only supports clients who can speak AMF and support the necessary classes to work properly. Java Message Service Messaging allows FDS to participate in the JMS messaging service and interact with any JMS client. Any application that can talk to JMS, can be called directly from a Flex client and any java application can publish events to Flex. JMS Messaging is pretty powerful stuff and makes FMS Messaging very scalable and very extensible.
Currently browsing the Internet is a fairly lonely experience. You know there are 100-10,000 other users looking at the same page but no one can interact and cooperate. Messaging allows Flex clients to interact with one another by listening and creating distributed events. These events can trigger sending an email, receiving an email from a webmail service, check product inventory, return SQL results, send your game coordinates to an opponent, co-browsing with a friend, or simply log data to the server. The key is that messaging is a wide open pattern ready to be used for many different purposes. It really is a blast to work with and is really easy develop.
Also my apologies on not getting this posted earlier. My next post will occur much sooner.
Still working on those custom preloaders :)
Enjoy Messaging!
Ted :)

Hey Ted,
thnx for letting me in on that little secret, didnt notice those classes yet :)
However, do you know where i can find more documentation on it?
Greetz EE
I have been trying to connect to a WebLogic JMS Queue using Adobe Flex 2.0.1 and Adobe Livecycle Data Services. I am able to connect to a WebLogic Topic without any problem. However, for some reason, flex is not able to get messages from a WebLogic JMS Queue. I have gone through the documentation (http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&file=messaging_config_103_08.html). The documentation is also light on JMS Queues.
Do I have to do anything different from connecting to a Topic to connect to a Queue?
Hi,
Thanks for giving nice example of FMS.
But I just want to know How can I go with Point to Point Messaging.