BlazeDS & Flex & LiveCycle DS & Tutorials 14 May 2008 07:07 am
BlazeDS Tutorial – Message Service
This article is applicable to LiveCycle DS, LiveCycle DS Express, and BlazeDS.
Message Service is one of the key features in LiveCycle DS and BlazeDS. It enables Flex clients to communicate in your enterprise infrastructure with zero-coding on the server side.
Based on the publisher-subscriber model, the Message Service acts as a message router for both Flex and JMS-enabled clients. This article shows you how to leverage the Message Service in your Flex applications.
The conceptual diagram below demonstrates the message flow. It also covers some basic lingoes you need to know,

The Message Producer and Message Consumer could be either Flex apps or JMS enabled Java clients. The Service Destination is the message routing service residing on the server. Channel is the communication protocol between server and client. There are a variety of protocols you could use based on your infrastructure and project requirements.
Configuring the Server Side
The message service configuration file, messaging-config.xml, resides under the WEB-INF/flex directory.
Within the configuration file, Adapter node determines what type of clients could participate in the service.
- The ActionScript Adapter supports messaging between Flex/Flash clients only. It is the default adapter setting.
- The JMS Adapter accepts messaging from both Flex and JMS-enabled clients.
- Custom messaging adapter could be created by extending the MessagingAdapter class on the server.
To create a messaging service, you need to add a destination node in messaging-config.xml,
[code lang="xml"]
[/code]
The messaging clients will publish and subscribe to the destination by referring to its id attribute.
The messaging service is free to use a variety of channel protocols defined in services-config.xml. The most commons ones are,
- my-rtmp for server-pushed messaging. It’s a lot more responsive compare to polling, but it does not work if the client is behind a web proxy. Note that RTMP is not supported in BlazeDS.
- my-polling-amf for client-pulled messaging. It’s not the most efficient, but it doesn’t have the client side proxy limitation.
- It’s also possible to create a secure polling-amf channel in services-config.xml
You can fine tune your message destination with a rich set of property settings,
[code lang="xml"]
[/code]
Coding on the Client Side
To start using the messaging service, the basic rules are,
- Messages flow from producers to consumers, via a message destination
- Each message destination could have multiple producers and consumers
- Each Flex client could instantiate multiple producers and consumers
To create a message producer, just specify the destination id,
[code lang="xml"]
[/code]
To publish a message,
[code lang="actionscript"]
private function pub():void
{
var message:AsyncMessage = new AsyncMessage();
message.headers.myCustomHeader = "hello header";
message.body = "hello flex message service!";
producer.send(message);
}
[/code]
To create a message consumer, supply the destination id along with a message handler,
[code lang="xml"]
[/code]
To handle an incoming message,
[code lang="actionscript"]
private function onMsg(event:MessageEvent):void
{
trace(event.message.body);
}
[/code]
Finally, bind the consumer to the destination,
[code lang="actionscript"]
private function init():void
{
consumer.subscribe();
}
[/code]
Note: you could put complex data types into the message body, such as collection data types, as long as the consumer could parse it properly.
See attached for the sample code used in this article.
Flex Message Service Sample Code
Need to bring your Flex project up to speed? Zee Yang is a freelance Flex developer with deep understanding of architecture and user experience. You can reach him at zee.yang@gmail.com.

on 20 May 2008 at 5:50 am 1.FlexLive.net » BlazeDS Tutorials said …
[...] BlazeDS Messaging Service – The Message Service has to be the coolest and most under-used feature. I’ve seen a lot of Flex solutions out there that could benefit from the Messaging Service. Check out if it’s the right solution for you. [...]
on 04 Jul 2008 at 1:44 pm 2.Alejandro said …
Great Article Zee! thanks a lot. Just one quick question when you say “you could put complex data types into the message body, such as collection data types, as long as the consumer could parse it properly.” it means that i could push an array for example?
I want to push a message to a flex app that displays the message from the user and his IP address into a datagrid. I can push the simple message just fine, but i was wondering about more complex structures.
Thanks!
on 17 Dec 2009 at 7:59 am 3.Derrick said …
It looks like some of the page formatting may have gotten lost over time. I was trying to look at this, but there’s nothing to see inside some of the code blocks.
Thanks!
on 05 Feb 2010 at 4:14 am 4.abhishek said …
Hey
Can u post any example here in which asp.net web service push data to flex client using fluorinefx…
Its urgent….
reply asap
take care…
on 15 Mar 2010 at 11:49 am 5.Glen said …
Does the “push” has to be message (or JMS) based? Can we do “push” in BlazeDS with just a general
event (e.g., click a Button form one of the clients)?