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


February 7, 2008 at 4:31 pm
This is a great solution. But what if you wanted to communicate with a data base using messaging? What would you recommend for the ‘middle-man’ to receive the new data from a flex app and then push it out to the subscribing flex app?
February 8, 2008 at 12:15 pm
You can create custom message service adapters.
It is very easy
You just have to extend ServiceAdapter class and override the invoke() method. Check this URL for more information
March 8, 2008 at 11:43 pm
I’d be pretty impressed if you had this working with a dynamic chat list, i.e. a standard chat room. Seems that it’s a little tricky doing this with Blaze (rather than LCDS) when you don’t have access to the [Managed] functionality. It might sound easy, but when multiple users login to the room all at the same time it’s tricky keeping everyone’s chat user list up to date. User timeouts/disconnects are also a problem – I’ve still been unable to detect when a client drops despite trying a few different methods.
March 13, 2008 at 4:09 pm
What do you use if you do not want to use Tomcat as your webserver?
I am forced to use IIS because I am on a DoD networkl. Is there a BlazeDS config for IIS?
Thanks in advance,
Gene
March 14, 2008 at 10:53 am
Hi Gene,
BlazeDS is a J2EE application. You need a servlet container to have BlazeDS running. You can find out how to integrate Java Servlet container in IIS web server. Please check out the URL below for more details on running J2EE apps on IIS.
http://support.microsoft.com/kb/q240842/
March 24, 2008 at 2:42 pm
hey it’s cool but the user list being hard coded is really not sufficient because it should be checking on the server for who is subscribed (online). How would you do that?
March 25, 2008 at 5:15 am
Hi DD,
As we are using BlazeDS. I would expose a method on the server which will give me the list of users online at a particular point of time. I will keep polling to that method and keep getting the latest information of online users.
If any one else has better solutions (with BlazeDS), please share
March 28, 2008 at 4:08 pm
A slightly better solution would be to subscribe to a feed service that “feeds” the current list of usernames. This at least avoids the client having to initiate the update, now it’s one way only.
September 4, 2008 at 2:51 pm
I assume you’re not using Flex 3 and BlazeDS. You have a variable in your messaging-config.xml file that is not supported in Flex 3 BlazeDS. flex.messaging.durability.FileStoreManager That will generate an error when you start the server.
Also, durable=true doesn’t work without JMS
September 17, 2008 at 2:54 pm
Hi!
Do You know, how to do chat with online user list??
I know that I need to use MessageService.getSubscriberIds but
problem is, how to do this?? Could someone help me??
September 18, 2008 at 1:48 pm
Hi Lucas,
I would have exposed a Java method as Remoting destination and let the Java method pass the details required. You can now invoke that Java method from Flex application.
You can also use the session to maintain the list of users logged in. Please find more details on session management at the URL below.
http://sujitreddyg.wordpress.com/2008/05/16/session-data-management-in-flex-remoting/
Hope this helps
January 4, 2009 at 1:58 am
A really dumb question but I’m a total noob to Tomcat. How would you deploy this chat application on the web ? Should you hosting plan include Tomcat ? Or can you install it or something and after that install BlazeDS too ?
Thanks guys.
January 5, 2009 at 6:41 am
Hi,
You need Tomcat to have BlazeDS support. Tomcat or any J2EE container is sufficient to add BlazeDS support.
Hope this helps.
February 22, 2009 at 8:21 pm
Hi sujit,
when i select a user and type in a message and click Send all i get is a popup which says
[object Object]
any idea whats wrong?
April 7, 2009 at 6:50 pm
[...] into modulesSession data management in Flex RemotingMapping Action Script objects to Java objectsMessaging using Flex and Blaze DSBlazeDS and LCDS Feature differenceRendering PDF content in Adobe AIR applicationHandling Java [...]
June 15, 2009 at 6:03 pm
Hi Noel,
try the body property.
June 17, 2009 at 10:53 am
Hi sujit,
when i select a user and type in a message and click Send all i get is a alert saying
[object Object]
i checked in fire bug “http://localhost:8080/samplewebapp/messagebroker/amfpolling” this is giving 404 error.. Is this the reason??
How to solve this
June 17, 2009 at 9:49 pm
Hi Ravi,
What is that you are passing to the show function of the Alert class? make sure you pass the right property, body is the property which has the data returned.
Hope this helps.
June 19, 2009 at 4:49 pm
Hi,
how could we get all subscribed users? I saw “getSubscriberIds” in the javadoc but have no clue how to use it yet. Some help would be very very very nice, please
July 6, 2009 at 1:51 pm
Hi
Nice article.
I tried setting up the chat application and it showed up the UI fine, but the message is not getting sent.
I get an exception:
**** MessageBrokerServlet failed to initialize due to runtime exception: Exception: flex.messaging.config.ConfigurationException: Unrecognized tag found in . Please consult the documentation to determine if the tag is invalid or belongs inside of a different tag:
‘/jms’ in destination with id: ‘chatApplication’ from file: messaging-config.xml
at flex.messaging.config.MessagingConfiguration.reportUnusedProperties(MessagingConfiguration.java:682)
at flex.messaging.MessageBrokerServlet.init(MessageBrokerServlet.java:160)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4045)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4351)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Jul 6, 2009 1:50:01 PM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet MessageBrokerServlet as unavailable
Jul 6, 2009 1:50:01 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /BlazeDSPOC threw load() exception
javax.servlet.UnavailableException: Unrecognized tag found in . Please consult the documentation to determine if the tag is invalid or belongs inside of a different tag:
‘/jms’ in destination with id: ‘chatApplication’ from file: messaging-config.xml
at flex.messaging.MessageBrokerServlet.init(MessageBrokerServlet.java:170)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4045)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4351)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Jul 6, 2009 1:50:01 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Jul 6, 2009 1:50:01 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Jul 6, 2009 1:50:01 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/31 config=null
Jul 6, 2009 1:50:01 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 4300 ms
Please help.
Thanks
Priya
July 6, 2009 at 1:51 pm
Hi
Nice article.
I tried setting up the chat application and it showed up the UI fine, but the message is not getting sent.
I get an exception:
**** MessageBrokerServlet failed to initialize due to runtime exception: Exception: flex.messaging.config.ConfigurationException: Unrecognized tag found in . Please consult the documentation to determine if the tag is invalid or belongs inside of a different tag:
‘/jms’ in destination with id: ‘chatApplication’ from file: messaging-config.xml
at flex.messaging.config.MessagingConfiguration.reportUnusedProperties(MessagingConfiguration.java:682)
at flex.messaging.MessageBrokerServlet.init(MessageBrokerServlet.java:160)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4045)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4351)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Jul 6, 2009 1:50:01 PM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet MessageBrokerServlet as unavailable
Jul 6, 2009 1:50:01 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /BlazeDSPOC threw load() exception
javax.servlet.UnavailableException: Unrecognized tag found in . Please consult the documentation to determine if the tag is invalid or belongs inside of a different tag:
‘/jms’ in destination with id: ‘chatApplication’ from file: messaging-config.xml
at flex.messaging.MessageBrokerServlet.init(MessageBrokerServlet.java:170)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4045)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4351)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Jul 6, 2009 1:50:01 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Jul 6, 2009 1:50:01 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Jul 6, 2009 1:50:01 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/31 config=null
Jul 6, 2009 1:50:01 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 4300 ms
Please help.
Thanks
Priya
July 20, 2009 at 8:22 pm
Hi daslicht,
Please check if the article at the URL below
http://sujitreddyg.wordpress.com/2008/08/14/sending-messages-from-java-to-blazeds-destinations-using-messagebroker/
Hope this helps.
July 20, 2009 at 9:13 pm
Hi Priya,
Looks like your messaging-config.xml contains tags which are not allowed. Please try removing the tag creating problem and restart your server.
Hope this helps.
July 22, 2009 at 6:23 pm
Hi, Sujit. I also like to know how to get all the online (subscribed) users in real time. Is is possible to achieve this from the client side instead of having to call a java method from the server side constantly to update the subscribers information.
If java methods have to be used, what information should I send to the client? I have read your article about sending messages from server to client but still have no idea about how to tackle this problem.
It’d be great if you can give us a more detailed explaination about this.
Thanks for your help
Regards,
Yang
August 20, 2009 at 10:28 pm
Hello folks, well i am a little confused about the use of Flex and java, this is my problem: My java application must read two .zip files from an online server. These classes will load and parse the data in a Thread and perform certain actions depending on such info. The problem occurs when my flex application calls the java method that queries such data. I need to WAIT until the loading has finished. Any ideas?
Another doubt is if the Java classes are being compiled and transformed into some form of ActionScript classes.
Maybe I’m lost in space, so please I need a light in the darkness, thank you.
August 28, 2009 at 7:54 pm
Hi Christian,
Java classes are not converted to AS3 directly. AMF is the format used to represent the objects to transfer between server and Flash Player. You can try not returning from the class invoked until your zip files are downloaded. You can also try pushing the data to the client when the data is ready as explained in this URL http://sujitreddyg.wordpress.com/2008/08/14/sending-messages-from-java-to-blazeds-destinations-using-messagebroker/
Hope this helps.
September 3, 2009 at 7:41 am
Hi Sujit,
Each time I click the button I am getting the error
“Destination CreatingRpc either does not exist….”
I know the error is quite informative but I am not able to figure out what went wrong. Would u please help me out… Thanks in advance.
remote-config.xml
___________________
org.user.UserService
application
services-config.xml
___________________
false
true
4
Thanks,
Arun
September 3, 2009 at 7:45 am
remote-config.xml
——————
<?xml version=”1.0″ encoding=”UTF-8″?>
<service id=”remoting-service” class=”flex.messaging.services.RemotingService”>
<adapters>
<adapter-definition id=”java-object” class=”flex.messaging.services.remoting.adapters.JavaAdapter” default=”true”/>
</adapters>
<default-channels>
<channel ref=”my-amf”/>
</default-channels>
<destination id=”CreatingRpc”>
<properties>
<source>org.user.UserService</source>
<scope>application</scope>
</properties>
<adapter ref=”java-object”/>
</destination>
</service>
“Channel” part of the services-config.xml
_________________________________________
<channels>
<channel-definition id=”my-amf” class=”mx.messaging.channels.AMFChannel”>
<endpoint url=”http://localhost:8080/blaze/messagebroker/amf” class=”flex.messaging.endpoints.AMFEndpoint”/>
</channel-definition>
<channel-definition id=”my-secure-amf” class=”mx.messaging.channels.SecureAMFChannel”>
<endpoint url=”http://localhost:8080/blaze/messagebroker/amfsecure” class=”flex.messaging.endpoints.SecureAMFEndpoint”/>
<properties>
<add-no-cache-headers>false</add-no-cache-headers>
</properties>
</channel-definition>
<channel-definition id=”my-polling-amf” class=”mx.messaging.channels.AMFChannel”>
<endpoint url=”http://localhost:8080/blaze/messagebroker/amfpolling” class=”flex.messaging.endpoints.AMFEndpoint”/>
<properties>
<polling-enabled>true</polling-enabled>
<polling-interval-seconds>4</polling-interval-seconds>
</properties>
</channel-definition>
</channels>
No other XML files is modified and the flash part is a copy paste from your blog source.
Regards,
Arun
September 7, 2009 at 6:52 pm
Hi Arun,
Please check if your Flex Builder project is pointing to right configuration file and try running a clean command on your Flex project. Also restart your server.
Hope this helps.
October 27, 2009 at 7:31 am
Question:
when i select a user and type in a message and click Send all i get is a popup which says
[object Object]
Answer:
Suppose you have object Message(title,content,responseTime)
You setup the AsyncMessage as follow in the PRODUCER:
var aMsg:AsyncMessage=new AsyncMessage();
msg.body.title= txtTitle.text;
msg.body.content=txtContent.text;
msg.body.responseTime=txtResponseTime.text;
….
producer.send(msg);
You’ll read AsyncMessage as follow in the CONSUMER:
strTitle = msg.body.title;
strContent = msg.body.content;
strResponseTime = msg.body.responseTime;
This works for me, but I feel annoying if you want to send an object which contains several objects inside it, the setup and reading information procedure is not fun at all. I wish Adobe help us the “body” attribute in AsyncMessage as Object class in Java.
Tuyen Nguyen