Easy Messaging with STOMP over WebSockets using Apollo

About Andrey Redko

In my previous post I have covered couple of interesting use cases implementing STOMP messaging over Websockects using well-known message brokers, HornetQ and ActiveMQ. But the one I didn’t cover is Apollo as in my own opinion its API is verbose and not expressive enough as for a Java developer. Nevertheless, the more time I spent playing with Apollo, more convinced I became that there is quite a potential out there. So this post is all about Apollo.

The problem we’re trying to solve stays the same: simple publish/subscribe solution where JavaScript web client sends messages and listens for a specific topic. Whenever any message is received, client shows alert window (please note that we need to use modern browser which supports Websockets, such as Google Chrome or Mozilla Firefox).

Let’s make our hands dirty by starting off with index.html (which imports awesome stomp.js JavaScript library):

<script src="stomp.js"></script><script type="text/javascript">    var client = Stomp.client( "ws://localhost:61614/stomp", "v11.stomp" );    client.connect( "", "",        function() {            client.subscribe("/topic/test",                function( message ) {                    alert( message );                },                 { priority: 9 }             );            client.send("/topic/test", { priority: 9 }, "Pub/Sub over STOMP!");        }    ); </script>

Source : http://www.javacodegeeks.com/2013/09/easy-messaging-with-stomp-over-websockets-using-apollo.html

Back to Top