CN114039961A - Message pushing method, device, server and storage medium based on WebSocket - Google Patents

Message pushing method, device, server and storage medium based on WebSocket Download PDF

Info

Publication number
CN114039961A
CN114039961A CN202111173764.7A CN202111173764A CN114039961A CN 114039961 A CN114039961 A CN 114039961A CN 202111173764 A CN202111173764 A CN 202111173764A CN 114039961 A CN114039961 A CN 114039961A
Authority
CN
China
Prior art keywords
server
websocket
target
websocket server
interface information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111173764.7A
Other languages
Chinese (zh)
Inventor
徐邦振
程宝平
许学
周鹤
庄载雄
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Mobile Communications Group Co Ltd
China Mobile Hangzhou Information Technology Co Ltd
Original Assignee
China Mobile Communications Group Co Ltd
China Mobile Hangzhou Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Mobile Communications Group Co Ltd, China Mobile Hangzhou Information Technology Co Ltd filed Critical China Mobile Communications Group Co Ltd
Priority to CN202111173764.7A priority Critical patent/CN114039961A/en
Publication of CN114039961A publication Critical patent/CN114039961A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/02Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1448Management of the data involved in backup or backup restore
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/542Event management; Broadcasting; Multicasting; Notifications
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/16Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
    • H04L69/161Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields
    • H04L69/162Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields involving adaptations of sockets based mechanisms
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/547Messaging middleware
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/548Queue

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Multimedia (AREA)
  • Computer Security & Cryptography (AREA)
  • Quality & Reliability (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Computer And Data Communications (AREA)

Abstract

The invention discloses a message pushing method, equipment, a server and a storage medium based on WebSocket, wherein the method comprises the following steps: when a subscription request sent by a first user terminal is received, the first WebSocket server stores the first sessionID, the first interface information and the first server IP address in a Redis cache in an associated manner; when the event to be consumed in the Kafka message queue is acquired, the second WebSocket server acquires target interface information corresponding to the event to be consumed; the second WebSocket server determines a target WebSocket server matched with the interface information in the WebSocket server; and the second WebSocket server sends a pushing request corresponding to the event to be consumed to the target WebSocket server, and the target WebSocket server pushes the event to be consumed to a target user terminal corresponding to the target WebSocket server. The invention improves the data storage capacity and the data reliability by adopting Kafka stored in the magnetic disk as the message middleware.

Description

Message pushing method, device, server and storage medium based on WebSocket
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a WebSocket-based message pushing method, device, server, and storage medium.
Background
As the technology of internet of things is continuously developed and evolved, more and more hardware devices are connected to the network, and thus, massive data are generated. The real-time data analysis and display system based on the data needs to rapidly clean, count and accurately distribute the continuously-gushed mass data to various data large screens and front-end reports.
In the prior art, client identification information is stored in a Redis cache, a Topic message is issued and received by using a Redis message queue, whether a session corresponding to a user exists locally is judged according to the identification information in the message, if so, the corresponding session is directly taken out of a memory and sent to the client corresponding to the session, and if not, the server IP and the session id corresponding to the user are inquired from the Redis cache according to the user id, and the user id, the session id and the Topic message are sent to the server by using an HTTP request. However, since the Redis is used as a cache message queue, and the Redis is a memory-based cache middleware, the data storage capacity is low and the data reliability is low.
The above is only for the purpose of assisting understanding of the technical aspects of the present invention, and does not represent an admission that the above is prior art.
Disclosure of Invention
The invention mainly aims to provide a message pushing method, a message pushing device, a message pushing server and a message pushing storage medium based on WebSocket, and aims to solve the technical problems of low data storage capacity and low data reliability caused by the fact that Redis is used as a cache message queue.
In order to achieve the above object, the present invention provides a message pushing method based on WebSocket, where the message pushing method based on WebSocket includes the following steps:
when a subscription request sent by a first user terminal is received, a first WebSocket server in a WebSocket server acquires first interface information, a first sessionID and a first server IP address corresponding to the subscription request, and stores the first sessionID, the first interface information and the first server IP address in a Redis cache in an associated manner;
when an event to be consumed in a Kafka message queue is acquired, a second WebSocket server in the WebSocket server acquires target interface information corresponding to the event to be consumed;
the second WebSocket server inquires the Redis cache based on the target interface information, and determines a target WebSocket server matched with the interface information in the WebSocket server;
and the second WebSocket server sends a pushing request corresponding to the event to be consumed to the target WebSocket server, wherein the target WebSocket server pushes the event to be consumed to a target user terminal corresponding to the target WebSocket server.
Further, the step of associating and storing the first sessionID, the first interface information, and the first server IP address to a Redis cache includes:
the first WebSocket server stores first data in the Redis cache, wherein a first key of the first data is the first interface information, and a first Set data of the first data is the first sessionID and the first server IP address;
and the first WebSocket server stores second data in the Redis cache, wherein a second key of the second data is the first sessionID and the first server IP address, and a second Set data of the second data is the first interface information.
Further, the step of querying, by the second WebSocket server, the Redis cache based on the target interface information, and determining, in the WebSocket server, a target WebSocket server that matches the interface information includes:
the second WebSocket server inquires the Redis cache based on the target interface information to obtain a target server IP address corresponding to the target interface information;
and the second WebSocket server takes the WebSocket server corresponding to the IP address of the target server in the WebSocket server as the target WebSocket server.
Further, the second WebSocket server sends a push request corresponding to the event to be consumed to the target WebSocket server, where the step of the target WebSocket server pushing the event to be consumed to the target user terminal corresponding to the target WebSocket server includes:
the second WebSocket server acquires a target sessionID corresponding to the target interface information;
and the second WebSocket server sends a pushing request to the target WebSocket server based on the event to be consumed and the target sessionID, wherein the target WebSocket server pushes the event to be consumed to a target user terminal corresponding to the target sessionID.
Further, the message pushing method based on WebSocket further includes:
when a disconnection request corresponding to a second user terminal is detected, a third WebSocket server in the WebSocket server acquires a second sessionID and a second server IP address corresponding to the disconnection request;
the third WebSocket server acquires corresponding second interface information in the Redis cache based on the second sessionID and the IP address of the second server;
and the third WebSocket server deletes corresponding target data in the Redis cache based on the second interface information, the second sessionID and the second server IP address.
Further, the step of deleting, by the third WebSocket server, the corresponding target data in the Redis cache based on the second interface information, the second sessionID, and the second server IP address includes:
and the third WebSocket server sends the second interface information, the second sessionID and a data deletion instruction corresponding to the second server IP address to the Redis cache, wherein the Redis cache deletes the second interface information, the second sessionID and the first target data and the second target data corresponding to the second server IP address based on the data deletion instruction.
Further, when receiving a subscription request sent by a first user terminal, a step of a first WebSocket server in the WebSocket servers acquiring first interface information, a first sessionID, and a first server IP address corresponding to the subscription request includes:
when a subscription request sent by a first user terminal is received, the first WebSocket server carries out authority verification on the first user terminal;
and when the authority of the first user terminal passes verification, the first WebSocket server acquires first interface information, a first sessionID and a first server IP address corresponding to the subscription request.
In addition, to achieve the above object, the present invention also provides a server, including: a first WebSocket server, a second WebSocket server, and a target WebSocket server, wherein,
the first WebSocket server comprises:
the first obtaining module is used for obtaining first interface information, a first sessionID and a first server IP address corresponding to a subscription request when the subscription request sent by a first user terminal is received, and storing the first sessionID, the first interface information and the first server IP address in a Redis cache in an associated manner;
the second WebSocket server includes:
the second acquisition module is used for acquiring target interface information corresponding to the event to be consumed when the event to be consumed in the Kafka message queue is acquired;
the query module is used for querying the Redis cache based on the target interface information and determining a target WebSocket server matched with the interface information in the WebSocket server;
the first sending module is used for sending a pushing request corresponding to the event to be consumed to the target WebSocket server;
the target WebSocket server comprises:
and the second sending module is used for pushing the event to be consumed to a target user terminal corresponding to the target WebSocket server.
In addition, to achieve the above object, the present invention further provides a message pushing device based on WebSocket, where the message pushing device based on WebSocket includes: the message pushing method based on the WebSocket comprises a memory, a processor and a message pushing program based on the WebSocket, wherein the message pushing program based on the WebSocket is stored in the memory and can run on the processor, and when being executed by the processor, the message pushing program based on the WebSocket realizes the steps of the message pushing method based on the WebSocket.
In addition, in order to achieve the above object, the present invention further provides a storage medium, where a message pushing program based on WebSocket is stored on the storage medium, and the message pushing program based on WebSocket realizes the steps of the message pushing method based on WebSocket when being executed by a processor.
When a subscription request sent by a first user terminal is received, a first WebSocket server in a WebSocket server acquires first interface information, a first sessionID and a first server IP address corresponding to the subscription request, and stores the first sessionID, the first interface information and the first server IP address to a Redis cache in an associated manner; when the event to be consumed in the Kafka message queue is obtained, a second WebSocket server in the WebSocket server obtains target interface information corresponding to the event to be consumed; then the second WebSocket server inquires the Redis cache based on the target interface information, and determines a target WebSocket server matched with the target interface information in the WebSocket server; and then the second WebSocket server sends a pushing request corresponding to the event to be consumed to the target WebSocket server, wherein the target WebSocket server pushes the event to be consumed to a target user terminal corresponding to the target WebSocket server, and the Kafka stored in a magnetic disk is used as a message middleware, so that the mass data storage problem and the capacity expansion cost problem can be avoided, the data storage capacity and the data reliability are improved, and meanwhile, due to the fact that the disk space is sufficient, multiple backups can be performed by using a Kafka data copy mechanism, and the data security is guaranteed.
Meanwhile, a plurality of Websocket servers (second Websocket servers) are used as the message broadcasting server, single-point faults of the servers are avoided, and the system can conveniently perform transverse capacity expansion at any time and improve the data processing capacity of the system by adding the servers. Moreover, sessionID, the server IP address of the WebSocket server and interface information are stored in the Redis cache, and when Kafka data is consumed, message broadcasting is only carried out on a server with a subscriber (sessionID), so that the number of data processing before message broadcasting is greatly reduced, and the system overhead is greatly saved.
Drawings
Fig. 1 is a schematic structural diagram of a WebSocket-based message pushing device in a hardware operating environment according to an embodiment of the present invention;
fig. 2 is a schematic flowchart of a first embodiment of a WebSocket-based message push method according to the present invention;
fig. 3 is a schematic functional module diagram of the WebSocket server according to an embodiment of the present invention.
The implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
As shown in fig. 1, fig. 1 is a schematic structural diagram of a WebSocket-based message pushing device in a hardware operating environment according to an embodiment of the present invention.
The message pushing device based on the WebSocket in the embodiment of the invention can be a PC. As shown in fig. 1, the WebSocket-based message pushing device may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, a communication bus 1002. Wherein a communication bus 1002 is used to enable connective communication between these components. The user interface 1003 may include a Display screen (Display), an input unit such as a Keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface). The memory 1005 may be a high-speed RAM memory or a non-volatile memory (e.g., a magnetic disk memory). The memory 1005 may alternatively be a storage device separate from the processor 1001.
Optionally, the WebSocket-based message pushing device may further include a camera, an RF (Radio Frequency) circuit, a sensor, an audio circuit, a WiFi module, and the like. Certainly, the message pushing device based on WebSocket may also be configured with other sensors such as a barometer, a hygrometer, a thermometer, an infrared sensor, and the like, which are not described herein again.
Those skilled in the art will appreciate that the terminal structure shown in fig. 1 does not constitute a limitation of the WebSocket-based message pushing apparatus, and may include more or less components than those shown, or combine some components, or arrange different components.
As shown in fig. 1, a memory 1005, which is a kind of computer storage medium, may include an operating system, a network communication module, a user interface module, and a WebSocket-based message push program therein.
In the terminal shown in fig. 1, the network interface 1004 is mainly used for connecting to a backend server and performing data communication with the backend server; the user interface 1003 is mainly used for connecting a client (user side) and performing data communication with the client; and processor 1001 may be configured to invoke a WebSocket-based message push program stored in memory 1005.
In this embodiment, the message pushing device based on WebSocket includes: the message pushing method comprises a memory 1005, a processor 1001 and a message pushing program based on WebSocket, wherein the message pushing program based on WebSocket is stored in the memory 1005 and can run on the processor 1001, and when the processor 1001 calls the message pushing program based on WebSocket stored in the memory 1005, the steps of the message pushing method based on WebSocket in the following embodiments are executed.
The invention also provides a message pushing method based on the WebSocket, and referring to FIG. 2, FIG. 2 is a schematic flow diagram of a first embodiment of the message pushing method based on the WebSocket.
In this embodiment, the message pushing method based on WebSocket includes the following steps:
step S101, when a subscription request sent by a first user terminal is received, a first WebSocket server in a WebSocket server acquires first interface information, a first sessionID and a first server IP address corresponding to the subscription request, and stores the first sessionID, the first interface information and the first server IP address to a Redis cache in an associated manner;
in the embodiment, a plurality of distributed WebSocket servers are arranged, and after a background starts the plurality of WebSocket servers, a user can randomly establish connection with one WebSocket server through a first user terminal. The device terminal reports the device event or the device state to a Kafka message producer through an Http interface, the Kafka message producer uploads data to a Kafka message queue, and specifically, when device data corresponding to the device event or the device state sent by the device terminal is received, the Kafka message producer generates a to-be-consumed event corresponding to the device data, and uploads the to-be-consumed event corresponding to the device data to the Kafka message queue. Meanwhile, a mobile terminal (for example, a mobile phone with a corresponding APP) records user behavior data such as user clicking, inquiring, purchasing and binding equipment, reports the user behavior data to a service module, and the service module generates one or more events to be consumed (events to be consumed corresponding to the user behavior data) according to the user behavior data and uploads the events to a Kafka message queue.
In this embodiment, a user may log in at a first user terminal in a manner of a username and password, and establish a long connection with any WebSocket server (e.g., a first WebSocket server in the WebSocket server), and the user selects, through an interface displayed by the first user terminal, to subscribe to data of a specified interface, and sends a subscription request through the first user terminal.
In this embodiment, when a subscription request sent by a first user terminal is received, a first WebSocket server obtains first interface information, a first sessionID, and a first server IP address corresponding to the subscription request, and associates and stores the first sessionID, the first interface information, and the first server IP address to a Redis cache. The first sessionID is terminal information (for example, account information) corresponding to the first user terminal, the first interface information is information of a subscription interface subscribed by the first user terminal, and the first server IP address is an IP address of the first WebSocket server.
Specifically, in an embodiment, the step S101 includes:
step a, the first WebSocket server stores first data in the Redis cache, wherein a first key of the first data is the interface information, and a first Set data of the first data is the sessionID and the first server IP address;
step b, the first WebSocket server stores second data in the Redis cache, wherein a second key of the second data is the sessionID and the IP address of the first server, and a second Set data of the second data is the interface information.
In this embodiment, the interface information, the sessionID, and the server IP address stored in the Redis cache include two data items, that is, first data and second data, where a first key of the first data is the first interface information, a first Set data of the first data is the first sessionID and the first server IP address, a second key of the second data is the first sessionID and the first server IP address, and a second Set data of the second data is the first interface information, so as to facilitate pushing of subsequent messages.
Step S102, when the event to be consumed in the Kafka message queue is obtained, a second WebSocket server in the WebSocket server obtains target interface information corresponding to the event to be consumed;
in this embodiment, the WebSocket server is a consumer of the Kafka message queue, and the WebSocket server monitors data (to-be-consumed events) of each Topic in the Kafka message queue simultaneously after being started. And, due to the regional nature of the Kafka message queue, for each to-be-consumed event, the Kafka message queue can only send the to-be-consumed event to a limited number of WebSocket servers.
When the event to be consumed in the Kafka message queue is acquired, a second WebSocket server in the WebSocket server acquires target interface information corresponding to the event to be consumed. Wherein the second WebSocket server may include the first WebSocket server.
Step S103, the second WebSocket server inquires the Redis cache based on the target interface information, and determines a target WebSocket server matched with the target interface information in the WebSocket server;
in this embodiment, when the target interface information is obtained, the second WebSocket server queries the Redis cache based on the target interface information to determine a target WebSocket server matched with the target interface information in the WebSocket server, and specifically, the second WebSocket server queries, in all first data of the Redis cache, a first key as first target data of the target interface information, obtains a first server IP address in first Set data corresponding to the first target data, and takes the WebSocket server corresponding to the first server IP address as the target WebSocket server.
Step S104, the second WebSocket server sends a pushing request corresponding to the event to be consumed to the target WebSocket server, wherein the target WebSocket server pushes the event to be consumed to a target user terminal corresponding to the target WebSocket server.
In this embodiment, when a target WebSocket server is obtained, a second WebSocket server sends a push request corresponding to the event to be consumed to the target WebSocket server, and the target WebSocket server pushes the event to be consumed to a target user terminal corresponding to the target WebSocket server, specifically, the push request may further include a target sessionID corresponding to target interface information.
In the message pushing method based on the WebSocket provided by the embodiment, when a subscription request sent by a first user terminal is received, a first WebSocket server in a WebSocket server obtains first interface information, a first sessionID and a first server IP address corresponding to the subscription request, and stores the first sessionID, the first interface information and the first server IP address in an associated manner to a Redis cache; when the event to be consumed in the Kafka message queue is obtained, a second WebSocket server in the WebSocket server obtains target interface information corresponding to the event to be consumed; then the second WebSocket server inquires the Redis cache based on the target interface information, and determines a target WebSocket server matched with the target interface information in the WebSocket server; and then the second WebSocket server sends a pushing request corresponding to the event to be consumed to the target WebSocket server, wherein the target WebSocket server pushes the event to be consumed to a target user terminal corresponding to the target WebSocket server, and the Kafka stored in a magnetic disk is used as a message middleware, so that the mass data storage problem and the capacity expansion cost problem can be avoided, the data storage capacity and the data reliability are improved, and meanwhile, due to the fact that the disk space is sufficient, multiple backups can be performed by using a Kafka data copy mechanism, and the data security is guaranteed.
Meanwhile, a plurality of Websocket servers (second Websocket servers) are used as the message broadcasting server, single-point faults of the servers are avoided, and the system can conveniently perform transverse capacity expansion at any time and improve the data processing capacity of the system by adding the servers. Moreover, sessionID, the server IP address of the WebSocket server and interface information are stored in the Redis cache, and when Kafka data is consumed, message broadcasting is only carried out on a server with a subscriber (sessionID), so that the number of data processing before message broadcasting is greatly reduced, and the system overhead is greatly saved.
Based on the first embodiment, a second embodiment of the message pushing method based on WebSocket of the present invention is proposed, in this embodiment, step S103 includes:
step S201, the second WebSocket server inquires the Redis cache based on the target interface information to obtain a target server IP address corresponding to the target interface information;
step S202, the second WebSocket server takes the WebSocket server corresponding to the IP address of the target server in the WebSocket server as the target WebSocket server.
In this embodiment, when the target interface information is obtained, the second WebSocket server queries the Redis cache based on the target interface information to obtain a target server IP address corresponding to the target interface information, specifically, the second WebSocket server queries, in all first data of the Redis cache, a first key as first target data of the target interface information to obtain a first server IP address in first Set data corresponding to the first target data, and then uses the WebSocket server corresponding to the first server IP address as the target WebSocket server.
In the message pushing method based on WebSocket provided in this embodiment, the second WebSocket server queries the Redis cache based on the target interface information to obtain the IP address of the target server corresponding to the target interface information; and then the second WebSocket server takes the WebSocket server corresponding to the IP address of the target server in the WebSocket server as the target WebSocket server, the target WebSocket server can be accurately obtained according to the target interface information, a plurality of WebSocket servers (the second WebSocket server) are used as the message broadcasting server, the single-point fault of the server is avoided, and the system can conveniently perform transverse capacity expansion and improve the data processing capacity of the system at any time by adding servers. Moreover, sessionID, the server IP address of the WebSocket server and interface information are stored in the Redis cache, and when Kafka data is consumed, message broadcasting is only carried out on a server with a subscriber (sessionID), so that the number of data processing before message broadcasting is greatly reduced, and the system overhead is greatly saved.
Based on the first embodiment, a third embodiment of the message pushing method based on WebSocket in the present invention is proposed, where in this embodiment, step S104 includes:
step S301, the second WebSocket server obtains a target sessionID corresponding to the target interface information;
step S302, the second WebSocket server sends a pushing request to the target WebSocket server based on the event to be consumed and the target sessionID, wherein the target WebSocket server pushes the event to be consumed to a target user terminal corresponding to the target sessionID.
In this embodiment, the second WebSocket server queries, in all first data cached by the Redis, the first key as first target data of the target interface information, and when acquiring a first server IP address in first Set data corresponding to the first target data, acquires a sessionID in the first Set data corresponding to the first target data, that is, a target sessionID corresponding to the target interface information.
And then, the second WebSocket server sends a pushing request to the target WebSocket server based on the event to be consumed and the target sessionID, the target WebSocket server obtains the event to be consumed and the target sessionID based on the pushing request, and pushes the event to be consumed to the target user terminal corresponding to the target sessionID.
In the message pushing method based on WebSocket provided by this embodiment, the second WebSocket server obtains the target sessionID corresponding to the target interface information; and then the second WebSocket server sends a pushing request to the target WebSocket server based on the event to be consumed and the target sessionID, wherein the target WebSocket server pushes the event to be consumed to a target user terminal corresponding to the target sessionID, the event to be consumed can be accurately pushed to the corresponding target user terminal according to the target sessionID, the message broadcasting is only carried out on a server with a subscriber (sessionID) when Kafka data is consumed, the number of data processing before the message broadcasting is greatly reduced, and the system overhead is greatly saved.
Based on the first embodiment, a fourth embodiment of the message pushing method based on WebSocket of the present invention is provided, and in this embodiment, the message pushing method based on WebSocket further includes:
step S401, when a disconnection request corresponding to a second user terminal is detected, a third WebSocket server in the WebSocket servers acquires a second sessionID corresponding to the disconnection request and a second server IP address;
step S402, the third WebSocket server acquires corresponding second interface information in the Redis cache based on the second sessionID and the second server IP address;
step S403, the third WebSocket server deletes corresponding target data in the Redis cache based on the second interface information, the second sessionID, and the second server IP address.
In this embodiment, when a disconnection request corresponding to a second user terminal is detected, a third WebSocket server in the WebSocket server obtains a second sessionID and a second server IP address corresponding to the disconnection request, where the third WebSocket server is a WebSocket server that establishes a long connection with the second user terminal, the second server IP address is an IP address of the third WebSocket server, and the second sessionID is a sessionID corresponding to the second user terminal.
Then, the third WebSocket server acquires corresponding second interface information in the Redis cache based on the second sessionID and the IP address of the second server; specifically, the third WebSocket server obtains the second sessionID and the second target data corresponding to the IP address of the second server through the second data in the Redis cache, and takes the interface information of the second target data as the second interface information.
And then, the third WebSocket server deletes corresponding target data in the Redis cache based on the second interface information, the second sessionID and the second server IP address. Specifically, step S403 includes:
and the third WebSocket server sends the second interface information, the second sessionID and a data deletion instruction corresponding to the second server IP address to the Redis cache, wherein the Redis cache deletes the second interface information, the second sessionID and the first target data and the second target data corresponding to the second server IP address based on the data deletion instruction. The key of the first target data is the second interface information, the Set data of the first target data is the second sessionID and the second server IP address, the key of the second target data is the second sessionID and the second server IP address, and the Set data of the second target data is the first interface information.
In the message pushing method based on the WebSocket provided by the embodiment, when a disconnection request corresponding to a second user terminal is detected, a third WebSocket server in the WebSocket server obtains a second sessionID and a second server IP address corresponding to the disconnection request; then, the third WebSocket server acquires corresponding second interface information in the Redis cache based on the second sessionID and the IP address of the second server; and then the third WebSocket server deletes corresponding target data in the Redis cache based on the second interface information, the second sessionID and the second server IP address, and improves the resource utilization rate of the Redis cache by correspondingly deleting the subscriber information stored in the Redis cache, and can avoid unnecessary message pushing.
Based on the foregoing embodiments, a fifth embodiment of the message pushing method based on WebSocket in the present invention is provided, and in this embodiment, the message pushing method based on WebSocket further includes:
step S501, when receiving a subscription request sent by a first user terminal, the first WebSocket server performs authority verification on the first user terminal;
step S502, when the first user terminal authority passes the verification, the first WebSocket server obtains the first interface information, the first sessionID and the first server IP address corresponding to the subscription request.
In this embodiment, when receiving a subscription request sent by a first user terminal, a first WebSocket server performs permission verification on the first user terminal, and specifically, the first WebSocket server performs permission verification on a user account currently logged in by the first user terminal, so as to determine whether a user has permission to subscribe to a message corresponding to the first interface information.
And then, when the authority verification of the first user terminal passes, the first WebSocket server acquires the first interface information, the first sessionID and the first server IP address corresponding to the subscription request.
In the message pushing method based on the WebSocket provided by the embodiment, when a subscription request sent by a first user terminal is received, the first WebSocket server performs authority verification on the first user terminal; and then when the authority verification of the first user terminal passes, the first WebSocket server acquires the first interface information, the first sessionID and the first server IP address corresponding to the subscription request, and the authority verification is carried out through the first user terminal, so that the accuracy of message pushing is improved.
The present invention also provides a server, referring to fig. 3, the server including: a first WebSocket server 10, a second WebSocket server 20, and a target WebSocket server 30, wherein,
the first WebSocket server 10 includes:
a first obtaining module 11, configured to, when receiving a subscription request sent by a first user terminal, obtain first interface information, a first sessionID, and a first server IP address corresponding to the subscription request, and store the first sessionID, the first interface information, and the first server IP address in association with a Redis cache;
the second WebSocket server 20 includes:
a second obtaining module 21, configured to obtain target interface information corresponding to the event to be consumed when the event to be consumed in the Kafka message queue is obtained;
the query module 22 is configured to query the Redis cache based on the target interface information, and determine a target WebSocket server matched with the interface information in the WebSocket server;
the first sending module 23 is configured to send a push request corresponding to the event to be consumed to the target WebSocket server;
the target WebSocket server 30 includes:
and the second sending module 31 is configured to push the event to be consumed to a target user terminal corresponding to the target WebSocket server.
The method executed by each program unit may refer to each embodiment of the WebSocket-based message pushing method of the present invention, and details are not described here.
The invention also provides a storage medium.
The storage medium is a computer readable storage medium, the storage medium is stored with a message pushing program based on the WebSocket, and the message pushing program based on the WebSocket realizes the steps of the message pushing method based on the WebSocket when being executed by a processor.
The method implemented when the message pushing program based on the WebSocket running on the processor is executed may refer to each embodiment of the message pushing method based on the WebSocket of the present invention, and is not described herein again.
In addition, an embodiment of the present invention further provides a computer program product, where the computer program product includes a message pushing program based on WebSocket, and the message pushing program based on WebSocket, when executed by a processor, implements the steps of the message pushing method based on WebSocket as described above.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) as described above and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (10)

