Simple example project that demonstrates using Apache Camel to receive JMS and then publish the messages to a CometD channel, where they are picked up by a web browser(s).
Featured on DZone Javalobby
And on my blog
- You need Java (JDK) and Maven installed and configured
This single demo project will open 3 windows (2 terminals and a browser):
- Terminal window - running an ActiveMQ\Camel server - with a CometD producer
- Web page window - consumes messages from the CometD producer when they become available
- Terminal window - running Java client app - which will fire JMS messages at the Camel server
Running the demo end to end you will see the java app sending messages to ActiveMQ, the Camel route on the ActiveMQ server will pick up the messages and push them to the CometD channel. The web page will pick them up from the CometD channel and display them as they arrive.
-
Open a terminal window and navigate to the project root directory ${ProjectHome}.
-
Type 'mvn clean install' to check it builds ok
- If you have any problems here - check your maven and java installations are ok
-
Type 'mvn camel:run'
- This will spin up the ActiveMQ server - on localhost:61616
- The ActiveMQ server is running Camel, which has a CometD route configured to publish on channel 'cometd://0.0.0.0:9099/broadcastMessageChannel'
- We now need to start up a CometD consumer on this channel....
-
Open the 'comet-test.html' web page in a browser
- this is in ${ProjectHome}/src/main/resources/html/comet-test.html
- this is now consuming on the CometD channel
-
Open a second new terminal window and navigate to the project root directory ${ProjectHome}
- Type 'mvn exec:java'
- This will run a simulation program which will fire JMS messages at the ActiveMQ server
- All being well - you should see them flash up on the comet-test.html page!