Message push method, device, electronic device and storage medium
By obtaining the routing status of the client and pushing the message to the Websocket node connected to it, the problem of message discarding when the node is not connected in the existing technology is solved, and the efficiency of message push is improved.
Patent Information
- Application Number
- CN202211269247.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-17
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2042-10-17
AI Technical Summary
In the existing technology, nodes with no connection between Websocket nodes and the client will receive and discard messages when messages are pushed, resulting in a waste of network traffic and node computing resources.
By obtaining the routing status of the target client, the target Websocket node that has a connection relationship with the target client is determined from multiple Websocket nodes, and the message to be pushed is only pushed to this node so that it can be sent to the client.
It avoids useless network traffic and waste of node computing resources, and improves the efficiency of message push.
Smart Images

Figure CN115514809B
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of message push, and in particular to a message push method, device, electronic device and storage medium. Background Art
[0002] This section is intended to provide a background or context to the embodiments of the application that are recited in the claims. No description herein is admitted to be prior art by inclusion in this section.
[0003] Websocket is a protocol for full-duplex communication over a single TCP connection. With Websocket, the browser and server only need to shake hands once to directly create a persistent connection between the two and perform two-way data transmission. Websocket distributed clusters are usually used to dispatch tasks from the server to the front end (user end), and the user may have established a connection with one or more nodes in the Websocket distributed cluster. In the current related technology, message broadcast push is mainly used. In this way, Websocket nodes that have not established a connection with the specified user end can also receive messages pushed to the user end, but can only discard the message, doing useless work and wasting a lot of network traffic and node computing resources. Summary of the invention
[0004] In view of this, the purpose of the present application is to provide a message push method, device, electronic device and storage medium.
[0005] Based on the above purpose, the present application provides a message push method, which is applied to a message push system based on Websocket, wherein the message push system includes multiple Websocket nodes; the method includes:
[0006] Get the routing status of the target user end;
[0007] Determine a target Websocket node having a connection relationship with the target user terminal from the multiple Websocket nodes based on the routing state;
[0008] The message to be pushed is pushed to the target Websocket node, so that the target Websocket node sends the message to be pushed to the target user terminal.
[0009] Based on the same inventive concept, the exemplary embodiment of the present application further provides a message push device, including:
[0010] The acquisition module obtains the routing status of the target user end;
[0011] A determination module, which determines a target Websocket node having a connection relationship with the target user terminal from the multiple Websocket nodes based on the routing state;
[0012] The push module pushes the message to be pushed to the target Websocket node, so that the target Websocket node sends the message to be pushed to the target user terminal.
[0013] Based on the same inventive concept, an exemplary embodiment of the present application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable by the processor, wherein the processor implements the message push method as described above when executing the program.
[0014] Based on the same inventive concept, an exemplary embodiment of the present application further provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the message pushing method as described above.
[0015] From the above, it can be seen that the message push method, device, electronic device and storage medium provided by the present application obtain the routing status of the target user end; determine the target Websocket node that has a connection relationship with the target user end from the multiple Websocket nodes based on the routing status; push the message to be pushed to the target Websocket node, so that the target Websocket node sends the message to be pushed to the target user end, so that the Websocket node will only receive messages from the user end that has established a connection with itself, there is no waste of network traffic and node computing power, and the efficiency of message push is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the present application or related technologies, the drawings required for use in the embodiments or related technical descriptions are briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0017] Figure 1 It is a structural diagram of a message push system based on Websocket in the related technology;
[0018] Figure 2 This is a schematic diagram of the structure of a message push system based on Websocket in an embodiment of the present application;
[0019] Figure 3A flowchart of a message push method according to an embodiment of the present application;
[0020] Figure 4 This is a schematic diagram of the structure of another message push device according to an embodiment of the present application;
[0021] Figure 5 A schematic diagram of the structure of a specific electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0022] The principles and spirit of the present application will be described below with reference to several exemplary embodiments. It should be understood that these embodiments are provided only to enable those skilled in the art to better understand and implement the present application, and are not intended to limit the scope of the present application in any way. On the contrary, these embodiments are provided to make the present application more thorough and complete, and to fully convey the scope of the present application to those skilled in the art.
[0023] According to the implementation manner of the present application, a message push method, device, electronic device and storage medium are proposed.
[0024] It should be understood herein that any number of elements in the drawings is for illustration rather than limitation, and any naming is only for distinction rather than having any limiting meaning.
[0025] The principles and spirit of the present application are explained in detail below with reference to several representative implementations of the present application. SUMMARY OF THE INVENTION
[0027] At present, the related technologies mainly push messages through message broadcasting. In this way, Websocket nodes that have not established a connection with the specified client can also receive messages pushed to the client, but can only discard the message, doing useless work and wasting a lot of network traffic and node computing resources. Figure 1 In the related art, when a server sends a push message to a certain client, it will send the push message to all Websocket nodes (Websocket nodes 1-4). However, since the current client is only connected to Websocket node 1, the push message can only be sent to the client through Websocket node 1. If the push message is sent to Websocket nodes 2-4 at the same time, the message will be discarded, wasting a lot of network traffic and node computing resources.
[0028] In order to solve the above problems, the present application provides a message push method, which specifically includes:
[0029] Acquire the routing status of the target user end; determine the target Websocket node that has a connection relationship with the target user end from the multiple Websocket nodes based on the routing status; push the message to be pushed to the target Websocket node, so that the target Websocket node sends the message to be pushed to the target user end, so that the Websocket node will only receive messages from the user end that has established a connection with itself, without wasting network traffic and node computing power, and improving the efficiency of message pushing. Reference Figure 2 When the server sends a push message to a certain user end (target user end), it will first determine which Websocket nodes have a connection relationship with the target user end through the routing status of the target user end. When it is determined that only Websocket node 1 has a connection relationship with the target user end, it only needs to send the push message to Websocket node 1, and there is no need to send the push message to Websocket nodes 2-4, which avoids the waste of network traffic and node computing power and improves the efficiency of message push.
[0030] After introducing the basic principles of the present application, various non-limiting implementation methods of the present application are described in detail below.
[0031] Application Scenario Overview
[0032] In some specific application scenarios, the message push method of the present application can be applied to various platforms or systems involving message push.
[0033] The message push method according to the exemplary implementation of the present application is described below in conjunction with a specific application scenario. It should be noted that the above application scenario is only shown to facilitate understanding of the spirit and principle of the present application, and the implementation of the present application is not limited in this respect. On the contrary, the implementation of the present application can be applied to any applicable scenario.
[0034] Exemplary Methods
[0035] refer to Figure 3 The embodiment of the present application provides a message push method, which is applied to a message push system based on Websocket, wherein the message push system includes multiple Websocket nodes; the method includes the following steps:
[0036] S101, obtaining the routing status of the target user terminal.
[0037] In specific implementation, the routing status of the target user end is used to indicate which Websocket nodes the target user end has established a connection with. Optionally, the routing status of multiple users can be saved in a database, and then the routing status of the target user end can be obtained from the database. Optionally, the target user end can be any user end, and the target user end is mainly used to indicate the user end that is currently going to receive the message to be pushed. The target user end can be set as needed, and there is no limitation on this.
[0038] In some embodiments, the routing state is stored via redis.
[0039] In the specific implementation, Redis (Remote Dictionary Server), i.e., remote dictionary service, is an open source log-type, Key-Value database written in ANSI C language, supporting the network, memory-based and persistent, and provides APIs in multiple languages. Optionally, the routing state can also be saved through other databases in the prior art, which is not limited to this.
[0040] S102: Determine a target Websocket node having a connection relationship with the target client from the multiple Websocket nodes based on the routing state.
[0041] In a specific implementation, after the routing status of the target user terminal is obtained, the target Websocket node having a connection relationship with the target user terminal can be determined from the multiple Websocket nodes according to the routing status.
[0042] S103: Push the message to be pushed to the target Websocket node, so that the target Websocket node sends the message to be pushed to the target user terminal.
[0043] In specific implementation, after determining the target Websocket node that has a connection relationship with the target user terminal, the message to be pushed can be pushed to the target Websocket node, so that the target Websocket node sends the message to be pushed to the target user terminal.
[0044] It should be noted that there may be multiple target Websocket nodes that have a connection relationship with the target user terminal. In this case, each target Websocket node will receive the message to be pushed, so that each target Websocket node sends the message to be pushed to the target user terminal. Optionally, the target user terminal may establish connections with different Websocket nodes in different states. For example, the same user terminal may establish connections with different Websocket nodes in different geographical areas, and all these connections will be recorded in the routing state of the user terminal to ensure that the user terminal can receive the message to be pushed in each geographical area.
[0045] It should be noted that, in some embodiments, Rabbitmq (an open source message queue service software) can be used to push the message to be pushed to the target Websocket node. At this time, the corresponding push message will be sent to the message queue on Rabbitmq corresponding to the target Websocket node. In addition, technical personnel in this field can also choose other methods as needed to push the message to be pushed to the target Websocket node, and there is no limitation on this.
[0046] In some embodiments, determining a target Websocket node having a connection relationship with the target client from the multiple Websocket nodes based on the routing state specifically includes:
[0047] Obtain a first routing key of each Websocket node in the plurality of Websocket nodes;
[0048] Determine a second routing key of the target user terminal based on the routing state, and determine a target first routing key corresponding to the second routing key;
[0049] The Websocket node corresponding to the target first routing key is determined as the target Websocket node.
[0050] In a specific implementation, each Websocket node has a unique first routing key. When determining the target Websocket node that has a connection relationship with the target user terminal from the multiple Websocket nodes, the second routing key of the target user terminal is first determined according to the routing status of the target user terminal. Optionally, the second routing key can be multiple or one, which is not limited here. Each first routing key corresponds to a second routing key, indicating that a connection relationship is established between the two. Optionally, a corresponding set of second routing keys and the first routing key can be exactly the same routing keys, that is, when the first routing key is the same as the second routing key, it means that the two correspond. Optionally, the corresponding relationship between the first routing key and the second routing key can also be determined by a preset relationship list, which is not limited to this.
[0051] In some embodiments, determining the second routing key of the target client based on the routing state specifically includes:
[0052] Acquire a first target value having a value of 1 and a first position of the first target value in the routing state; wherein the routing state is represented by a binary number;
[0053] The second routing key is determined based on the first target value and the first position; wherein the second routing key is a binary number.
[0054] In specific implementation, the routing state is represented by binary numbers, wherein the first target values at different positions in the routing state determine the second routing key of the target user end. For example, routing state 101 can be converted to the second routing key 1.0.1, and routing state 1000 can be converted to the second routing key 1.0.0.0.
[0055] It should be noted that, in order to facilitate the matching of the first routing key and the second routing key, the first routing key of each Websocket node can be represented by a wildcard. For example, when the second routing key is 1.0.1, the first routing key corresponding to the second routing key 1.0.1 is: #.1 and #.1.*.*, where "#" indicates that there are words greater than or equal to 0, and "*" indicates that there is a word. When the first routing key of each Websocket node is represented by a wildcard and the second routing key of the target user end is a value, all first routing keys corresponding to the second routing key of the current target user end can be directly determined by fuzzy matching.
[0056] In some embodiments, there are multiple second routing keys; determining a target first routing key corresponding to the second routing key specifically includes:
[0057] For each second routing key among the plurality of second routing keys, determining the first routing key corresponding to the second routing key; wherein the first routing key is represented by a binary number and has only one value of 1;
[0058] All the first routing keys corresponding to the second routing keys are determined as the target first routing keys.
[0059] In specific implementation, the first routing key is represented by a binary digit and has only one value of 1. For example, there are currently three first routing keys: 1, 1.0, and 1.0.0. The current routing state of the target user terminal is: 101, and the second routing keys obtained according to the routing state of the target user terminal are: 1 and 1.0.0. Then, the two first routing keys 1 and 1.0.0 of the above three first routing keys can be determined as the target first routing keys. It should be noted that when there are multiple second routing keys for the target user terminal, each second routing key is represented by a binary digit and has only one value of 1.
[0060] In some embodiments, determining a target Websocket node having a connection relationship with the target client from the multiple Websocket nodes based on the routing state specifically includes:
[0061] Obtain a first routing key of each Websocket node in the plurality of Websocket nodes; wherein the first routing key is represented by a binary number and has only one value of 1;
[0062] Determine a second position of a second target value having a value of 1 in the first routing key;
[0063] Obtaining a first position of a first target value having a value of 1 in the routing state; wherein the routing state is represented by a binary number;
[0064] The target Websocket node is determined based on the first location and the second location.
[0065] In specific implementation, when the routing state of the target user terminal is 101, the second position of the corresponding second target value has two positions, which are the first and third positions from right to left. At this time, it is only necessary to determine which two first routing keys have the first positions of the first and third positions from right to left, respectively, to determine the target Websocket node. Optionally, the first routing key of each Websocket node can be represented by a wildcard, such as the commonly used wildcards "#" and "*", where "#" indicates that there are words greater than or equal to 0, and "*" indicates that there is a word, and the words are separated by ".", then the first routing keys whose first positions are the first and third positions from right to left can be represented as: #.1 and #.1.*.*.
[0066] In some embodiments, before obtaining the routing status of the target user terminal, the method further includes:
[0067] In response to determining that the target user establishes a connection with the target Websocket node, updating the routing state based on a response to the establishment of the connection and a routing node state of the target Websocket node;
[0068] In response to determining that the target user is disconnected from the target Websocket node, the routing state is updated based on a response to the disconnection and a routing node state of the target Websocket node.
[0069] In specific implementation, when determining the routing state of the target user terminal, optionally, the initial routing state of the target user terminal can be set to 0, that is, no connection is established with any Websocket node. Then, when the target user establishes a connection with the target Websocket node, the routing state is updated according to the routing node state of the target Websocket node, that is, the first routing key is added to the routing state before the update. When the target user is disconnected from the target Websocket node, the routing state is updated according to the routing node state of the target Websocket node, that is, the first routing key is subtracted from the routing state before the update. In this way, it can be ensured that the routing state of the target user terminal is always in the latest state, so that the push message can be accurately sent to the target Websocket node, and further ensure that the target user terminal can receive the push message.
[0070] In some embodiments, updating the routing state based on the response to establishing the connection and the routing node state of the target Websocket node specifically includes:
[0071] Obtaining the routing node state and the routing state before updating; wherein the routing state is represented by a binary number, and the routing node state is represented by a binary number and has only one value of 1;
[0072] An AND operation is performed on the routing node state and the routing state before the update, and the routing state is updated based on the result of the AND operation.
[0073] In specific implementation, for example, if the routing state of the target user terminal before the update is 10, and the routing node state of the target Websocket node that has established a connection relationship with the target user terminal is 100, then the routing state of the updated target user terminal can be obtained by performing an "AND" operation on 100 and 10, which is 110. Thus, the updated routing state can be obtained quickly. Optionally, each Websocket node stores its own routing node state, and its corresponding routing node state can be directly obtained from the target Websocket node.
[0074] In some embodiments, updating the routing state based on the disconnection response and the routing node state of the target Websocket node specifically includes:
[0075] Obtaining the routing node state and the routing state before updating; wherein the routing state is represented by a binary number, and the routing node state is represented by a binary number and has only one value of 1;
[0076] An XOR operation is performed on the routing node state and the routing state before the update, and the routing state is updated based on the result of the XOR operation.
[0077] In specific implementation, for example, if the routing state of the target user terminal before the update is 111, and the routing node state of the target Websocket node that has disconnected from the target user terminal is 100, performing an "XOR" operation on 111 and 100 can obtain the routing state of the updated target user terminal as 011 (i.e., 11). Thus, the routing state can be quickly updated based on the disconnection response and the routing node state of the target Websocket node.
[0078] In some embodiments, after updating the routing state, the method further comprises:
[0079] In response to determining that all values in the updated routing state are 0, deleting the updated routing state;
[0080] The routing status is represented by binary numbers.
[0081] In specific implementation, when all values in the updated routing state are 0, it means that the target client has no connection with all Websocket nodes at this time. In order to save memory, the updated routing state can be directly deleted.
[0082] The message push method provided by the present application is applied to a message push system based on Websocket, wherein the message push system includes multiple Websocket nodes; the method first obtains the routing status of the target user terminal; then, based on the routing status, a target Websocket node having a connection relationship with the target user terminal is determined from the multiple Websocket nodes; finally, the message to be pushed is pushed to the target Websocket node, so that the target Websocket node sends the message to be pushed to the target user terminal, so that the Websocket node only receives messages from the user terminal that has established a connection with itself, there is no waste of network traffic and node computing power, and the efficiency of message push is improved. In addition, in the related art, a consistent hashing algorithm is used to ensure that the push message is sent to the corresponding Websocket node, and then pushed to the user end by the corresponding Websocket node. However, this method requires the establishment of a service registration center and a gateway. After the Websocket node is started, it needs to register with the service registration center. The service registration center uses a consistent hashing algorithm to build a hash ring based on the registered Websocket nodes. The Websocket nodes are distributed on the hash ring. The addition or deletion of Websocket nodes will cause the connection of some users to be unavailable. At the same time, it is necessary to set up an additional service registration center to implement the consistent hashing algorithm, which increases the complexity of the system and increases the system maintenance burden on developers. In comparison, the method of the embodiment of the present application has no additional system construction cost and subsequent maintenance cost, and is simple to implement. At the same time, adding or deleting a part of the Websocket nodes will not affect other Websocket nodes, that is, the connection established between the user end and other Websocket nodes will not be disturbed.
[0083] Exemplary Devices
[0084] Based on the same inventive concept, corresponding to any of the above-mentioned embodiment methods, the present application also provides a message pushing device.
[0085] refer to Figure 4 , the message push system comprises:
[0086] Acquisition module 201, acquiring the routing status of the target user terminal;
[0087] A determination module 202, which determines a target Websocket node having a connection relationship with the target client from the multiple Websocket nodes based on the routing state;
[0088] The push module 203 pushes the message to be pushed to the target Websocket node, so that the target Websocket node sends the message to be pushed to the target user terminal.
[0089] For the convenience of description, the above system is described by dividing the functions into various modules. Of course, when implementing the present application, the functions of each module can be implemented in the same or multiple software and / or hardware.
[0090] The system of the above embodiment is used to implement the corresponding message push method in any of the above embodiments, and has the beneficial effects of the corresponding method embodiment, which will not be repeated here.
[0091] Based on the same inventive concept, corresponding to any of the above-mentioned embodiment methods, the present application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the message push method described in any of the above embodiments is implemented.
[0092] Figure 5 A more specific schematic diagram of the hardware structure of an electronic device provided in this embodiment is shown, and the device may include: a processor 1010, a memory 1020, an input / output interface 1030, a communication interface 1040, and a bus 1050. The processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040 are connected to each other through the bus 1050 in the device.
[0093] The processor 1010 can be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.
[0094] The memory 1020 may be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 1020 may store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program codes are stored in the memory 1020 and are called and executed by the processor 1010.
[0095] The input / output interface 1030 is used to connect the input / output module to realize information input and output. The input / output module can be configured in the device as a component (not shown in the figure), or it can be externally connected to the device to provide corresponding functions. The input device may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output device may include a display, a speaker, a vibrator, an indicator light, etc.
[0096] The communication interface 1040 is used to connect a communication module (not shown) to realize communication interaction between the device and other devices. The communication module can realize communication through a wired mode (such as USB, network cable, etc.) or a wireless mode (such as mobile network, WIFI, Bluetooth, etc.).
[0097] The bus 1050 includes a path that transmits information between the various components of the device (eg, the processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040).
[0098] It should be noted that, although the above device only shows the processor 1010, the memory 1020, the input / output interface 1030, the communication interface 1040 and the bus 1050, in the specific implementation process, the device may also include other components necessary for normal operation. In addition, it can be understood by those skilled in the art that the above device may also only include the components necessary for implementing the embodiments of the present specification, and does not necessarily include all the components shown in the figure.
[0099] The electronic device of the above embodiment is used to implement the corresponding message push method in any of the above embodiments, and has the beneficial effects of the corresponding method embodiment, which will not be repeated here.
[0100] Exemplary Program Products
[0101] Based on the same inventive concept, corresponding to any of the above-mentioned embodiment methods, the present application also provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the message push method described in any of the above embodiments.
[0102] The computer-readable medium of this embodiment includes permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device.
[0103] The computer instructions stored in the storage medium of the above embodiment are used to enable the computer to execute a message push method as described in any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0104] Those skilled in the art should understand that the discussion of any of the above embodiments is merely illustrative and is not intended to imply that the scope of the present application (including the claims) is limited to these examples; based on the concept of the present application, the technical features in the above embodiments or different embodiments may be combined, the steps may be implemented in any order, and there are many other variations of the different aspects of the embodiments of the present application as described above, which are not provided in detail for the sake of simplicity.
[0105] In addition, to simplify the description and discussion, and in order not to make the embodiments of the present application difficult to understand, the known power supply / ground connection with the integrated circuit (IC) chip and other components may or may not be shown in the provided drawings. In addition, the device can be shown in the form of a block diagram to avoid making the embodiments of the present application difficult to understand, and this also takes into account the fact that the details of the implementation of these block diagram devices are highly dependent on the platform to be implemented in the embodiments of the present application (that is, these details should be fully within the scope of understanding of those skilled in the art). In the case of elaborating specific details (e.g., circuits) to describe exemplary embodiments of the present application, it is obvious to those skilled in the art that the embodiments of the present application can be implemented without these specific details or when these specific details are changed. Therefore, these descriptions should be considered to be illustrative rather than restrictive.
[0106] Although the present application has been described in conjunction with specific embodiments of the present application, many replacements, modifications and variations of these embodiments will be apparent to those skilled in the art from the foregoing description. For example, other memory architectures (e.g., dynamic RAM (DRAM)) may use the embodiments discussed.
[0107] The embodiments of the present application are intended to cover all such substitutions, modifications and variations that fall within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the embodiments of the present application should be included in the scope of protection of the present application.
Claims
1. A message push method, characterized in that: The method is applied to a message push system based on Websocket, wherein the message push system includes multiple Websocket nodes; the method includes: Get the routing status of the target user end; Determine a target Websocket node having a connection relationship with the target user terminal from the multiple Websocket nodes based on the routing state; Pushing the message to be pushed to the target Websocket node, so that the target Websocket node sends the message to be pushed to the target user terminal; Wherein, determining a target Websocket node having a connection relationship with the target user terminal from the multiple Websocket nodes based on the routing state specifically includes: Obtain a first routing key of each Websocket node in the plurality of Websocket nodes; wherein the first routing key is represented by a binary number and has only one value of 1; Determine a second position of a second target value having a value of 1 in the first routing key; Obtaining a first position of a first target value having a value of 1 in the routing state; wherein the routing state is represented by a binary number; The target Websocket node is determined based on the first location and the second location.
2. The method according to claim 1, characterized in that Determining a target Websocket node having a connection relationship with the target user terminal from the multiple Websocket nodes based on the routing state specifically includes: Obtain a first routing key of each Websocket node in the plurality of Websocket nodes; Determine a second routing key of the target user terminal based on the routing state, and determine a target first routing key corresponding to the second routing key; The Websocket node corresponding to the target first routing key is determined as the target Websocket node.
3. The method according to claim 2, characterized in that Determining the second routing key of the target user terminal based on the routing state specifically includes: Acquire a first target value having a value of 1 and a first position of the first target value in the routing state; wherein the routing state is represented by a binary number; The second routing key is determined based on the first target value and the first position; wherein the second routing key is represented by a binary number.
4. The method according to claim 3, characterized in that The second routing key is multiple; determining the target first routing key corresponding to the second routing key specifically includes: For each second routing key among the plurality of second routing keys, determining the first routing key corresponding to the second routing key; wherein the first routing key is represented by a binary number and has only one value of 1; All the first routing keys corresponding to the second routing keys are determined as the target first routing keys.
5. The method according to claim 1, characterized in that: Before obtaining the routing status of the target user terminal, the method further includes: In response to determining that the target user establishes a connection with the target Websocket node, updating the routing state based on a response to the establishment of the connection and a routing node state of the target Websocket node; In response to determining that the target user is disconnected from the target Websocket node, the routing state is updated based on a response to the disconnection and a routing node state of the target Websocket node.
6. The method according to claim 5, characterized in that The method further includes updating the routing state based on the response to establishing the connection and the routing node state of the target Websocket node, specifically comprising: Obtaining the routing node state and the routing state before updating; wherein the routing state is represented by a binary number, and the routing node state is represented by a binary number and has only one value of 1; An AND operation is performed on the routing node state and the routing state before the update, and the routing state is updated based on the result of the AND operation.
7. The method according to claim 5, characterized in that The method further includes updating the routing state based on the disconnection response and the routing node state of the target Websocket node, specifically comprising: Obtaining the routing node state and the routing state before updating; wherein the routing state is represented by a binary number, and the routing node state is represented by a binary number and has only one value of 1; An XOR operation is performed on the routing node state and the routing state before the update, and the routing state is updated based on the result of the XOR operation.
8. The method according to claim 5, characterized in that After updating the routing state, the method further comprises: In response to determining that all values in the updated routing state are 0, deleting the routing state; The routing status is represented by binary numbers.
9. The method according to claim 1, characterized in that: The routing status is stored via redis.
10. A message push device, characterized in that: include: The acquisition module obtains the routing status of the target user end; A determination module, which determines a target Websocket node having a connection relationship with the target user terminal from a plurality of Websocket nodes based on the routing state; A push module pushes the message to be pushed to the target Websocket node, so that the target Websocket node sends the message to be pushed to the target user terminal; The determination module is specifically used for: Obtain a first routing key of each Websocket node in the plurality of Websocket nodes; wherein the first routing key is represented by a binary number and has only one value of 1; Determine a second position of a second target value having a value of 1 in the first routing key; Obtaining a first position of a first target value having a value of 1 in the routing state; wherein the routing state is represented by a binary number; The target Websocket node is determined based on the first location and the second location.
11. An electronic device, characterized in that: The method comprises a memory, a processor, and a computer program stored in the memory and executable by the processor, wherein the processor implements the method according to any one of claims 1 to 9 when executing the program.
12. A non-transitory computer-readable storage medium, characterized in that: The non-transitory computer-readable storage medium stores computer instructions for causing a computer to execute the method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Method and device for circularly pushing reminding message
CN111917687A
Data set management method, system and device, electronic equipment and storage medium
CN112925788A
Message pushing method, device and system, electronic equipment and storage medium
CN113157466A
Message pushing method and system, computing device and readable storage medium
CN114461419A
Message push method and message service system
WO2022095678A1