1. A message pushing method based on WebSocket is characterized by comprising the following steps:
when a subscription request sent by a first user terminal is received, a first WebSocket server in a WebSocket server acquires first interface information, a first sessionID and a first server IP address corresponding to the subscription request, and stores the first sessionID, the first interface information and the first server IP address in a Redis cache in an associated manner;
when an event to be consumed in a Kafka message queue is acquired, a second WebSocket server in the WebSocket server acquires target interface information corresponding to the event to be consumed;
the second WebSocket server inquires the Redis cache based on the target interface information, and determines a target WebSocket server matched with the interface information in the WebSocket server;
and the second WebSocket server sends a pushing request corresponding to the event to be consumed to the target WebSocket server, wherein the target WebSocket server pushes the event to be consumed to a target user terminal corresponding to the target WebSocket server.
2. The WebSocket-based message pushing method of claim 1, wherein the step of associating the first sessionID, the first interface information, and the first server IP address to a Redis cache comprises:
the first WebSocket server stores first data in the Redis cache, wherein a first key of the first data is the first interface information, and a first Set data of the first data is the first sessionID and the first server IP address;
and the first WebSocket server stores second data in the Redis cache, wherein a second key of the second data is the first sessionID and the first server IP address, and a second Set data of the second data is the first interface information.
3. The message pushing method based on the WebSocket as claimed in claim 1, wherein the second WebSocket server queries the Redis cache based on the target interface information, and the step of determining, in the WebSocket server, the target WebSocket server that matches the interface information includes:
the second WebSocket server inquires the Redis cache based on the target interface information to obtain a target server IP address corresponding to the target interface information;
and the second WebSocket server takes the WebSocket server corresponding to the IP address of the target server in the WebSocket server as the target WebSocket server.
4. The message pushing method based on WebSocket of claim 1, wherein the second WebSocket server sends a pushing request corresponding to the event to be consumed to the target WebSocket server, and the step of the target WebSocket server pushing the event to be consumed to a target user terminal corresponding to the target WebSocket server includes:
the second WebSocket server acquires a target sessionID corresponding to the target interface information;
and the second WebSocket server sends a pushing request to the target WebSocket server based on the event to be consumed and the target sessionID, wherein the target WebSocket server pushes the event to be consumed to a target user terminal corresponding to the target sessionID.
5. The WebSocket-based message pushing method of claim 1, wherein the WebSocket-based message pushing method further comprises:
when a disconnection request corresponding to a second user terminal is detected, a third WebSocket server in the WebSocket server acquires a second sessionID and a second server IP address corresponding to the disconnection request;
the third WebSocket server acquires corresponding second interface information in the Redis cache based on the second sessionID and the IP address of the second server;
and the third WebSocket server deletes corresponding target data in the Redis cache based on the second interface information, the second sessionID and the second server IP address.
6. The message pushing method based on the WebSocket of claim 5, wherein the step of deleting, by the third WebSocket server, the corresponding target data in the Redis cache based on the second interface information, the second sessionID, and the second server IP address includes:
and the third WebSocket server sends the second interface information, the second sessionID and a data deletion instruction corresponding to the second server IP address to the Redis cache, wherein the Redis cache deletes the second interface information, the second sessionID and the first target data and the second target data corresponding to the second server IP address based on the data deletion instruction.
7. The WebSocket-based message pushing method of any one of claims 1 to 6, wherein, when receiving a subscription request sent by a first user terminal, a step of a first WebSocket server in the WebSocket server obtaining first interface information, a first sessionID, and a first server IP address corresponding to the subscription request includes:
when a subscription request sent by a first user terminal is received, the first WebSocket server carries out authority verification on the first user terminal;
and when the authority of the first user terminal passes verification, the first WebSocket server acquires first interface information, a first sessionID and a first server IP address corresponding to the subscription request.
8. A server, characterized in that the server comprises: a first WebSocket server, a second WebSocket server, and a target WebSocket server, wherein,
the first WebSocket server comprises:
the first obtaining module is used for obtaining first interface information, a first sessionID and a first server IP address corresponding to a subscription request when the subscription request sent by a first user terminal is received, and storing the first sessionID, the first interface information and the first server IP address in a Redis cache in an associated manner;
the second WebSocket server includes:
the second acquisition module is used for acquiring target interface information corresponding to the event to be consumed when the event to be consumed in the Kafka message queue is acquired;
the query module is used for querying the Redis cache based on the target interface information and determining a target WebSocket server matched with the interface information in the WebSocket server;
the first sending module is used for sending a pushing request corresponding to the event to be consumed to the target WebSocket server;
the target WebSocket server comprises:
and the second sending module is used for pushing the event to be consumed to a target user terminal corresponding to the target WebSocket server.
9. A message pushing device based on WebSocket, wherein the message pushing device based on WebSocket comprises: the message pushing method comprises a memory, a processor and a message pushing program based on WebSocket, wherein the message pushing program based on WebSocket is stored in the memory and can run on the processor, and when being executed by the processor, the message pushing program based on WebSocket realizes the steps of the message pushing method based on WebSocket according to any one of claims 1 to 7.
10. A storage medium, wherein a message pushing program based on WebSocket is stored on the storage medium, and when executed by a processor, the message pushing program based on WebSocket implements the steps of the message pushing method based on WebSocket according to any one of claims 1 to 7.
CN202111173764.7A 2021-10-08 2021-10-08 Message pushing method, device, server and storage medium based on WebSocket Pending CN114039961A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111173764.7A CN114039961A (en) 2021-10-08 2021-10-08 Message pushing method, device, server and storage medium based on WebSocket

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111173764.7A CN114039961A (en) 2021-10-08 2021-10-08 Message pushing method, device, server and storage medium based on WebSocket

