RIA Prototype Client Using BlazeDS Messaging and JMS - J2EE Server
In a previous posting I gave an overview of the dashboard prototype that I created to investigate BlazeDS messaging with Flex clients. This posting focuses specifically on the J2EE application server component. I encourage you to read the prototype overview section of my initial post if you have not done so already to glean an understanding of what this server component does in the prototype.
Server Architecture
The EJB3 server architecture is quite basic and consists of one interface, one enterprise Java Bean (EJB), and one plain old Java object (POJO) value object. ITimer is a local interface that is implemented by the stateless DataGeneratorBean EJB. The DataGeneratorBean takes advantage of EJB timer service in order to generate events at the frequency specified by the client. You can start and stop message generation by calling the startTimer() or stopTimer() methods of the DataGeneratorBean EJB (these are the methods called by the client to start and stop message generation). It should be noted that by default EJB timers are persistent. That is if the timer is running when you shut the application server down it will start up automatically when you start the application server and again.
The MetricsVO value object is used to encapsulate the metrics data. A corresponding MetricsVO object is defined within the Flex client and the [RemoteClass(alias='info.jimboone.MetricsVO')] meta tag is added to the Flex definition object to assist BlazeDS in translating the Java object to/from the ActionScript object . You can view all of the Java EJB source files here.
BlazeDS Configuration
Integration of the J2EE server with BlazeDS occurs in the web.xml file. All that is required here is the definition of the MessageBrokerServlet servlet and a listener that keeps track of the HTTP Flex sessions (HttpFlexSession). This is fairly straightforward and very well documented within the BlazeDS Developers Guide (you can also view the web.xml files in the turnkey applications examples). The complete web.xml file is shown below:
DashboardServer BlazeDS BlazeDS Application flex.messaging.HttpFlexSession MessageBrokerServlet flex.messaging.MessageBrokerServlet services.configuration.file /WEB-INF/flex/services-config.xml 1 MessageBrokerServlet /messagebroker/* index.html index.htm index.jsp
The BlazeDS MessageBrokerServlet is configured by reading the services-config.xml file. This file includes two additional files describing both remoting and messaging destinations. As I have mentioned previously, the remoting channel uses an EJB3 factory to lookup the stateless session bean that will service the remoting request. The following remoting config file shows how easy it is to specify the JNDI name for the session bean that will service all remoting method calls.
ejb
dashboard/DataGeneratorBeanThe BlazeDS messaging destinations are configured in the messaging-config.xml file. There are a plethora of settings that one can specify in this file for the JMSAdapter component. These options are documented clearly in the BlazeDS Developers Guide. The following snippet shows the more interesting configuration details from this file.
5 1000 0 false Topic javax.jms.ObjectMessage java:/ConnectionFactory topic/testTopic NON_PERSISTENT DEFAULT_PRIORITY true AUTO_ACKNOWLEDGE 1
Prerequisites for Running the Prototype
You are more than welcome to download the prototype and experiment with it to yourself. Perhaps the easiest thing to do is to download the ear file and copy it into the JBoss server/default/deploy directory. The ear includes the client swf file so you should be able to open a browser and hit the following URL to access the client: http://localhost:8080/DashboardServer/CustomDashboardMain.html
Obviously, before you do this you need to ensure that the following prerequisites are available:
- Java5 JDK or higher installed
- JBoss 4.2.1 or 4.2.2 (I have not tested with a JBoss 5.X)
- Prototype EAR file
Please note that I have been using the “default” server image that is included in the standard JBoss distribution. This image includes a topic with the JNDI name topic/testTopic. The prototype code base assumes that this topic will be present. If it is not defined in the application server, then you will have to create the topic before the prototype will work.
Experimenting with the Client Code
After you drop the ear file and deploy directory and play around with the client for awhile, things can get pretty boring. You might also want to modify the client code somehow to suit your needs. I have included the Flex Builder 3 project here for download. You can import it into Flex Builder and run the client directly from Flex Builder. That is the beauty configuring your destinations directly in ActionScript. You have effectively decoupled the deployment of client code from the server code. Enjoy!!
3 Comments so far
Leave a reply
[...] Jim Boone’s Blog [...]
great article, thanks
the link for project sources seems to be broken. could you please provide new one?
Piotr,
Sorry about the link. I was pointing to a zip file and WordPress seems to think this is a page. I ended up simply renaming the file with the extension ‘zipfile’ and it now works (rename it to .zip once you download). Unfortunately, I broke the formatting in the XML code by simply editing!! Oh well, so much for a buggy formatting plugin. I don’t have time to mess with it now. Sorry I took so long to get back to you.
Jim