@ -944,7 +944,7 @@ to use in applications along with an annotation programming model for routing an
@@ -944,7 +944,7 @@ to use in applications along with an annotation programming model for routing an
processing STOMP messages from WebSocket clients. As a result an `@Controller`
can now contain both `@RequestMapping` and `@MessageMapping` methods for handling
HTTP requests and messages from WebSocket-connected clients. The new `spring-messaging`
module also contains key abstractions from the
module also contains key abstractions formerly from the
http://projects.spring.io/spring-integration/[Spring Integration] project such as
`Message`, `MessageChannel`, `MessageHandler`, and others to serve as a foundation
for messaging-based applications.
@ -36685,7 +36685,7 @@ and also provides additional value-add as explained in the rest of the introduct
@@ -36685,7 +36685,7 @@ and also provides additional value-add as explained in the rest of the introduct
[[websocket-into-fallback-options]]
==== Fallback Options
==== WebSocket Fallback Options
An important challenge to adoption is the lack of support for WebSocket in some
browsers. Notably the first Internet Explorer version to support WebSocket is
version 10 (see http://caniuse.com/websockets for support by browser versions).
@ -36707,7 +36707,7 @@ modifying the application otherwise.
@@ -36707,7 +36707,7 @@ modifying the application otherwise.
[[websocket-intro-architecture]]
==== Messaging Architecture
==== A Messaging Architecture
Aside from short-to-midterm adoption challenges, using WebSocket
brings up important design considerations that are important to recognize
early on, especially in contrast to what we know about building web applications today.
@ -36734,7 +36734,7 @@ annotation based programming model.
@@ -36734,7 +36734,7 @@ annotation based programming model.
[[websocket-intro-sub-protocol]]
==== Sub-Protocol Support
==== Sub-Protocol Support in WebSocket
WebSocket does imply a __messaging architecture__ but does not mandate the
use of any specific __messaging protocol__. It is a very thin layer over TCP
that transforms a stream of bytes into a stream of messages
@ -36767,7 +36767,7 @@ WebSocket and over the web.
@@ -36767,7 +36767,7 @@ WebSocket and over the web.
[[websocket-intro-when-to-use]]
==== When To Use WebSocket?
==== Should I Use WebSocket?
With all the design considerations surrounding the use of WebSocket, it is
reasonable to ask when is it appropriate to use?
@ -36810,7 +36810,7 @@ WebSocket clients or to a specific user.
@@ -36810,7 +36810,7 @@ WebSocket clients or to a specific user.
[[websocket-server]]
=== WebSocket Server
=== WebSocket API
The Spring Framework provides a WebSocket API designed to adapt to various WebSocket engines.
For example, it runs on JSR-356 runtimes such as Tomcat (7.0.47+), GlassFish (4.0+) and
WildFly (8.0+) but can also adapt to other WebSocket runtimes such as the Jetty (9.1+)
@ -37448,7 +37448,7 @@ log category to TRACE.
@@ -37448,7 +37448,7 @@ log category to TRACE.
====
[[websocket-fallback-cors]]
==== CORS Headers for SockJS Requests
==== CORS Headers for SockJS
The SockJS protocol uses CORS for cross-domain support in the XHR streaming and
polling transports. Therefore CORS headers are added automatically unless the
The WebSocket protocol defines two main types of messages -- text and binary --
but leaves their content undefined. Instead it's expected that client and
server may agree on using a sub-protocol, i.e. a higher-level protocol that defines
@ -37575,7 +37575,7 @@ Spring MVC provides a programming model based on HTTP.
@@ -37575,7 +37575,7 @@ Spring MVC provides a programming model based on HTTP.
[[websocket-stomp-enable]]
==== Enable STOMP (over WebSocket)
==== Enable STOMP over WebSocket
The Spring Framework provides support for using STOMP over WebSocket through
the +spring-messaging+ and +spring-websocket+ modules. It's easy to enable it.
@ -37666,56 +37666,65 @@ sections <<websocket-stomp-handle-broker-relay-configure>> and
@@ -37666,56 +37666,65 @@ sections <<websocket-stomp-handle-broker-relay-configure>> and
[[websocket-stomp-handle]]
==== Overview of STOMP Message Handling
When a STOMP endpoint is configured, the Spring application effectively becomes
the broker to connected clients, handling incoming messages and broadcasting
messages back to them. This part of the documentation describes how STOMP
messages are handled within the application.
As mentioned in the <<websocket-intro-architecture,introduction>> the
`spring-messaging` module contains key abstractions from the
https://spring.io/spring-integration[Spring Integration] project, including
`Message`, `MessageChannel`, `MessageHandler` and a few others.
[NOTE]
====
Spring Integration 4 will be the first version to start using the abstractions
from the package structure of the `spring-messaging` module as opposed to its
own present packages. Spring Integration also provides many additional
abstractions and implementations in support of the well-known
In effect, the broker relay enables robust and scalable message broadcasting.
[[websocket-stomp-handle-broker-relay-configure]]
===== Configuring Connections To The Full-Featured Broker
==== Connections To Full-Featured Broker
A STOMP broker relay maintains a single "system" TCP connection to the broker.
This connection is used for messages originating from the server-side application
@ -38043,7 +38005,7 @@ the TCP connection is established is different from the host providing the
@@ -38043,7 +38005,7 @@ the TCP connection is established is different from the host providing the
cloud-based STOMP service.
[[websocket-stomp-handle-user]]
===== Authentication and Handling Messages to User Destinations
==== Authentication and User Destinations
An application can also send messages targeting a specific user.
@ -38083,8 +38045,10 @@ So in that case the client could subscribe to `/user/exchange/amq.direct/positio
@@ -38083,8 +38045,10 @@ So in that case the client could subscribe to `/user/exchange/amq.direct/positio
ActiveMQ has http://activemq.apache.org/delete-inactive-destinations.html[configuration options]
for purging inactive destinations.
[[websocket-stomp-testing]]
===== Testing Message Handling Controllers
==== Testing Annotated Controller Methods
There are two main approaches to testing applications using Spring's STOMP over
WebSocket support. The first is to write server-side tests verifying the functionality