Using Spring 4 WebSocket, sockJS and Stomp support to implement two way server client communication

Develop and Conquer

One exciting new feature of Spring 4 is the support for WebSocket, SockJS and STOMP messaging. This allows two way communication between the server and its clients in a Spring MVC web application using the standard point-to-point and publish-subscribe messaging protocols. In this post, I will demonstrate how to set up a basic boilerplate project to start using this new feature. It is in part based on this article.

Maven Setup

First we need to add the Spring messaging modules in the POM file:


Spring MVC Configuration

Next, we need to add the message broker config to the Spring MVC config XML file.

<websocket:message-broker application-destination-prefix="/app">
       <websocket:stomp-endpoint path="/hello">
       <websocket:simple-broker prefix="/topic"/>
<!-- Other MVC config omitted here-->

The main thing here is the set up of the message broker for…

View original post 518 more words