Message broadcasting method and device, storage medium and back-end server
By introducing Redis's message subscription mechanism in the message broadcasting system, decoupling WebSocket message push and business logic, solving the problems of low flexibility, high maintenance costs and slow response speed in the existing technology, and achieving more efficient message broadcasting and System reliability.
Patent Information
- Application Number
- CN202411269876.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-11
- Publication Date
- 2024-11-08
AI Technical Summary
In the prior art, the message broadcasting scheme has low flexibility, low scalability, high maintenance cost and slow response speed, which is mainly due to the tight coupling of the WebSocket protocol with business logic, which increases maintenance difficulty and reduces response speed.
Introduce Redis' message subscription mechanism to decouple WebSocket message push and business logic. Using Redis's asynchronous message push mechanism, publish and push messages to the target terminal device through the pre-set Redis channel, reducing business logic and WebSocket messages Push dependencies improve system flexibility and scalability, and maintain connection lists through heartbeat detection to ensure the real-time and reliability of messages.
It simplifies the system architecture, improves the flexibility of function expansion and maintenance, reduces maintenance costs and difficulty, improves response speed and real-time message broadcasting, and enhances the system's high concurrency processing capabilities and fault tolerance.
Smart Images

Figure CN118921360A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a message broadcasting method, device, storage medium and back-end server. Background Art
[0002] With the development of computer technology and the continuous updating of product marketing strategies, many applications and applets have launched the function of online product drawing, allowing consumer users to queue online and complete product drawing through terminal devices, for example, they can achieve a reward by operating the terminal device. During the product drawing process, the consumer user's queue information and the remaining product information in the product warehouse are constantly updated over time, so the service provider needs to broadcast real-time messages to the terminal devices held by consumer users so that consumer users can be informed of the latest current situation in a timely manner.
[0003] At present, the existing message broadcasting scheme adopts HTTP (Hypertext Transfer Protocol) polling to broadcast messages. However, considering that this scheme cannot meet the real-time requirements, the prior art also proposes a scheme of using the WebSocket protocol to implement message broadcasting, so as to improve the real-time performance of message broadcasting.
[0004] However, the inventors have found that in the above solution, the message sending mechanism based on the WeoSocket protocol is tightly coupled with the business logic. This not only increases the difficulty of implementing, expanding and maintaining the business logic, thereby reducing flexibility and scalability, increasing maintenance costs, but also increases the processing time of the business logic, thereby reducing the response speed. Summary of the invention
[0005] The purpose of this application is to solve at least one of the above-mentioned technical defects, especially the technical defects of low flexibility, low scalability, high maintenance cost and slow response speed in the prior art.
[0006] In a first aspect, an embodiment of the present application provides a message broadcasting method, which is applied to a backend server, comprising:
[0007] In response to a product extraction request, the preset business logic code is executed and the latest queue information and the latest product remaining information are generated respectively;
[0008] Generate a message to be broadcast according to the latest queuing information and the latest remaining commodity information;
[0009] According to the preset Redis channel information, the message to be broadcast is published to the target Redis channel; the target Redis channel is the Redis channel subscribed by the backend server;
[0010] Receiving the message to be broadcast sent by the target Redis channel;
[0011] Determine each target terminal device, and push the message to be broadcast to each target terminal device based on the WebSocket protocol; wherein the target terminal device is a terminal device that establishes a WebSocket connection with the backend server.
[0012] In one embodiment, the WebSocket protocol is the STOMP protocol.
[0013] In one embodiment, the method further comprises:
[0014] Generate or update a record list of each WebSocket connection object according to the received WebSocket connection request; wherein the WebSocket connection object is generated according to the WebSocket connection established between the backend server and the target terminal device;
[0015] Respectively receiving the first heartbeat message regularly sent by each of the target terminal devices, and judging whether each of the target terminal devices is online according to the reception status of the heartbeat message, to obtain an online judgment result;
[0016] If the online determination result reflects that at least one of the target terminal devices is offline, the WebSocket connection object corresponding to the offline target terminal device is deleted from the record list.
[0017] In one embodiment, the determining each target terminal device and pushing the to-be-broadcast message to each target terminal device based on the WebSocket protocol includes:
[0018] For each of the WebSocket connection objects recorded in the record list, based on the WebSocket protocol, the message to be broadcast is pushed to the target terminal device corresponding to the WebSocket connection object.
[0019] In one embodiment, the method further comprises:
[0020] In response to the start of the scheduled task, obtaining a current timestamp, and generating a second heartbeat message according to the current timestamp;
[0021] The second heartbeat message is sent to a Redis server used to maintain the target Redis channel.
[0022] In a second aspect, an embodiment of the present application provides a message broadcasting device, which is applied to a backend server, including:
[0023] A business execution module, for responding to a commodity extraction request, executing a preset business logic code and generating the latest queue information and the latest commodity remaining information;
[0024] A message generation module, used to generate a message to be broadcast according to the latest queuing information and the latest remaining commodity information;
[0025] A message publishing module, used for publishing the message to be broadcast to a target Redis channel according to the preset Redis channel information; the target Redis channel is a Redis channel subscribed by the backend server;
[0026] A message receiving module, used for receiving the message to be broadcast sent by the target Redis channel;
[0027] The message push module is used to determine each target terminal device and push the message to be broadcast to each target terminal device based on the WebSocket protocol; wherein the target terminal device is a terminal device that establishes a WebSocket connection with the backend server.
[0028] In one embodiment, the WebSocket protocol is the STOMP protocol.
[0029] In one embodiment, the device further comprises:
[0030] A list generation module, used to generate or update a record list of various WebSocket connection objects according to the received WebSocket connection request; wherein the WebSocket connection object is generated according to the WebSocket connection established between the backend server and the target terminal device;
[0031] An online judgment module, used to respectively receive the first heartbeat message regularly sent by each of the target terminal devices, and to respectively judge whether each of the target terminal devices is online according to the message reception status of the heartbeat message, to obtain an online judgment result;
[0032] The object deletion module is used to delete the WebSocket connection object corresponding to the offline target terminal device in the record list if the online judgment result reflects that at least one of the target terminal devices is offline.
[0033] In a third aspect, an embodiment of the present application provides a storage medium, which stores computer-readable instructions. When the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the message broadcasting method described in any of the above embodiments.
[0034] In a fourth aspect, an embodiment of the present application provides a backend server, the backend server comprising: one or more processors, and a memory;
[0035] The memory stores computer-readable instructions, and when the computer-readable instructions are executed by the one or more processors, the steps of the message broadcasting method described in any of the above embodiments are performed.
[0036] In the message broadcasting method, device, storage medium and back-end server provided in some embodiments of the present application, the message subscription mechanism of Redis is introduced into the WebSocket protocol, so that the WebSocket message push is decoupled from the business logic processing, thereby simplifying the system architecture of the algorithm system and improving the independence between the various code modules. In this way, functional expansion and maintenance can be carried out more flexibly, thereby improving flexibility and scalability. At the same time, by decoupling the business logic from the WebSocket message push, the change of the business logic will not affect the implementation of WebSocket, thereby reducing the maintenance cost and difficulty of the algorithm system.
[0037] On the other hand, through Redis's asynchronous message push mechanism, business logic processing no longer depends on the sending of WebSocket messages, which can reduce the processing time of business logic, improve the response speed of the algorithm system, and improve the real-time performance of message broadcasting. In addition, through Redis's message subscription and publishing mechanism, it can better cope with a large number of messages in high-concurrency scenarios, thereby improving the system's high-concurrency processing capabilities. Since Redis has high availability and persistence mechanisms, even if the backend WebSocket server fails, the broadcast message will not be lost, thereby improving the system's fault tolerance and reliability. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0039] Figure 1 One of the flowcharts of the message broadcasting method in one embodiment;
[0040] Figure 2 This is a second flow chart of a message broadcasting method in one embodiment;
[0041] Figure 3 A schematic diagram of the structure of a message broadcasting device in one embodiment;
[0042] Figure 4 The internal structure diagram of the back-end server in one embodiment. DETAILED DESCRIPTION
[0043] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0044] The terms involved in this application are explained below.
[0045] Redis (Remote Dictionary Server): A key-value pair storage database that can implement message push functionality based on the publish / subscribe model. Specifically, message consumers can subscribe to a specific Redis channel. Whenever a message publisher publishes a message to the specific Redis channel, the message consumer can receive the message pushed by Redis, thus implementing message push.
[0046] WebSocket: A protocol for full-duplex communication over a single TCP (Transmission Control Protocol) connection, allowing two-way real-time communication between the client and the server. The server and the client can send and receive data at the same time, without waiting for the other party to respond, and without frequently establishing and closing the connection between the server and the client. The WebSocket protocol has the advantages of low latency, lightweight and good compatibility.
[0047] STOMP (Streaming Text Orientated Message Protocol): A simple text protocol designed for MOM (Message Oriented Middleware). The STOMP protocol provides an interoperable connection format that allows STOMP clients to interact with any STOMP message broker.
[0048] In one embodiment, the message broadcast method provided in this application can be applied to the scenario where the front-end device interacts with the back-end server. Among them, the front-end device can be a terminal device for direct interaction with the user, which can be but not limited to a handheld mobile terminal, a wearable smart device, a laptop computer, a desktop computer, etc. The back-end server can be a device for executing the commodity extraction algorithm, which can be implemented by a single server or a server cluster, and this document does not make specific restrictions on this.
[0049] Further, in one example, the backend server may include a business logic algorithm module and a WebSocket server. The business logic algorithm module refers to a module for executing a preset business logic code, and the WebSocket server may be a device for broadcasting messages according to the WebSocket protocol. It can be understood that the business logic algorithm module may be set in the WebSocket server, in which case the backend server may be implemented by one server. The business logic algorithm module may also be set in other servers besides the WebSocket server, in which case the backend server may include two or more servers.
[0050] Furthermore, in addition to the business logic algorithm module and the WebSocket server, the backend server may also include a Redis server. The Redis server may be a server for maintaining a Redis channel, and is used to send messages to devices that have subscribed to the Redis channel according to the message update status of the Redis channel.
[0051] In one embodiment, the present application provides a message broadcast method, and the following embodiment is described by taking the method applied to the backend server described above as an example. Figure 1 As shown, the message broadcasting method of the present application may include the following steps:
[0052] S102: In response to the commodity extraction request, the preset business logic code is executed and the latest queuing information and the latest commodity remaining information are generated respectively.
[0053] The commodity extraction request may be a request for instructing the backend server to execute the business logic code corresponding to the commodity extraction function, and may be triggered by the user operating the terminal device. The business logic code may be the program code corresponding to the commodity extraction function. In other words, the backend server may provide the user with the commodity extraction function by executing the business logic code.
[0054] In this step, when the business logic algorithm module of the backend server receives the commodity extraction request sent by the terminal device, it can execute the business logic code pre-set in the backend server to provide the user with a commodity extraction function. Each execution of the business logic code can be regarded as providing a commodity extraction service. The backend server can determine the extracted commodities involved in this commodity extraction service based on the execution result of this business logic code, and update the queue status and the remaining commodity information in the commodity warehouse accordingly, so as to generate the latest queue information and the latest remaining commodity information respectively.
[0055] S104: Generate a message to be broadcast according to the latest queue information and the latest commodity remaining information.
[0056] In this step, the business logic algorithm module of the back-end server can generate a to-be-broadcast message for pushing to the terminal device according to the latest queue information and the latest remaining commodity information, so that the to-be-broadcast message carries the latest queue information and the latest remaining commodity information. It can be understood that in this step, the back-end server can generate the to-be-broadcast message according to any message structure and in any way, and this document does not make any specific restrictions on this, as long as it meets the message requirements of the WebSocket protocol and the Redis message requirements.
[0057] S106: According to the preset Redis channel information, the message to be broadcast is published to the target Redis channel.
[0058] The preset Redis channel information may be the channel information of the target Redis channel. The target Redis channel may be the Redis channel subscribed by the backend server. Further, in one example, the target Redis channel may be the Redis channel subscribed by the WebSocket server.
[0059] In this step, the business logic algorithm module of the backend server can publish the message to be broadcast to the target Redis channel.
[0060] S108: Receive the message to be broadcast sent by the target Redis channel.
[0061] In this step, when a message to be broadcast is generated, the business logic algorithm module of the backend server can publish the message to be broadcast to a specified channel of Redis, so as to push the message to be broadcast to the WebSocket server by utilizing the message subscription mechanism of Redis.
[0062] Specifically, the backend server can publish the message to be broadcast to the target Redis channel according to the preset Redis channel information. Since the WebSocket server in the backend server has subscribed to the target Redis channel, whenever a new message is published to the target Redis channel, Redis will push the newly published message to the WebSocket server, so that the WebSocket server can obtain the message to be broadcast.
[0063] In this way, message broadcasting can be performed based on the asynchronous message push mechanism of Redis, and the processing of business logic no longer depends on the sending of WebSocket messages, thus realizing the decoupling of business logic and WebSocket message push, making business logic and the sending of WebSocket messages independent of each other, and solving the problem of strong coupling between WebSocket and business logic. At the same time, it can also reduce the waiting time of business logic code and improve the overall response speed of the algorithm system to product extraction requests.
[0064] S110: Determine each target terminal device, and push the message to be broadcast to each target terminal device based on the WebSocket protocol.
[0065] The target terminal device is a terminal device that establishes a WebSocket connection with the backend server.
[0066] In this step, after receiving the to-be-broadcast message sent by the target Redis channel, the WebSocket server of the backend server can push the to-be-broadcast message to the front-end user based on the WebSocket protocol to realize message broadcasting.
[0067] This application introduces the Redis message subscription mechanism into the WebSocket protocol, so that the WebSocket message push is decoupled from the business logic processing, thereby simplifying the system architecture of the algorithm system and improving the independence between the various code modules. In this way, functional expansion and maintenance can be carried out more flexibly, thereby improving flexibility and scalability. At the same time, by decoupling the business logic from the WebSocket message push, changes in the business logic will not affect the implementation of WebSocket, thereby reducing the maintenance cost and difficulty of the algorithm system.
[0068] On the other hand, through Redis's asynchronous message push mechanism, business logic processing no longer depends on the sending of WebSocket messages, which can reduce the processing time of business logic, improve the response speed of the algorithm system, and improve the real-time performance of message broadcasting. In addition, through Redis's message subscription and publishing mechanism, it can better cope with a large number of messages in high-concurrency scenarios, thereby improving the system's high-concurrency processing capabilities. Since Redis has high availability and persistence mechanisms, even if the backend WebSocket server fails, the broadcast message will not be lost, thereby improving the system's fault tolerance and reliability.
[0069] In one embodiment, the WebSocket protocol may be the STOMP protocol. In other words, the WebSocket server of the backend server may push the message to be broadcast to the frontend user through the STOMP protocol. In this way, message broadcasting may be achieved through the combination of the STOMP protocol and the Redis subscription mechanism, thereby ensuring the stability and reliability of message broadcasting.
[0070] In one embodiment, the message broadcasting method of the present application may further include the following steps:
[0071] Step A1: Generate or update a record list of various WebSocket connection objects according to the received WebSocket connection request; wherein the WebSocket connection object is generated according to the WebSocket connection established between the backend server and the target terminal device;
[0072] Step A3: receiving the first heartbeat message sent regularly by each target terminal device respectively, and judging whether each target terminal device is online according to the reception status of the heartbeat message respectively, and obtaining an online judgment result;
[0073] Step A5: If the online determination result reflects that at least one target terminal device is offline, the WebSocket connection object corresponding to the offline target terminal device is deleted from the record list.
[0074] In this embodiment, the back-end server can periodically detect whether the target terminal device is online based on the heartbeat detection algorithm, and promptly discover and delete the WebSocket connection object corresponding to the offline device based on the online judgment result, so as to avoid occupying server resources due to invalid connections and reduce the resource pressure of the back-end server.
[0075] Specifically, the terminal device can send a WebSocket connection request to the WebSocket server to request to establish a WebSocket connection with the WebSocket server. When the WebSocket server receives the WebSocket connection request, it can generate or update the record list accordingly, so that the record list can comprehensively record the WebSocket connection objects corresponding to each target terminal device.
[0076] The target terminal device can periodically send a first heartbeat message to the WebSocket server to reflect to the WebSocket server that the device is online. Therefore, the WebSocket server can receive the first heartbeat message sent by each target terminal device respectively, and judge the online status of each target terminal device accordingly. For example, when the WebSocket server receives the first heartbeat message, it can record the reception time of the first heartbeat message and the device identifier of the target terminal device that sent the first heartbeat message. The WebSocket server can judge the latest online time of each target terminal device according to the reception time corresponding to each first heartbeat message and its corresponding device identifier, and judge whether each target terminal device is online according to the current time and the latest online time of each target terminal device.
[0077] If at least one target terminal device is offline, that is, at least one target terminal device is offline, the WebSocket server can delete the WebSocket connection object corresponding to the offline target terminal device in the record list. In this way, on the one hand, the accuracy of the record list content can be improved, and on the other hand, the resource pressure of the WebSocket server can be reduced.
[0078] In one embodiment, S110 may include: for each WebSocket connection object recorded in the record list, based on the WebSocket protocol, pushing the message to be broadcast to a target terminal device corresponding to the WebSocket connection object.
[0079] In this embodiment, the WebSocket server can broadcast messages according to the WebSocket connection objects recorded in the record list, so as to push the message to be broadcast to each target terminal device comprehensively and accurately. Specifically, the WebSocket server traverses each WebSocket connection object in the record list, and pushes the message to be broadcast to the target terminal device corresponding to each WebSocket connection object based on the WebSocket protocol.
[0080] In one embodiment, the message broadcasting method of the present application may further include the following steps:
[0081] Step B1: in response to the start of the scheduled task, obtain the current timestamp, and generate a second heartbeat message according to the current timestamp;
[0082] Step B3: Send a second heartbeat message to the Redis server used to maintain the target Redis channel.
[0083] In this embodiment, the WebSocket server can periodically send a second heartbeat message to the Redis server, so that the Redis server can determine whether the WebSocket server is online based on the received second heartbeat message, and judge whether the WebSocket server can consume messages in the target Redis channel. When the WebSocket server is offline due to equipment failure or communication failure, the Redis server can determine that the WebSocket has been offline based on the reception of the second heartbeat message, and send the WebSocket server the message in the target Redis channel that the WebSocket server has not consumed when the WebSocket server is back online. In this way, the high availability and persistence mechanism of Redis can be used to realize message broadcasting, avoid the loss of the broadcast message when the WebSocket server is offline, thereby improving the fault tolerance and reliability of the system.
[0084] To facilitate understanding of the solution of the present application, a specific example is provided below for illustration.
[0085] like Figure 2 As shown, the message broadcasting method based on the STOMP protocol in the present application may include the following steps:
[0086] S202: The terminal device sends a product extraction request to the business logic algorithm module;
[0087] S204: the business logic algorithm module executes the preset business logic code in response to the commodity extraction request, and generates a message to be broadcast; wherein the message to be broadcast includes the latest queuing information and the latest commodity remaining information;
[0088] S206: The business logic algorithm module publishes the message to be broadcast to the target Redis channel;
[0089] S208: The target Redis channel sends the message to be broadcast to the WebSocket server;
[0090] S210: The WebSocket server pushes the message to be broadcast to the terminal device.
[0091] The message broadcasting device provided in an embodiment of the present application is described below. The message broadcasting device described below and the message broadcasting method described above can be referenced to each other.
[0092] In one embodiment, Figure 3 As shown, the present application provides a message broadcasting device 300, comprising:
[0093] The business execution module 302 is used to respond to the commodity extraction request, execute the preset business logic code and generate the latest queue information and the latest commodity remaining information respectively;
[0094] A message generating module 304, configured to generate a message to be broadcast according to the latest queuing information and the latest remaining commodity information;
[0095] The message publishing module 306 is used to publish the message to be broadcast to the target Redis channel according to the preset Redis channel information; the target Redis channel is the Redis channel subscribed by the backend server;
[0096] A message receiving module 308, configured to receive the message to be broadcast sent by the target Redis channel;
[0097] The message push module 310 is used to determine each target terminal device and push the to-be-broadcast message to each target terminal device based on the WebSocket protocol; wherein the target terminal device is a terminal device that establishes a WebSocket connection with the backend server.
[0098] In one embodiment, the WebSocket protocol is the STOMP protocol.
[0099] In one embodiment, the message broadcasting device 300 of the present application further includes:
[0100] A list generation module, used to generate or update a record list of various WebSocket connection objects according to the received WebSocket connection request; wherein the WebSocket connection object is generated according to the WebSocket connection established between the backend server and the target terminal device;
[0101] An online judgment module, used to respectively receive the first heartbeat message regularly sent by each of the target terminal devices, and to respectively judge whether each of the target terminal devices is online according to the message reception status of the heartbeat message, to obtain an online judgment result;
[0102] The object deletion module is used to delete the WebSocket connection object corresponding to the offline target terminal device in the record list if the online judgment result reflects that at least one of the target terminal devices is offline.
[0103] In one embodiment, the message push module 310 of the present application includes:
[0104] The push unit is used to push the message to be broadcast to the target terminal device corresponding to each WebSocket connection object recorded in the record list based on the WebSocket protocol.
[0105] In one embodiment, the message broadcasting device 300 of the present application further includes:
[0106] A heartbeat message generating module 304, configured to obtain a current timestamp in response to the start of a scheduled task, and generate a second heartbeat message according to the current timestamp;
[0107] A heartbeat message sending module is used to send the second heartbeat message to the Redis server used to maintain the target Redis channel.
[0108] In one embodiment, the present application further provides a storage medium storing computer-readable instructions. When the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the message broadcasting method in any embodiment.
[0109] In one embodiment, the present application also provides a back-end server, in which computer-readable instructions are stored. When the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the message broadcasting method in any embodiment.
[0110] Indicatively, Figure 4 A schematic diagram of the internal structure of a backend server provided in an embodiment of the present application. Figure 4 The backend server 900 includes a processing component 902, which further includes one or more processors, and a memory resource represented by a memory 901, for storing instructions that can be executed by the processing component 902, such as an application. The application stored in the memory 901 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 902 is configured to execute instructions to perform the steps of the message broadcast method described in any of the above embodiments.
[0111] The backend server 900 may further include a power supply component 903 configured to perform power management of the backend server 900, a wired or wireless network interface 904 configured to connect the backend server 900 to the network, and an input / output (I / O) interface 905. The backend server 900 may operate based on an operating system stored in the memory 901, such as Windows Server TM, Mac OS X TM, Unix TM, Linux TM, Free BSD TM or the like.
[0112] Those skilled in the art will understand that the internal structure of the computer device shown in the present application is merely a block diagram of a partial structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0113] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is any such actual relationship or order between these entities or operations. Moreover, the term "include", "comprise" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or equipment including a series of elements not only includes those elements, but also includes other elements not clearly listed, or also includes elements inherent to such process, method, article or equipment. In the absence of more restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the process, method, article or equipment including the elements. Herein, "one", "one", "said", "the" and "it" may also include plural forms, unless the context clearly indicates another way. A plurality refers to at least two cases, such as 2, 3, 5 or 8, etc. "And / or" includes any and all combinations of the relevant listed items.
[0114] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can refer to each other.
[0115] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A message broadcasting method, characterized in that: Applicable to backend servers, including: In response to a product extraction request, the preset business logic code is executed and the latest queue information and the latest product remaining information are generated respectively; Generate a message to be broadcast according to the latest queuing information and the latest remaining commodity information; According to the preset Redis channel information, the message to be broadcast is published to the target Redis channel; the target Redis channel is the Redis channel subscribed by the backend server; Receiving the message to be broadcast sent by the target Redis channel; Determine each target terminal device, and push the message to be broadcast to each target terminal device based on the WebSocket protocol; wherein the target terminal device is a terminal device that establishes a WebSocket connection with the backend server.
2. The method according to claim 1, characterized in that The WebSocket protocol is the STOMP protocol.
3. The method according to claim 1 or 2, characterized in that: The method further comprises: Generate or update a record list of each WebSocket connection object according to the received WebSocket connection request; wherein the WebSocket connection object is generated according to the WebSocket connection established between the backend server and the target terminal device; Respectively receiving the first heartbeat message regularly sent by each of the target terminal devices, and judging whether each of the target terminal devices is online according to the reception status of the heartbeat message, to obtain an online judgment result; If the online determination result reflects that at least one of the target terminal devices is offline, the WebSocket connection object corresponding to the offline target terminal device is deleted from the record list.
4. The method according to claim 3, characterized in that The determining of each target terminal device and pushing the to-be-broadcast message to each target terminal device based on the WebSocket protocol includes: For each of the WebSocket connection objects recorded in the record list, based on the WebSocket protocol, the message to be broadcast is pushed to the target terminal device corresponding to the WebSocket connection object.
5. The method according to claim 1 or 2, characterized in that: The method further comprises: In response to the start of the scheduled task, obtaining a current timestamp, and generating a second heartbeat message according to the current timestamp; The second heartbeat message is sent to a Redis server used to maintain the target Redis channel.
6. A message broadcasting device, characterized in that: Applicable to backend servers, including: A business execution module, for responding to a commodity extraction request, executing a preset business logic code and generating the latest queue information and the latest commodity remaining information; A message generation module, used to generate a message to be broadcast according to the latest queuing information and the latest remaining commodity information; A message publishing module, used for publishing the message to be broadcast to a target Redis channel according to the preset Redis channel information; the target Redis channel is a Redis channel subscribed by the backend server; A message receiving module, used for receiving the message to be broadcast sent by the target Redis channel; The message push module is used to determine each target terminal device and push the message to be broadcast to each target terminal device based on the WebSocket protocol; wherein the target terminal device is a terminal device that establishes a WebSocket connection with the backend server.
7. The device according to claim 6, characterized in that The WebSocket protocol is the STOMP protocol.
8. The device according to claim 6 or 7, characterized in that The device also includes: A list generation module, used to generate or update a record list of various WebSocket connection objects according to the received WebSocket connection request; wherein the WebSocket connection object is generated according to the WebSocket connection established between the backend server and the target terminal device; An online judgment module, used to respectively receive the first heartbeat message regularly sent by each of the target terminal devices, and to respectively judge whether each of the target terminal devices is online according to the message reception status of the heartbeat message, to obtain an online judgment result; The object deletion module is used to delete the WebSocket connection object corresponding to the offline target terminal device in the record list if the online judgment result reflects that at least one of the target terminal devices is offline.
9. A storage medium, characterized in that: The storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the message broadcasting method according to any one of claims 1 to 5.
10. A backend server, characterized in that: include: one or more processors, and memory; The memory stores computer-readable instructions, and when the computer-readable instructions are executed by the one or more processors, the steps of the message broadcasting method according to any one of claims 1 to 5 are performed.
