Extended BlazeDS and JMS example +
We extended the example from the absolutly helpful Blog entry from Michael about BlazeDS and JMS. It demonstrates a flex app using BlazeDS with a message-destination from a JMS Topic using ActiveMQ (separate process).
Installation:
1. Download and install BlazeDS (bundles with Tomcat): blazeds_turnkey from http://opensource.adobe.com/wiki/display/blazeds/Release+Builds
2. Download and install ActiveMQ (4.1.1) from: http://activemq.apache.org/download.html
3. Download the extended example blazetest-extended and extract into your BlazeDS-Turnkey directory.
The interesting BlazeDS configuration files are services-config.xml and messaging-config.xml in tomcat/webapps/BlazeTest/WEB-INF/flex. Also look into the tomcat JNDI resource file BlazeTest.xml in tomcat/conf/Cataline/localhost and in the flex-app itself (test.mxml or test2.mxml, whose only difference is the value of the message selector)
Run example:
1. Start ActiveMQ
2. Start BlazeDS-Tomcat
3. Browse to http://localhost:8400/BlazeTest/
[
]
Screen shot of the example application running in Firefox
What it shows:
It is a simple chat-application that consists of one HTML-page and two Flex-applications. The first Flex-app in the upper part of the window is added twice to the page. The second Flex-app in the lower part also appears twice.
You see, that the browser (tested with FireFox3) does not allow enough HTTP-connections to be opened simoultanously so that most of the Flex-apps need to poll instead of streaming.
A single JMS topic is used to distinguish the chat-messages for both Flex-apps. Message filtering is done with JMS-Message Selectors, a String-property named “RType” in the example, with the value “one” or “two”.
test.mxml
To send a message with a message selector from flex, refer to function sendMessage() in test.mxml (or test2.mxml):

