JIRA: https://jira.spring.io/browse/INTSAMPLES-137 * Upgrade to Boot 1.1.7 * Fix several Boot apps to get deal with `args`, e.g. `--debug` option can be useful for Boot * Provide a loca copy for JavaScript files (`sock.js` and `stomp.js`) to avoid extra Internet connection on testing INTS-137-2: Make JavaScript cross-browser Some additional polishing to the server config, like `logging-channel-adapter` for server message flow
2.8 KiB
WebSockets Stomp Chat Sample
This application demonstrates the Web chat based on STOMP WebSocket sub-protocol with Spring Integration Adapters.
Server
The server is presented only with a single org.springframework.integration.samples.websocket.standard.server.Application
class, which is based on the Spring Boot AutoConfiguration and Spring Integration xml configuration @ImportResource.
It is a main and starts an embedded Tomcat server on the default 8080 port.
The WebSocket endpoint is mapped to the /chat path.
The server also can be run from Gradle gradlew :stomp-chat:run
The server application demonstrates how Spring Integration can be used as a STOMP Broker.
webSocketSessionStore- theSimpleMetadataStoreto keep track ofWebSocketSessionand itsuser.chatMessagesStore- theSimpleMessageStoreto store messages for chat rooms.chatRoomSessions- theMap<String, Tuple2<String, String>>to keep track ofWebSocketSessionsubscriptionsto the concrete chat room - STOMPdestination.<int-event:inbound-channel-adapter channel="routeStompEvents">is subscribed to theAbstractSubProtocolEventtype to handle STOMP sub-protocol events.<int:payload-type-router input-channel="routeStompEvents">is mapped to the appropriateAbstractSubProtocolEventtype to provide the specific integration flow for each event type.<int-websocket:inbound-channel-adapter>receives STOMP messages, store them to the appropriatemessageGroup(according to the STOMPdestination) and forward to the<int-websocket:outbound-channel-adapter>to send to eachWebSocketSessionsubscribed to that STOMPdestination- chat room.
Client
The index.html in the src/main/resources/static directory of this project demonstrates a JavaScript STOMP client
over SockJS client.
This application covers classical STOMP scenario:
connect- requirement to enter theuser name- chat member;subscribe- theJoinoperation on the one of chat rooms and receiving messages to that subscription for the destination;sendandreceive- just chat messages;unsubscribe- theLeaveoperation on the chat room: the current web socket session stops receiving messages for the destination;disconnect- close current web socket session and unsubscribe from all its subscriptions.
To get real chat interaction it's just enough to open several tabs in browser. When the user joins to the chat room, his subscription receives all messages, sent by other users to that room, immediately.
Test Case
The org.springframework.integration.samples.chat.stomp.server.ApplicationTests demonstrates the Spring Boot test
framework and just starts Server on the random port to be sure that this application is run correctly.