Based SpringBoot + Netty implement its own push service system

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

image-20191209160801307

  • 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

image-20191209210053902

Check the token is valid

image-20191209210156135

Netty's integration with SpringBoot

image-20191209210242588

  • Parameter Type WebSocket able to receive

image-20191209210341387

  • When the end of the parameter type with registration WebSocket client

image-20191209210406070

  • Push back to the unified parameter types WebSocket client

image-20191209210446737

Push Interface

image-20191209210541866

MQ asynchronous push

image-20191209210609700

Source

Source

This article from the blog article multiple platforms OpenWrite release!

Guess you like

Origin www.cnblogs.com/sherrykid/p/12013479.html