aims
Achieve a WebSocket service center, the level of support extended
Technology stack
SpringBoot、Netty、JDK8、MySQL、Redis、RabbitMQ、MyBatis-Plus
Environment to build
The main function points Description
WebSocket connection requires authentication
Token server provides an interface to obtain, first obtain the token before WS connection
Certification information provided by the server
Http interface request requires authentication
The interface in general is pushing Interface
Follow-up can also be made to push record query interface
Support single push
According to registration information, query the user to perform push
Support batch Push
According to registration information, query the user to perform push
MQ supports asynchronous push
Support for regular push
Push the log record
Record Connection Log
Support cluster deployment
Code design
WebSocket connection requires authentication
Develop a http interface is used to obtain authentication header, WebSocket up at the time of registration, registered only allowed with the correct authentication header, the server
- Related design
- A saved authentication information table: reg_user
- Http obtain a token of the interface
- A token judge the legality of the Service layer method
- reg_user table structure
- Core logic
- Once the authentication request by the token stored Redis and set an expiration time of Key
- Check the time by querying Redis achieved, as long as there is this token as a Key value pairs exist, say what legal token
- To be perfect
- Certification authority is not precise enough, only do identity, not to fine access control
- On account of the allocation of the access side, there needs to be manually
- Password authentication information is stored in plain text
Http interface request requires authentication
- Preparation of a filter for an interface requires authentication, the token acquisition request header, validity checking
MQ Asynchronous Transmission
- As consumers, consumer asynchronous request
- As a producer, by broadcasting the call
- fanout broadcast mode
- At the same time you are listening to this broadcast, to ensure that there is at least one consumer
Using JMeter stress test carried out WebSocket
- Install Plug-in Manager
- WebSocket plug-in installation
Core code
Obtain certification token
Check the token is valid
Netty's integration with SpringBoot
- Parameter Type WebSocket able to receive
- When the end of the parameter type with registration WebSocket client
- Push back to the unified parameter types WebSocket client
Push Interface
MQ asynchronous push
Source
This article from the blog article multiple platforms OpenWrite release!