Disclosure of Invention
In order to realize the instant pushing of alarm information, the invention provides an alarm information pushing method, which comprises the steps that a server and a client are connected by WebSocket; the method comprises the steps that a server obtains user information of a client, and a connection management relationship of a user and WebSocket connection between the server and the client is established according to the user information; the server receives alarm information; the server acquires push WebSocket connection corresponding to the user matched with the alarm information from the connection management relationship, and pushes the alarm information to the corresponding push client according to the push WebSocket connection.
Further, establishing a connection management relationship according to the user information to establish a connection management relationship list; the connection management relationship list stores user information of the user and WebSocket connection between the server and the client corresponding to the user.
Further, the obtaining the user information of the client is: and acquiring user information from the httpress session.
Further, the method further comprises: the server sets an initial weight value of the user according to a preset initial weight value configuration strategy; the server pushes alarm information to the pushing client once every time, and the weight value of the user corresponding to the pushing client is reduced by 1; the server receives a feedback result of the pushing client for processing the alarm information; when receiving alarm information processed by the pushing client, adding 1 to a weight value of a user corresponding to the pushing client; and the server compares the weight value of the user with the preset weight value every preset time period, and if the weight value of the user is smaller than the preset weight value, the WebSocket connection between the client corresponding to the user and the server is disconnected.
Further, the method further comprises: the server receives a feedback result of the pushing client for processing the alarm information; if the pushing client side processes the alarm information, updating the processing state of the alarm information stored in the server, and pushing the updated alarm information to the pushing client side.
The present invention also provides a server, the server comprising: the receiving module is used for receiving the alarm information and receiving feedback results of the push client side for processing the alarm information; the connection management relation creation module is connected with the receiving module and used for creating a connection management relation according to the user information and the WebSocket connection between the server and the client; the alarm information pushing module is connected with the receiving module and the connection management creating module and is used for acquiring pushing WebSocket connection corresponding to the user matched with the alarm information according to the connection management relation and pushing the alarm information to the corresponding pushing client according to the pushing WebSocket connection.
Further, the server further includes: the user weight management module is connected with the alarm information pushing module and is used for setting an initial weight value of a user according to a preset initial weight value configuration strategy and adjusting the weight value of the user according to a feedback result of the alarm information processing of the pushing client and the alarm information pushing condition; the WebSocket connection management module is connected with the user weight value management module and is used for disconnecting the WebSocket connection between the client corresponding to the user and the server when the weight value of the user is lower than a preset weight value.
The invention also provides a client, which comprises: the user information sending module is used for sending user information to the server; the alarm information receiving module is connected with the user information sending module and used for receiving the alarm information of the server; the alarm information storage module is connected with the alarm information receiving module and is used for storing alarm information and updating the processing state of the alarm information after the client side processes the alarm information; and the alarm information processing result feedback module is connected with the alarm information storage module and is used for sending the processing result of the client processing the alarm information to the server.
Further, the client further includes: the alarm information processing state updating module is connected with the alarm information storage module and is used for judging whether the alarm information is in the alarm information storage module after receiving the alarm information of the server; if the alarm information is stored in the alarm information storage module, judging whether the processing state of the alarm information is the same as the processing state of the alarm information stored in the alarm information storage module, and if the processing state of the alarm information is different from the processing state of the alarm information stored in the alarm information storage module, updating the processing state of the alarm information stored in the alarm information storage module; and if the alarm information is not stored in the alarm information storage module, storing the alarm information in the alarm information storage module.
The invention also provides an alarm information pushing system, which comprises a server and a client, wherein: the server is connected with the client by adopting a WebSocket, and is used for receiving the alarm information, acquiring the user information of the client, establishing a connection management relationship of the user and the WebSocket connection between the server and the client according to the user information, acquiring a push WebSocket connection corresponding to the user matched with the alarm information according to the connection management relationship, and pushing the alarm information to the corresponding push client according to the push WebSocket connection; and the client is used for sending the user information to the server, receiving and storing the alarm information of the server and updating the processing state of the alarm information.
According to the alarm information pushing method, after the server receives the alarm information, the alarm information can be timely pushed to the client, the client does not need to send a request to the server, whether the server generates a new message or not is inquired, and network resources are saved. The alarm information pushing method provided by the invention can accurately push the alarm information to an administrator with processing authority for the alarm information, and realizes accurate pushing. The client provided by the invention can also update the state of the alarm information in each client in real time according to the processing result of the alarm information, and when a plurality of administrators exist and can process the alarm information, one of the administrators processes and then updates the state of the alarm information of each client, thereby avoiding the repeated processing of other administrators and wasting resources.
Detailed Description
The terms and expressions used in the description of the present invention are used as examples only and are not meant to be limiting. It will be appreciated by those skilled in the art that numerous changes may be made to the details of the above-described embodiments without departing from the underlying principles of the disclosed embodiments. The scope of the invention is, therefore, to be determined only by the following claims, in which all terms are to be understood in their broadest reasonable sense unless otherwise indicated.
In one embodiment of the present invention, as shown in fig. 1, a method for pushing alarm information is provided:
step S101: and the server establishes WebSocket connection with the client.
WebSocket is a protocol that performs full duplex communication over a single TCP (transmission control protocol ) connection. WebSocket makes data exchange between the client and the server simpler, and allows the server to actively push data to the client. The browser and the server only need to complete one handshake, and can directly establish persistent connection and perform bidirectional data transmission between the two. Through the establishment of the WebSocket connection, the server can actively push alarm information to the client. The client is not required to send a request to the server, so that network resources are saved.
Step S102: the server acquires user information of the client, and establishes a connection management relationship of the user and the WebSocket connection between the server and the client according to the user information.
Specifically, the server may establish WebSocket connection with a plurality of clients at the same time, and after establishing connection, the server obtains user information logged in each client, and establishes a connection management relationship of the user and WebSocket connection between the server corresponding to the user and the client according to the obtained user information. When the alarm information is conveniently pushed, a user matched with the alarm information and WebSocket connection corresponding to the user can be found in time according to the alarm information, so that the alarm information is pushed out.
Step S103: the server receives the alarm information.
Monitoring is carried out in real time by the monitoring equipment, after an event needing to carry out alarming is monitored, alarm information is sent to the server, and subsequent alarm information pushing work is carried out after the server receives the alarm information sent by the monitoring equipment.
Step S104: the server acquires push WebSocket connection corresponding to the user matched with the alarm information from the connection management relationship, and pushes the alarm information to the corresponding push client according to the push WebSocket connection.
Specifically, the received alarm information includes an item to which the alarm information belongs and a corresponding item manager, a user who has permission to process the alarm information is determined according to the item and the item manager, a WebSocket connection corresponding to the user is found from an established connection management relationship according to the determined user who has permission to process the alarm information, the WebSocket connection found at this time is a push WebSocket connection, and the alarm information is pushed to a corresponding push client according to the push WebSocket connection. The above-mentioned push WebSocket connection refers to WebSocket connection between a server and a client corresponding to all users having authority to process the alarm information found in the connection management relationship. The pushing clients refer to clients corresponding to the pushing WebSocket connections, namely clients logged in by an administrator with authority to process the alarm information.
In yet another embodiment of the present invention, establishing a connection management relationship according to the user information is establishing a connection management relationship list; the connection management relationship list stores user information of the user and WebSocket connection between the server and the client corresponding to the user. The user information of the user is user ID information.
In yet another embodiment of the present invention, the obtaining the user information of the login client is: and acquiring user information from the httpress session.
Specifically, after the user logs in successfully, the server establishes a session object for each user, and meanwhile, the server allocates a unique ID, namely a user ID, for each session, and the session always exists before the user logs out of the login, and the server always maintains the session. When the client initiates the WebSocket connection, ID information stored in session is directly obtained from the connection request so as to identify the user, and user data is not required to be sent again when the WebSocket connection is performed, so that user information leakage caused by secondary user information sending is avoided.
In one embodiment of the present invention, as shown in fig. 2, the method further comprises:
step S201: the server sets an initial weight value of the user according to a preset initial weight value configuration strategy;
further, after setting the initial weight value of the user, the initial weight value of the user is stored in a memory database (Redis) of the server, and each user can be represented by using the id+ip address of the user, so that the users can be distinguished. The user ID is an identification code of the user, the user ID of each user is different, and the IP address of the user refers to the Internet address or Internet address of the user. The IP address is a unified address format provided by the IP protocol, which allocates a logical address to each network and each host on the internet, so as to mask the difference of physical addresses.
Step S202: the server pushes alarm information to the pushing client once every time, and the weight value of the user corresponding to the pushing client is reduced by 1;
specifically, the server may find the weight value stored by the user in the in-memory database according to the user id+ip address, and update the weight value.
Step S203: the server receives a feedback result of the pushing client for processing the alarm information;
specifically, the feedback result of the alarm information processed by the client may include read unprocessed, read processed, etc., and may be set as required.
Step S204: when receiving the processed alarm information of the pushing client, adding 1 to the weight value of the user corresponding to the pushing client;
specifically, if the server receives the processed alarm information of a certain push client, the weight value of the user corresponding to the push client is increased by 1.
Step S205: and the server compares the weight value of the user with the preset weight value every preset time period, and if the weight value of the user is smaller than the preset weight value, the WebSocket connection between the client corresponding to the user and the server is disconnected.
Through the process, the weight value of the user processing the alarm information is increased, the weight value of the user not processing the alarm information for a long time is reduced, the weight value of the user is compared with the preset weight value every preset time period by the server, so that the user not processing the alarm information for a long time is screened out, and WebSocket connection between the client corresponding to the users and the server is disconnected in time.
In yet another embodiment of the present invention, the method further comprises: the server receives a feedback result of the pushing client for processing the alarm information; if the pushing client side processes the alarm information, updating the processing state of the alarm information stored in the server, and pushing the updated alarm information to the pushing client side. Because one alarm message may have a plurality of administrators authority to process the alarm message, when one administrator processes the alarm message at the logged-in client, the server updates the state of the stored alarm message and pushes the updated alarm message to the pushing client again, so that all administrators with the authority to process the alarm message can timely learn that the alarm message is processed by other administrators, repeated processing of the alarm message by the administrator due to information asymmetry is avoided, and the manager can comb the alarm message more conveniently.
In one embodiment of the present invention, as shown in fig. 3, a server is further provided, where the server includes a receiving module 301, configured to receive alarm information, and receive a feedback result of processing the alarm information by the push client; the connection management relationship creation module 302 is connected with the receiving module and is used for creating a connection management relationship according to the user information and the WebSocket connection between the server and the client; the alarm information pushing module 303 is connected with the receiving module 301 and the connection management creating module 302, and is configured to obtain a pushed WebSocket connection corresponding to a user matched with the alarm information according to the connection management relationship, and push the alarm information to a corresponding pushing client according to the pushed WebSocket connection. The server provided in this embodiment establishes WebSocket connection with the client, pushes the alarm information to the client in time when receiving the alarm information sent by other monitoring devices, and can be quickly matched with a user with management authority for the early warning information when pushing the early warning information by establishing a connection management relationship in advance, so that WebSocket connection corresponding to the user with management authority for the alarm information is obtained as a pushing WebSocket connection, and the alarm information is pushed to a pushing client corresponding to the pushing WebSocket connection.
Further, in one embodiment of the present invention, as shown in fig. 4, the server further includes: the user weight management module 304 is connected with the alarm information pushing module 303, and is used for setting an initial weight of a user according to a preset initial weight configuration strategy, and adjusting the weight of the user according to a feedback result of the alarm information processing by the pushing client and the alarm information pushing condition; the WebSocket connection management module 305 is connected with the user weight management module 304, and is configured to disconnect WebSocket connection between a client and a server corresponding to a user when the weight of the user is lower than a preset weight.
In this embodiment, the weight value of the user is adjusted according to the processing situation of the user on the alarm information, and by comparing the weight value of the user with the preset weight value, it is determined whether the user does not process the alarm information frequently, so that the WebSocket connection corresponding to the user who does not process the received alarm information frequently is connected, if relevant alarm information exists, the user is not sent any more, the WebSocket connection which is not processed for a long time is disconnected, and the pressure of the server is reduced.
In yet another embodiment of the present invention, as shown in fig. 5, there is further provided a client, a user information sending module 401, configured to send user information to a server; the alarm information receiving module 402 is connected with the user information sending module and is used for receiving the alarm information of the server; the alarm information storage module 403 is connected with the alarm information receiving module and is used for storing alarm information and updating the processing state of the alarm information after the client processes the alarm information; and the alarm information processing result feedback module 404 is connected with the alarm information storage module and is used for sending the processing result of the client processing the alarm information to the server.
Specifically, the alarm information storage module 403 may establish an alarm information list to store relevant alarm information, where each piece of alarm information may include an information ID, a processing person, a processing state, and so on of the alarm information.
Further, in still another embodiment of the present invention, as shown in fig. 6, the client further includes: the alarm information processing state updating module 404 is connected with the alarm information storage module 403 and is used for judging whether the alarm information is stored in the alarm information storage module 403 after receiving the alarm information of the server; if the alarm information is stored in the alarm information storage module 403, judging whether the processing state of the alarm information is the same as the processing state of the alarm information stored in the alarm information storage module 403, and if the processing state of the alarm information is different, updating the processing state of the alarm information stored in the alarm information storage module 403; if the alarm information is not stored in the alarm information storage module 403, the alarm information is stored in the alarm information storage module 403.
Specifically, whether the alarm information currently received by the client is stored in the alarm information storage module or not is judged by judging whether the information ID of the alarm information received by the client is the same as the information ID of the alarm information stored in the alarm information storage module, if the alarm information currently received by the client is already stored in the alarm information storage module, it is indicated that the alarm information currently received by the client is not newly generated alarm information, whether the processing state of the alarm information currently received by the client is the same as the processing state of the alarm information stored in the alarm information storage module is further judged, if the processing state of the alarm information currently received by the client is not the same as the processing state of the alarm information stored in the alarm information storage module, the processing state of the alarm information stored in the alarm information storage module is modified to be the same as the processing state of the alarm information currently received by the client. The above-mentioned information ID refers to a code that each alarm information has to be able to distinguish from each other, and the information ID of each alarm information is unique.
Through the process, the processing state of the same alarm information can be updated in real time by a plurality of clients, and when one manager processes the alarm information, other managers can know the alarm information in time, so that the repeated processing of the alarm information is avoided.
The invention also provides an alarm information pushing system, which comprises a server and a client, wherein: the server is connected with the client by adopting a WebSocket, and is used for receiving the alarm information, acquiring the user information of the client, establishing a connection management relationship of the user and the WebSocket connection between the server and the client according to the user information, acquiring a push WebSocket connection corresponding to the user matched with the alarm information according to the connection management relationship, and pushing the alarm information to the corresponding push client according to the push WebSocket connection; and the client is used for sending the user information to the server, receiving and storing the alarm information of the server and updating the processing state of the alarm information.
The terms and expressions used in the description of the present invention are used as examples only and are not meant to be limiting. It will be appreciated by those skilled in the art that numerous changes may be made to the details of the above-described embodiments without departing from the underlying principles of the disclosed embodiments. The scope of the invention is, therefore, to be determined only by the following claims, in which all terms are to be understood in their broadest reasonable sense unless otherwise indicated.