Demo: JBoss A-MQ, Websockets/HTML5, and Gordon Gecko

Back in early 2013, Eric Schabell, a Red Hat JBoss evangelist, created a cool JBoss A-MQ demo based on HTML5 websockets. You can see the YouTube demo here and access the JBoss Github repo for the demo here.

I wanted to work through it myself; only, it didn’t work for me out of the box. I fixed it and submitted a pull request, but while we’re waiting for the JBoss folks to accept the PR (’cause you know they should!), you can use the changes on my fork. Plus, I’ll help you out if you hit issues (I’m a consultant, you know…). But let’s walk through the demo for fun and clarification.

Running the demo

The README in the demo repo has all the nitty gritty details you need, but you might want an overview first since it’s a little more involved than just firing up a web application.

  1. Download a recent copy of JBoss A-MQ 6.1 from the JBoss Developer site and copy it to the “installs” directory — even if you already have A-MQ installed.
  2. Run the init.sh script to build all the artifacts you need and to provision the A-MQ installation correctly.
  3. Start the “feeder” standalone client, which will start putting stock price (and news) messages on JMS topics.
  4. Install the Websocket OSGI features as well as the demonstration web app.

What it looks like when you stay on the demonstration’s happy path

You’ll start the Karaf command-line client (from target/{amq_version}/bin).

a-mq-karaf

After installing the websocket application, you’ll see installed near the end of the osgi:list:

a-mq-demo-webapp-installed

Next, you’ll start your feeder application from the support directory (support/start_feeder.sh). You should start seeing messages flowing into the A-MQ topic such as the following:

feeder-updates

Finally, you’ll load up a web browser and start seeing messages flowing through websockets to update web stock prices dynamically:

a-mq-demo-client

What the demonstration does under the hood

The demonstration shows really well, but you’re probably interested in what’s happening under the hood and how it may (or may not) apply to the work you actually do.

How the demonstration initialization script provisions the A-MQ server

First of all, you might bristle a little at the init script. Let’s talk about what it does because it’s not as black box or magical as it might appear.

  1. It unpacks the JBoss A-MQ installation you downloaded and puts it in the target directory.
  2. It copies over some configuration files. These files mostly just add security accounts so the feeder and client UI can interact.
  3. It runs Maven builds on the feeder and web UI clients so you can (a) run the feeder script and (b) install the web application and websocket features.

The Java code for the message producer and consumers

There are two Java applications that ship with the demo. The “feeder” application puts fake stock and news updates on two JMS topics: stockQueueTopic and newsTopic. The following is just a snippet from FeedThread on how the feeder applcation accesses A-MQ and the topics I just mentioned:

The Websocket-based client code uses the STOMP protocol through Jeff Mesnil’s stomp.js client code. One you login, it starts sending websocket frames to populate the screen I showed you above.

a-mq-demo-websocket-frames

Cool, huh? You might bump into issues out there, so let me know what we can do to improve it.

Leave a Reply

Your email address will not be published. Required fields are marked *