Skip to content

cogdachris/spring-websocket-portfolio

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

A sample demonstrating capabilities in the Spring Framework to build WebSocket-style messaging applications. The application uses STOMP (over WebSocket) for messaging between browsers and server and SockJS for WebSocket fallback options.

Client-side libraries used:

Server-side runs on Tomcat 8, Jetty 9.0.4, or Glassfish 4.0. Other servlet containers should also function correctly via fallback options (assuming Servlet 3.0) but they don't support WebSocket yet.

Also see the blog post introducing these features.

Tomcat 8

At present Tomcat 8 is available as snapshots only (alpha release is forthcoming). Spring Framework 4.0 M2 release has been tested with tomcat-8.0-20130718.155757-5. When using a more recent snapshot, you may also have to switch to Spring Framework 4.0.0.BUILD-SNAPSHOT.

After unzipping Tomcat 8, set TOMCAT8_HOME as an environment variable and use deployTomcat8.sh and shutdownTomcat8.sh in this directory.

Open a browser and go to http://localhost:8080/spring-websocket-portfolio/index.html

Jetty 9

The easiest way to run on Jetty 9.0.4:

mvn jetty:run

Open a browser and go to http://localhost:8080/spring-websocket-portfolio/index.html

Note: To deploy to a Jetty installation, add this to Jetty's start.ini:

OPTIONS=plus
etc/jetty-plus.xml
OPTIONS=annotations
etc/jetty-annotations.xml

Glassfish

After unzipping Glassfish 4 start the server:

<unzip_dir>/glassfish4/bin/asadmin start-domain

Set GLASSFISH4_HOME as an environment variable and use deployGlassfish.sh in this directory.

Open a browser and go to http://localhost:8080/spring-websocket-portfolio/index.html

Using a Message Broker

Out of the box, a "simple" message broker is used to send messages to subscribers (e.g. stock quotes) but you can optionally use a fully featured STOMP message broker such as RabbitMQ, ActiveMQ, and others, by following these steps:

  1. Install and start the message broker. For RabbitMQ make sure you've also installed the RabbitMQ STOMP plugin. For ActiveMQ you need to configure a STOMP transport connnector.
  2. Comment in the stomp-broker-relay profile and comment out the simple-broker profile in DispatcherServletInitializer.java.
  3. You may also need to configure one or more StompBrokerRelayMessageHandler properties (relayHost, relayPort, systemLogin, systemPassword) in WebConfig.java depending on how your message broker is configured. The default settings should work for RabbitMQ and ActiveMQ.

Logging

To see all logging, enable TRACE for org.springframework.messaging and org.springframework.samples in log4j.xml.

Keep in mind that will generate a lot of information as messages flow through the application. The QuoteService for example generates a lot of messages frequently. You can modify it to send quotes less frequently or simply comment out the @Scheduled annotation.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published