private function sendMessage():void {
var message:AsyncMessage = new AsyncMessage();
message.body = sendTextArea.text;
message.headers = new Array();
message.headers["RType"] = “one”;
producer.send(message);
sendTextArea.text=”";
}
To filter messages received with a message selector, set “selector” attribute in the <mx:Consumer> element:
<mx:Consumer id=”consumer”
destination=”message-destination”
message=”messageHandler(event)”
selector=”RType=’one’”
acknowledge=”acknowledgeHandler(event);”
fault=” faultHandler(event)”/>
Java application using JMS
A Java application (e.g. servlet or EJB) can easily communicate with the same JMS Topic, so that you can send messages to the client applications or listen to messages. The Java application does not need any Blaze-DS library, just plain JMS (and the activemq-libs). There a two simple Java-main() apps: JMSTopicSender and JMSTopicListener.
JMSTopicListener.java
It prints all messages and their properties to the console, that you send to the JMS topic.
JMSTopicSender.java
It sends 100 messages in 200 seconds to the JMS Topic with the message selector set to “one” or “two”. You can see the messages appear in the open flex-apps.
I hope, this example helps you with your own BlazeDS experiments.
TO DO: Tomcat resource for JMS Topic with SonicMQ instead of ActiveMQ
I did not find a way to configure the tomcat JMS-resource (file tomcat/conf/Catalina/localhost/BlazeTest.xml) so that the same example runs with SonicMQ (7.6) instead of ActiveMQ (4.11).
Something alike is included in the BlazeTest.xml file, but it does not work yet. If you have a hint, please send me…
Hi,
I have followed the instructions, but still can’t get the screen as shown above. The browser just show as following:
RType=’one’
RType=’two’
Anything I had missed out?? Any possible errors ? Please correct me.
Looking forward for your help.
Thank you.
Are there any errror messages in the tomcat or activeMQ- consoles? If yes, then send me.
Does your webbrowser have the required Flash-Plugins installed?
Hi,
I got it.
I try the steps as follow:
1) Update the my current browser FireFox to FireFox3
2) Turn off the caching
3) Re-paste the BlazeTest folder into webapps folder.
4) Re-paste the BlazeTest.xml into conf\Catalina\localhost folder.
5) Re-run the steps: ActiveQM –> Tomcat –> http://localhost:8400/BlazeTest/
Then it works!
Inside the folder java-src\BlazeTest\src have 3 Java file – ActiveMQConnecter, JMSTopicSender and JMSTopicListener. Is it i have to compile is to get the .class file and put inside the WEB-INF class folder? But even i compile also got errors. Why can run without the .class file??
Hello,
first, congratulations for the success and thanks for trying and describing the steps.
The 3 java-files don’t belong to the blazeds-webapp. They are just examples of what a java-server-app (like servlet/ejb) could do to publish some messages to the JMSTopic, that the blazeDS-App is using.
The 3 java-files thus demonstrate how an application that has absolutely no dependency to any blazeds-library can publish messages to different destinations and receive messages. We are using this technique to integrate the blazeds-applications with our existing server-product, which is using plain JMS to broadcast events.
If you want to see what happens, compile the 3 classes and run JMSTopicSender and/or JMSTopicListener (both have a main() method). I did so from within my IDE (IntelliJ/Eclipse…).
How to compile?
Put some libs in the classpath: tomcat/webapps/BlazeTest/WEB-INF/lib/*.jar, tomcat/lib/activemq4.1.1/*.jar, javaee.jar (package javax.jms)
Bye,
Roman
[...] public links >> selectors The Fabulous One Saved by misterdeity on Wed 10-9-2008 Extended BlazeDS and JMS example Saved by unpoete on Wed 10-9-2008 Comparing Objective-C selectors Saved by higeorange on Mon [...]
why I can not compile using tomcat/webapps/BlazeTest/WEB-INF/lib/*.jar ?? thx
@timotius : What did you do and what is the error message?
You need tomcat/webapps/BlazeTest/WEB-INF/lib/*.jar, tomcat/lib/activemq4.1.1/*.jar and javaee.jar (package javax.jms) to compile.
[...] public links >> jms The JMS 146: Some Slow Songs First saved by dagoz | 0 days ago Extended BlazeDS and JMS example First saved by gnomadic | 13 days ago JMS Topic First saved by Antrozous | 34 days ago [...]
Hi, I have followed the instructions, try to send a message.
Alert Box error:
Fault: Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Failed: url: ‘http://localhost:8400/BlazeTest/msgbroker/amf’
click “OK” button,
Alert Box error:
Fault: The consumer was not able to subscribe to its target destination.
Anything I had missed out?? Any possible errors ? Please correct me.
Looking forward for your help.
Thank you.
It’s all great, worked for me without any problems.
Also, have you seen a new Flex-BlazeDS-Spring integration ?
http://www.springsource.org/spring-flex
2 things:
1) is something other than chat sample avaliable, something where Flex client consumes ActiveMQ JMS messages, say, TraderDesktop ?
2) how to deploy that sample on JBoss5 ?
TIA,
Oleg.
Hi,
I am trying to deploy that sample to JBoss 5.1.0 and having problems.
Deploying as an exploded archive.
Getting several exceptions starting with:
ERROR [StandardContext] Error starting static Resources
java.lang.IllegalArgumentException:
Document base C:\jboss-5.1.0.GA\server\default\deploy\BlazeTest\WEB-INF\web.xml does not exist or is not a readable directory
at org.apache.naming.resources.FileDirContext.setDocBase(FileDirContext.java:148)
at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4021)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4188)
at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal (TomcatDeployment.java:310)
at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy (TomcatDeployment.java:142)
at org.jboss.web.deployers.AbstractWarDeployment.start(AbstractWarDeployment.java:461)
at org.jboss.web.deployers.WebModule.startModule(WebModule.java:118)
at org.jboss.web.deployers.WebModule.start(WebModule.java:97)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)
That web.xml exists there & readable and is a normal deployment descriptor.
I am fairly new to JBoss5 & BlazeDS.
Just dropped blazeds.war to server/default/deploy without any config changes.
Should I change something in config, like deploy the different web.xml in the ROOT ?
Also, the context XML file which on Tomcat was on: conf/Catalina/localhost dir,
on JBoss I put it in server/default/conf dir. Is it correct place ?
Is that context XML acceptable to JBoss5 or does it JMS require any changes?
I’ve heard JBoss took ActiveMQ5.2 and incorporated there.
That sample run fine on my external ActiveMQ5.2…
Please help !
TIA,
Oleg.
Hi,
I had your app running fine on Tomcat6 turnkey testdrive.
I tried to take a fresh Tomcat6, copied BlazeDS jars there
and moved your app there.
But it didn’t work.
Getting “Fault: null”, “Fault: The consumer was not able to subscribe to its target destination” popups. And MessageTopic is not showing up in ActiveMQ console.
In the Tomcat console see error:
“[BlazeDS] JMS consumer for JMS destination ‘java:comp/env/jms/messageTopic’
is being removed from the JMS adapter due to the following error:
Name jms is not bound in this Context”
I have copied BlazeTest.xml file too. No configuration changes.
In messaging-config: java:comp/env/jms/messageTopic, in Context: <Resource name="jms/messageTopic".
In messaging-config: java:comp/env/jms/flex/TopicConnectionFactory , in Context: Resource name=”jms/flex/TopicConnectionFactory”
Are these name matching ?
Any idea ?
Please help !
TIA,
Oleg.
Sorry, but I would need to investigate into that myself, too. No time to reproduce so far.
hi …
I have also implemented the flex/java integration and stuck up with the following error.
“The consumer was not able to subscribe to its target destination.”
Kindly help me to figure this out.
Shubhajeet