this demo use handler chain to filter message and process business.
- start application
- open 127.0.0.1:8083/index.html in browser
- open 127.0.0.1:8083/web/token in new tap
- open 127.0.0.1:8083/web/users in ne tap
- in the index.html tap,click Connect button to use WebSocket
- refresh users tap,the WebSocket session is associate user
- then in users tap,send message to signal user or kick user,the result will show in index.html tap
core: spring boot WebSocket
the config package read properties to init server endpoint.
the handler package defined handler to process event:
MessageHandler:
accept all event and distribute them to another handler
MessageSelectorHandler:
deal with OnMessage event
OpenCloseHandler:
deal with connection is opened and closed event
you can define specify handler to process different even in MessageHandler class
define the message process bean,like servlet filter. specify filter handle specify message. all message must be subClass of Message. the message type and filters define in application.properties.
- client connect
- server invoke MessageHandler
- MessageHandler invoke MessageSelectorHandler
- MessageSelectorHandler init BusinessFilterChain,
- filter chain process message
- result send to client