Publications (1)

Publication Number Publication Date
CN114039961A true CN114039961A (en) 2022-02-11

Family

ID=80134788

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111173764.7A Pending CN114039961A (en) 2021-10-08 2021-10-08 Message pushing method, device, server and storage medium based on WebSocket

Country Status (1)

Country Link
CN (1) CN114039961A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114827171A (en) * 2022-03-23 2022-07-29 青岛中科曙光科技服务有限公司 Information synchronization method and device, computer equipment and storage medium
CN115987929A (en) * 2022-12-21 2023-04-18 浪潮通信信息系统有限公司 Method for broadband maintenance real-time communication

Citations (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CA2759923A1 (en) * 2010-06-07 2011-12-07 Guangzhou Sunrise Electronics Development Co., Ltd. User information pushing method, user information presentation method, system, server and client
WO2015149471A1 (en) * 2014-04-04 2015-10-08 中兴通讯股份有限公司 Information pushing method, system and device and computer storage medium
CN108377247A (en) * 2018-03-08 2018-08-07 北京车和家信息技术有限公司 A kind of information push method and device
CN109361770A (en) * 2018-12-11 2019-02-19 苏州创旅天下信息技术有限公司 The system and method for bidirectional real-time is realized based on WebSocket and message queue
CN109451072A (en) * 2018-12-29 2019-03-08 广东电网有限责任公司 A kind of message caching system and method based on Kafka
CN110708391A (en) * 2019-10-17 2020-01-17 山东健康医疗大数据有限公司 WebSocket-based internet inquiry realization method and system
CN111031058A (en) * 2019-12-23 2020-04-17 集奥聚合(北京)人工智能科技有限公司 Websocket-based distributed server cluster interaction method and device
CN111371892A (en) * 2020-03-05 2020-07-03 中国银行股份有限公司 High-concurrency distributed message pushing system and method
CN111447185A (en) * 2020-03-10 2020-07-24 平安科技(深圳)有限公司 Processing method of push information and related equipment
CN111859127A (en) * 2020-07-13 2020-10-30 海尔优家智能科技(北京)有限公司 Subscription method and device of consumption data and storage medium
CN111917687A (en) * 2019-05-08 2020-11-10 北京京东振世信息技术有限公司 Method and device for circularly pushing reminding message
CN112347379A (en) * 2020-10-30 2021-02-09 银盛支付服务股份有限公司 Spark-based data real-time processing visualization method
CN112416614A (en) * 2020-10-28 2021-02-26 网宿科技股份有限公司 Data processing method, system and server based on message queue
CN112511580A (en) * 2019-09-16 2021-03-16 北京国双科技有限公司 Message pushing method, device, storage medium and equipment

Patent Citations (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CA2759923A1 (en) * 2010-06-07 2011-12-07 Guangzhou Sunrise Electronics Development Co., Ltd. User information pushing method, user information presentation method, system, server and client
WO2015149471A1 (en) * 2014-04-04 2015-10-08 中兴通讯股份有限公司 Information pushing method, system and device and computer storage medium
CN108377247A (en) * 2018-03-08 2018-08-07 北京车和家信息技术有限公司 A kind of information push method and device
CN109361770A (en) * 2018-12-11 2019-02-19 苏州创旅天下信息技术有限公司 The system and method for bidirectional real-time is realized based on WebSocket and message queue
CN109451072A (en) * 2018-12-29 2019-03-08 广东电网有限责任公司 A kind of message caching system and method based on Kafka
CN111917687A (en) * 2019-05-08 2020-11-10 北京京东振世信息技术有限公司 Method and device for circularly pushing reminding message
CN112511580A (en) * 2019-09-16 2021-03-16 北京国双科技有限公司 Message pushing method, device, storage medium and equipment
CN110708391A (en) * 2019-10-17 2020-01-17 山东健康医疗大数据有限公司 WebSocket-based internet inquiry realization method and system
CN111031058A (en) * 2019-12-23 2020-04-17 集奥聚合(北京)人工智能科技有限公司 Websocket-based distributed server cluster interaction method and device
CN111371892A (en) * 2020-03-05 2020-07-03 中国银行股份有限公司 High-concurrency distributed message pushing system and method
CN111447185A (en) * 2020-03-10 2020-07-24 平安科技(深圳)有限公司 Processing method of push information and related equipment
CN111859127A (en) * 2020-07-13 2020-10-30 海尔优家智能科技(北京)有限公司 Subscription method and device of consumption data and storage medium
CN112416614A (en) * 2020-10-28 2021-02-26 网宿科技股份有限公司 Data processing method, system and server based on message queue
CN112347379A (en) * 2020-10-30 2021-02-09 银盛支付服务股份有限公司 Spark-based data real-time processing visualization method

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114827171A (en) * 2022-03-23 2022-07-29 青岛中科曙光科技服务有限公司 Information synchronization method and device, computer equipment and storage medium
CN114827171B (en) * 2022-03-23 2023-12-15 青岛中科曙光科技服务有限公司 Information synchronization method, apparatus, computer device and storage medium
CN115987929A (en) * 2022-12-21 2023-04-18 浪潮通信信息系统有限公司 Method for broadband maintenance real-time communication

Similar Documents

Publication Publication Date Title
US11184411B2 (en) Communication terminal, communication system, log data transmission method, and non-transitory computer-readable medium
CN114039961A (en) Message pushing method, device, server and storage medium based on WebSocket
JP2011511972A (en) Apparatus and method for searching / downloading content in a communication device
CN103997452A (en) Information sharing method and apparatus among multiple platforms
CN102377617A (en) Systems, methods, and apparatus to monitor and authenticate mobile internet activity
CN102387156B (en) Equipment logging treatment method, device and system
CN102932325B (en) Identify the method for contact person, system and the server of device users
CN109167840B (en) Task pushing method, node autonomous server and edge cache server
US8949599B2 (en) Device management apparatus, method for device management, and computer program product
CN112953791B (en) Network detection method and device, electronic equipment and computer readable storage medium
WO2013033863A1 (en) Performance monitoring of a media player launched by a web browser
WO2013013556A1 (en) Data reporting method and device
CN111859127A (en) Subscription method and device of consumption data and storage medium
WO2014015525A1 (en) Method and device for querying for user online state
CN111930542A (en) Data acquisition method and device, electronic equipment and computer readable storage medium
CN108737350B (en) Information processing method and client
CN110933070A (en) User identification method, system, equipment and computer readable storage medium
CN112231566B (en) Information pushing method, device, system and readable storage medium
CN104462235A (en) Internet of Things general event service mechanism based on Restful Web Service
CN115361378A (en) Test environment file searching method and system and computer equipment
CN115412920A (en) Internet of things equipment binding system, method and device and electronic equipment
CN106534238B (en) Method and device for providing offline application service for user
CN113014456A (en) Monitoring data transmission system, method, device, equipment and storage medium
CN103795748A (en) Method for downloading mobile internet website content information
CN109785129B (en) Data acquisition method, device, equipment and computer readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination