Skip to content

rstoyanchev/spring-websocket-portfolio

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
July 28, 2022 07:52
July 11, 2013 08:50
September 16, 2014 13:58
July 28, 2022 07:38

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, Jetty, WildFly, Glassfish, and other Servlet 3.0+ containers with WebSocket support.

Tomcat

For Tomcat, set TOMCAT_HOME as an environment variable and use deployTomcat.sh and shutdownTomcat.sh in this directory.

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

Jetty

The easiest way to run on Jetty is with 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

WildFly 10+

Unzip the WildFly server.

Set WILDFLY_HOME as an environment variable and use deployWildFly.sh in this directory.

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

WebSphere Liberty 16+

Build and deploy with the following server configuration:

<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">
    <!-- Enable features -->
    <featureManager>
        <feature>jsp-2.3</feature>
        <feature>webSocket-1.1</feature>
    </featureManager>
    <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
    <httpEndpoint id="defaultHttpEndpoint"
                  httpPort="9080"
                  httpsPort="9443" />
    <!-- Automatically expand WAR files and EAR files -->
    <applicationManager autoExpand="true"/>
</server>

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. Use the MessageBrokerConfigurer in WebSocketConfig.java to enable the STOMP broker relay instead of the simple broker.
  3. You may also need to configure additional STOMP broker relay properties such as relayHost, relayPort, systemLogin, systemPassword, depending on your message broker. 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