A long connection channel-based information pushing method, device and system
Patent Information
- Application Number
- CN202211664032.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-23
- Publication Date
- 2026-11-03
- Estimated Expiration
- 2042-12-23
AI Technical Summary
In existing technologies, long-lived connection channels between clients and servers cannot support horizontal scaling in non-clustered environments, resulting in a limited number of connections and information transmission delays and resource waste in large systems. In clustered environments, clients cannot share long-lived connection channels, leading to uneven information transmission and delays.
By introducing a connection manager cluster into the microservice cluster, clients can establish multiple long-lived connection channels with the microservice cluster. By using load balancing strategies, a target channel can be selected from multiple long-lived connection channels for information push, thereby achieving load balancing and resource sharing.
It enables servers in a microservice cluster to share a long-lived connection channel, avoiding resource waste, balancing the load, reducing information transmission latency, supporting horizontal scaling in a distributed cluster environment, and meeting the connection needs of large systems.
Smart Images

Figure CN116233230B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of computer technology, and in particular relates to an information push method, device and system based on a long connection channel. Background Technology
[0002] Currently, if a client needs to obtain server status information in real time, it typically does so using client-side polling. Simply put, client-side polling means that the client periodically requests the server to obtain the latest server status information.
[0003] While client-side polling is relatively easy to implement, it suffers from several drawbacks. Firstly, its real-time performance is low due to time delays. Secondly, it is performance-intensive, as all polling requests are invalid if the server's state remains unchanged. Establishing a persistent connection between the server and client, allowing the server to proactively push updated information to the client, can resolve these issues.
[0004] However, building long-lived connection channels in a non-clustered environment does not support horizontal scaling, and the number of connections is limited, which cannot meet the needs of large-scale systems. In the existing clustered environment, it is also impossible for a single client to correspond to multiple long-lived connection channels at the same time. Therefore, when a single long-lived connection channel has a bottleneck, it is easy to cause information transmission delays. Furthermore, in a distributed environment, there are also problems such as servers not being able to share long-lived connection channels, and uneven information transmission frequency among different long-lived connection channels. Summary of the Invention
[0005] This application provides an information push method, apparatus, and system based on a long connection channel, which can solve the above-mentioned technical problems.
[0006] In a first aspect, embodiments of this application provide an information push method based on a long connection channel, comprising: obtaining target information to be pushed to a target client; wherein the target information includes identity information corresponding to the target client; determining the connection manager corresponding to the target client based on the identity information, and determining multiple long connection channels established by the target client through the connection manager; determining a target long connection channel from the multiple established long connection channels according to a load balancing strategy; and pushing the target information to the target client based on the target long connection channel.
[0007] Furthermore, the target client corresponds to multiple connection managers; the target long connection channel is determined from the multiple established long connection channels according to the load balancing strategy, including: determining the target connection manager from the multiple connection managers according to the first load balancing strategy, and determining the target long connection channel from the long connection channels corresponding to the target client under the target connection manager.
[0008] Further, determining the target long connection channel from the long connection channels corresponding to the target client under the target connection manager includes: if the target client under the target connection manager has one long connection channel, then the long connection channel corresponding to the target client under the target connection manager is determined as the target long connection channel; if the target client under the target connection manager has multiple long connection channels, then the target long connection channel is determined from the multiple long connection channels corresponding to the target client under the target connection manager according to the second load balancing strategy.
[0009] Furthermore, the target client corresponds to a connection manager; the target long connection channel is determined from multiple established long connection channels according to the load balancing strategy, including: determining the connection manager corresponding to the target client as the target connection manager; and determining the target long connection channel from multiple long connection channels corresponding to the target client under the target connection manager according to the second load balancing strategy.
[0010] Furthermore, the target information also includes the target client type. Before determining the target long connection channel from the multiple established long connection channels according to the load balancing strategy, the process includes: determining a long connection channel with a matching type from the multiple established long connection channels according to the target client type; wherein, the same identity information corresponds to multiple client types, and the client type is bound to at least one established long connection channel; determining the target long connection channel from the multiple established long connection channels according to the load balancing strategy includes: determining the target long connection channel from the long connection channels with a matching type according to the load balancing strategy.
[0011] Furthermore, the target information also includes target tags. Before determining the target long connection channel from the multiple established long connection channels according to the load balancing strategy, the process includes: determining the long connection channel matching the tag from the multiple established long connection channels according to the target client tag; wherein, the same identity information corresponds to multiple tags, and each tag and the client type corresponding to the tag are bound to at least one established long connection channel; determining the target long connection channel from the multiple established long connection channels according to the load balancing strategy includes: determining the target long connection channel from the long connection channels matching the tag according to the load balancing strategy.
[0012] Furthermore, based on the identity information, the connection manager corresponding to the target client is determined, and the multiple long connection channels established by the target client through the connection manager are identified. This includes: retrieving long connection channel data corresponding to the identity information from the mapping table in the cache database; wherein each long connection channel data includes at least the connection manager address, and the long connection channel data consists of the connection managers registered in the mapping table; based on the connection manager address in the long connection channel data corresponding to the identity information, the connection manager corresponding to the target client is determined, and the multiple long connection channels established by the target client through the connection manager are identified.
[0013] Secondly, embodiments of this application provide an information push device based on a long connection channel, comprising: an acquisition unit, configured to acquire target information to be pushed to a target client; wherein the target information includes identity information corresponding to the target client; a first determination unit, configured to determine the connection manager corresponding to the target client based on the identity information, and determine multiple long connection channels established by the target client through the connection manager; a second determination unit, configured to determine a target long connection channel from the multiple established long connection channels according to a load balancing strategy; and a push unit, configured to push the target information to the target client based on the target long connection channel.
[0014] Furthermore, the second determining unit includes: a third determining unit, configured to determine a target connection manager from multiple connection managers according to the first load balancing strategy, and to determine a target long connection channel from the long connection channels corresponding to the target client under the target connection manager.
[0015] Furthermore, the third determining unit is specifically used for: if the target client under the target connection manager corresponds to one long connection channel, then determining one long connection channel corresponding to the target client under the target connection manager as the target long connection channel; if the target client under the target connection manager corresponds to multiple long connection channels, then determining the target long connection channel from the multiple long connection channels corresponding to the target client under the target connection manager according to the second load balancing strategy.
[0016] Furthermore, the second determining unit includes: a fourth determining unit, used to determine that the connection manager corresponding to the target client is the target connection manager; and a fifth determining unit, used to determine the target long connection channel from multiple long connection channels corresponding to the target client under the target connection manager according to the second load balancing strategy.
[0017] Furthermore, the device further includes: a type matching unit, configured to determine a type-matching long connection channel from multiple established long connection channels based on the target client type; wherein the same identity information corresponds to multiple client types, and the client type is bound to at least one established long connection channel; and a second determining unit, specifically configured to: determine the target long connection channel from the type-matching long connection channels according to a load balancing strategy.
[0018] Furthermore, the device further includes: a tag matching unit, used to determine a tag-matching long connection channel from multiple established long connection channels based on a target client tag; wherein, the same identity information corresponds to multiple tags, and each tag and the client type corresponding to the tag are bound to at least one established long connection channel; and a second determining unit, specifically used to determine a target long connection channel from the tag-matching long connection channels according to a load balancing strategy.
[0019] Further, the first determining unit is specifically used to: obtain long connection channel data corresponding to the identity information from the mapping table in the cache database; wherein, each long connection channel data includes at least the address of the connection manager, and the long connection channel data is the data registered by each connection manager to the mapping table; determine the connection manager corresponding to the target client based on the connection manager address in the long connection channel data corresponding to the identity information, and determine the multiple long connection channels that the target client has established through the connection manager.
[0020] Thirdly, this application provides an information push system based on a long connection channel, including: a microservice cluster, a connection manager cluster, and a client. The microservice cluster includes several servers, and the connection manager cluster includes several connection managers.
[0021] Each client is used to establish multiple long-lived connection channels with the server through the connection manager;
[0022] The server is used to execute information push methods based on long connections, as described in the first aspect.
[0023] Fourthly, embodiments of this application provide a server, including a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the method described in the first aspect above.
[0024] Fifthly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the method described in the first aspect above.
[0025] In this embodiment, the information push method based on long connection channels is applied to servers in a microservice cluster. Specifically, the server first obtains the target information to be pushed to the target client. The target information includes the identity information corresponding to the target client. Since a client can establish multiple long connection channels with the microservice cluster, and different long connection channels can be maintained by one or more connection managers, after obtaining the identity information corresponding to the target client, the server needs to determine the connection manager corresponding to the target client based on the identity information, and determine the multiple long connection channels that the target client has established through the corresponding connection manager. Then, according to the load balancing strategy, the target long connection channel is determined from the multiple established long connection channels, and the target information is pushed to the target client based on the target long connection channel. The above method not only realizes the sharing of long connection channels among servers in the microservice cluster, avoiding resource waste, but also balances the load, avoiding uneven resource allocation. Furthermore, since a client can establish multiple long connection channels with the microservice cluster, it can also reduce the probability of information transmission delay, and support horizontal scaling in a distributed cluster environment, meeting the connection needs of large systems and solving performance bottlenecks. Attached Figure Description
[0026] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0027] Figure 1 This is a schematic diagram of the architecture of the information push system based on a long connection channel provided in the first embodiment of this application;
[0028] Figure 2 This is a schematic flowchart of the information push method based on a long connection channel provided in the second embodiment of this application;
[0029] Figure 3 This is a schematic flowchart of S102 in the information push method based on a long connection channel provided in the second embodiment of this application;
[0030] Figure 4 This is a schematic diagram of the architecture for maintaining the mapping table provided in the embodiments of this application;
[0031] Figure 5 This is a schematic diagram of the connection relationships within the mapping table provided in the embodiments of this application;
[0032] Figure 6 This is another schematic flowchart of the information push method based on a long connection channel provided in the second embodiment of this application;
[0033] Figure 7 This is another schematic flowchart of the information push method based on a long connection channel provided in the second embodiment of this application;
[0034] Figure 8 This is a schematic diagram of an information push device based on a long connection channel provided in the third embodiment of this application;
[0035] Figure 9 This is a schematic diagram of the server provided in the fourth embodiment of this application. Detailed Implementation
[0036] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application may also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods have been omitted so as not to obscure the description of this application with unnecessary detail.
[0037] It should be understood that, when used in this application specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or a collection thereof.
[0038] It should also be understood that the term “and / or” as used in this application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0039] As used in this application specification and the appended claims, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection." Similarly, the phrase "if determined" or "if detected [the described condition or event]" may be interpreted, depending on the context, as meaning "once determined," "in response to determination," "once detected [the described condition or event]," or "in response to detection [the described condition or event]."
[0040] Furthermore, in the description of this application and the appended claims, the terms "first," "second," "third," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0041] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0042] Please see Figure 1 , Figure 1 This is a schematic diagram of the architecture of an information push system based on a long connection channel provided in the first embodiment of this application, including: a microservice cluster 101, a connection manager cluster 102, and a client 103. The microservice cluster 101 includes a plurality of servers 1011, and the connection manager cluster 102 includes a plurality of connection managers 1021.
[0043] Each client 103 is used to establish multiple long-lived connection channels with the server 1011 through the connection manager 1021;
[0044] In this embodiment, client 103 refers to the hardware device relative to server 1011.
[0045] Specifically, client 103 can refer to an application client or an intelligent robot.
[0046] Applications can be categorized into mobile applications, web applications, tablet applications, etc. Similarly, application clients can be classified by type into mobile clients, web clients, and tablet clients, etc.
[0047] It should be noted that microservice architecture is a distributed architecture, but the reverse is not necessarily true. In this embodiment, server 1011 can form a server cluster, and multiple server clusters can work together to implement microservice architecture.
[0048] Alternatively, server 1011 can be directly interpreted as a server cluster.
[0049] In this embodiment, the connection manager 1021 refers to the device that maintains the long connection channel between the server 1011 and the client 103. Several connection managers 1021 constitute a connection manager cluster 102, which supports horizontal scaling and can meet the needs of large systems.
[0050] To understand it further, Connection Manager 1021 refers to a device running a Connection Manager instance, which maintains a long-lived connection channel.
[0051] Please see Figure 2 , Figure 2 This is a schematic flowchart of the information push method based on a long-connection channel provided in the second embodiment of this application. In this embodiment, the executing entity of the information push method based on a long-connection channel is a server in a microservice cluster, or more specifically, a processor or microprocessor within the server. The following explanation uses a server as the executing entity for the information push method based on a long-connection channel in this embodiment. Figure 2 The information push method based on long connection channels shown may include:
[0052] S101: Obtain the target information to be pushed to the target client; wherein, the target information includes the identity information corresponding to the target client.
[0053] The server obtains the target information to be pushed to the target client.
[0054] Here, "server" refers to the server in the microservice cluster of the aforementioned system architecture. The concept and understanding of it in this embodiment will not be repeated here.
[0055] In this embodiment, the target client refers to the client that receives the target information. The client is consistent with the above understanding, which can refer to an application client or an intelligent robot.
[0056] In addition to the information to be pushed, the target information must also include the identity information of the target client.
[0057] In an optional implementation, the identity information corresponding to the target client refers to user identity information (represented as userId). The same user identity information can be used on different types of clients. For example, the same user identity information can be used on mobile clients, web clients, and tablet clients. Therefore, in this embodiment, the target client can refer to all types of clients corresponding to the same user identity information, or it can refer to a certain type of client corresponding to the user identity information.
[0058] If you want to push a target message to a specific type of client, the target information must also specify the target client type. This will be explained in detail in the following implementation.
[0059] In another alternative implementation, the identity information corresponding to the target client refers to the robot's identity information (represented as deviceNo).
[0060] S102: Determine the connection manager corresponding to the target client based on the identity information, and determine the multiple long connection channels that the target client has established through the connection manager.
[0061] In this embodiment, a client can establish multiple long-lived connection channels with the microservice cluster, and different long-lived connection channels can be maintained by one or more connection managers.
[0062] Therefore, after obtaining the identity information of the target client, the server needs to determine the connection manager corresponding to the target client based on the identity information, and determine the multiple long connection channels that the target client has established through the corresponding connection manager.
[0063] In one alternative implementation, to achieve accurate information delivery, each server in the microservice cluster can maintain a mapping table that stores which long-lived connection channels have been established for each client and the correspondence between the long-lived connection channels and the connection manager.
[0064] This approach has two problems. First, each server needs to maintain a mapping table, which becomes very large when there are many long-lived connection channels, occupying storage space. Second, when a long-lived connection channel is updated (interrupted or registered), each server needs to update the mapping table, causing resource consumption.
[0065] In another alternative embodiment, please refer to Figure 3 , Figure 3 This is a schematic flowchart of S102 in the information push method based on a long connection channel provided in the second embodiment of this application. S102 includes:
[0066] S1021: Retrieve the long connection channel data corresponding to the identity information from the mapping table in the cache database; wherein, each long connection channel data includes at least the connection manager address, and the long connection channel data is registered to the mapping table by each connection manager.
[0067] S1022: Based on the connection manager address in the long connection channel data corresponding to the identity information, determine the connection manager corresponding to the target client, and determine the multiple long connection channels that the target client has established through the connection manager.
[0068] In this embodiment, the mapping table is stored in a cache database, which can be a distributed cache database, such as Redis, ZooKeeper, etc.
[0069] If the server wants to obtain the mapping relationship between identity information, connection manager, and long connection channel, it first needs to retrieve the long connection channel data corresponding to the identity information from the mapping table in the cache database.
[0070] Here, the long-lived connection channel data is registered in the mapping table by each connection manager. Specifically, each connection manager has a background daemon thread that periodically writes the data of the long-lived connection channels it maintains to the cache database, including but not limited to creating new long-lived connection channels and terminating long-lived connection channels.
[0071] In an optional embodiment, an expiration time for long-connection channel data can also be set. When the current time reaches the expiration time, the long-connection channel data will be automatically expired and cleared.
[0072] If a connection manager instance terminates abnormally, it means that the corresponding background daemon thread will also terminate, and no more information will be reported. The corresponding long connection channel data will also automatically expire and be cleared in the cache database.
[0073] Please see Figure 4 , Figure 4 This is a schematic diagram of the mapping table maintenance architecture provided in this application embodiment. As can be seen, each connection manager will periodically report the data of the long connection channels it maintains and write them to the distributed cache database Redis.
[0074] The above solution can solve the problem of excessively large mapping tables and avoid resource waste.
[0075] In this embodiment, each long-connection channel in the cache database includes at least the connection manager address.
[0076] After the server retrieves the long connection channel data corresponding to the identity information from the mapping table in the cache database, it can determine the connection manager corresponding to the target client based on the connection manager address in the long connection channel data corresponding to the identity information. Thus, it can also determine the multiple long connection channels that the target client has established through the connection manager.
[0077] Specifically, please see Figure 5 , Figure 5 This is a schematic diagram of the connection relationships within the mapping table provided in an embodiment of this application. As can be seen, Figure 5 The identity information refers to the userId. The userId:123 corresponds to four long-connection channel data entries, each containing the connection manager address. Figure 5 The serverAddress shown consists of an IP address and a port number.
[0078] To understand it further, the connection manager is actually a device running a connection channel instance. The connection manager address here does not refer to the device address, but rather to the process representation of the connection manager instance. The process representation is uniquely identified by the IP address and port.
[0079] As can be seen, the long connection channel data corresponding to userId:123 includes 4 entries. The connection managers corresponding to the target client are connection manager 10.10.1.112:80 and connection manager 10.10.1.113:80. Specifically, two long connection channels are maintained through connection manager 10.10.1.112:80 and two long connection channels are maintained through connection manager 10.10.1.113:80.
[0080] S103: Determine the target long connection channel from the multiple established long connection channels according to the load balancing strategy.
[0081] The server determines the target long-lived connection channel from multiple established long-lived connection channels based on the load balancing strategy.
[0082] Any load balancing strategy can be used here, and no restrictions are imposed.
[0083] In one optional embodiment, the target client corresponds to multiple connection managers, and S103 includes:
[0084] S1031: Determine the target connection manager from multiple connection managers according to the first load balancing strategy, and determine the target long connection channel from the long connection channels corresponding to the target client under the target connection manager.
[0085] The server determines the target connection manager from multiple connection managers based on the first load balancing strategy, and then determines the target long connection channel from the long connection channels corresponding to the target client under the target connection manager.
[0086] In other words, the server first determines the target connection manager from multiple connection managers, and then determines the target long connection channel from the long connection channels corresponding to the target client under the target connection manager.
[0087] Please see Figure 5 The connection managers corresponding to the target clients are connection manager 10.10.1.112:80 and connection manager 10.10.1.113:80. According to the first load balancing rule, one of the two must be selected. For example, if connection manager 10.10.1.112:80 is selected, and connection manager 10.10.1.112:80 maintains two long connection channels, then load balancing needs to be performed again.
[0088] Specifically, if the target client under the target connection manager has multiple long connection channels, the target long connection channel is determined from the multiple long connection channels corresponding to the target client under the target connection manager according to the second load balancing strategy.
[0089] Understandably, if the target client under the target connection manager has a corresponding long connection channel, then the long connection channel corresponding to the target client under the target connection manager can be directly identified as the target long connection channel.
[0090] In an optional implementation, the target client corresponds to a connection manager, and S103 includes:
[0091] S1032: Determine that the connection manager corresponding to the target client is the target connection manager.
[0092] S1033: Determine the target long connection channel from the multiple long connection channels corresponding to the target client under the target connection manager according to the second load balancing strategy.
[0093] In this embodiment, there is only one connection manager corresponding to the target client. Therefore, there is no need to balance the load of the connection manager. The server can directly determine the target long connection channel from the multiple long connection channels corresponding to the target client under the target connection manager according to the second load balancing strategy.
[0094] In this embodiment, not only is a shared long connection channel between servers in the microservice cluster realized to avoid resource waste, but the load can also be balanced to avoid uneven resource allocation. Furthermore, since a client can establish multiple long connection channels with the microservice cluster, the probability of information transmission delay can also be reduced.
[0095] In one optional implementation, please refer to Figure 6 , Figure 6 This is another schematic flowchart of the information push method based on a long connection channel provided in the second embodiment of this application. The target information also includes the target client type. Before determining the target long connection channel from the multiple established long connection channels according to the load balancing strategy in S103, the following steps are included:
[0096] S105: Determine the long connection channel that matches the type from among the multiple established long connection channels based on the target client type; wherein, the same identity information corresponds to multiple client types, and the client type is bound to at least one established long connection channel.
[0097] S103 determines the target long-term connection channel from multiple established long-term connection channels according to the load balancing strategy, including:
[0098] S1034: Determine the target long connection channel from the long connection channels that match the type according to the load balancing strategy.
[0099] The same identity information can be used on mobile clients, web clients, and tablet clients, meaning that the same identity information corresponds to multiple client types (represented as clientType).
[0100] Each client type is bound to at least one established long-lived connection channel. Assuming an identity is universally accepted on both mobile and web clients, then each mobile client must correspond to at least one long-lived connection channel, and each web client must correspond to at least one long-lived connection channel.
[0101] If the target information includes the target client type, then the server needs to determine the long connection channel that matches the target client type from the multiple established long connection channels, and filter out the long connection channels that do not match the target client type.
[0102] Then, the target long connection channel is determined from the long connection channels that match the type according to the load balancing strategy.
[0103] In this embodiment, the server can transmit a target message containing the target client type, thereby achieving precise push to specific types of clients.
[0104] In one optional implementation, please refer to Figure 7 , Figure 7 This is another schematic flowchart of the information push method based on a long connection channel provided in the second embodiment of this application. The target information also includes a target marker. Before determining the target long connection channel from the multiple established long connection channels according to the load balancing strategy in S103, the following steps are included:
[0105] S106: Determine the long connection channel that matches the target client tag from among the multiple established long connection channels; wherein, the same identity information corresponds to multiple tags, and each tag and the client type corresponding to the tag are bound to at least one established long connection channel.
[0106] S103 determines the target long-term connection channel from multiple established long-term connection channels according to the load balancing strategy, including:
[0107] S1035: Determine the target long connection channel from the long connection channels that are matched by the load balancing strategy.
[0108] In this embodiment, the same identity information corresponds to multiple tags, and each tag and the corresponding client type are bound to at least one established long connection channel.
[0109] When a client requests to create a long-lived connection channel, it can carry multiple tags. The tags can be bound to the client type first, and each tag and the corresponding client type are bound to at least one established long-lived connection channel.
[0110] The target information includes target tags, which can also be used to filter long connection channels. Compared with filtering by client type, this method is more flexible. For example, if the client type corresponding to two long connection channels is mobile client, but the tags corresponding to the two long connection channels can be A1 and A2, then by specifying A1 or A2, a specific long connection channel can be selected for message push.
[0111] In this embodiment, the use of tags can be more flexible, which is more conducive to the server achieving accurate push.
[0112] S104: Push target information to the target client based on the target long connection channel.
[0113] The server pushes target information to the target client based on the target long-lived connection channel.
[0114] It should also be noted that, please refer to Figure 1 , Figure 1 Each server 1011 in the microservice cluster uses a packaged JAR file. This means that each server 1011 in the cluster doesn't need to worry about the underlying code implementation logic; as long as the target information and the parameters included in that information are determined, information can be pushed. Furthermore, Figure 1 The document also shows that the registry center, microservice cluster 101, and connection manager cluster 1011 all need to be registered in the registry center, and can be continuously horizontally expanded to meet larger system requirements.
[0115] In an optional implementation, to ensure the security of message push, the client needs to carry the user's identity information and token information when requesting to establish a long connection channel. The token information refers to a token, or a username and password can be used to verify the user's identity.
[0116] If a robot requests to create a long-lived connection channel, it is necessary to determine whether the robot has already been connected to the service platform based on the robot's identity information. If it has not been connected, the connection service will be refused.
[0117] Since the embodiments of this application support the reuse of long connection channels, unified authentication and interception logic can be performed when creating long connection channels, eliminating the need to repeatedly write the same code and avoiding code redundancy.
[0118] In this embodiment, the information push method based on long connection channels is applied to servers in a microservice cluster. Specifically, the server first obtains the target information to be pushed to the target client. The target information includes the identity information corresponding to the target client. Since a client can establish multiple long connection channels with the microservice cluster, and different long connection channels can be maintained by one or more connection managers, after obtaining the identity information corresponding to the target client, the server needs to determine the connection manager corresponding to the target client based on the identity information, and determine the multiple long connection channels that the target client has established through the corresponding connection manager. Then, according to the load balancing strategy, the target long connection channel is determined from the multiple established long connection channels, and the target information is pushed to the target client based on the target long connection channel. The above method not only realizes the sharing of long connection channels among servers in the microservice cluster, avoiding resource waste, but also balances the load, avoiding uneven resource allocation. Furthermore, since a client can establish multiple long connection channels with the microservice cluster, it can also reduce the probability of information transmission delay, and support horizontal scaling in a distributed cluster environment, meeting the connection needs of large systems and solving performance bottlenecks.
[0119] The following section provides a further explanation of the information push system based on long-connection channels.
[0120] Please see Figure 1 The system includes a microservice cluster 101, a connection manager cluster 102, and a client 103. The microservice cluster 101 includes several servers 1011, and the connection manager cluster 102 includes several connection managers 1021.
[0121] Each client 103 is used to establish multiple long-lived connection channels with the server 1011 through the connection manager 1021;
[0122] Server 1011 is used to execute the long-connection-based information push method as described in the second embodiment.
[0123] The information push system based on long connection channels and the information push method based on long connection channels provided in this embodiment belong to the same concept. The implementation process is detailed in the method embodiment and will not be repeated here.
[0124] Please see Figure 8 , Figure 8 This is a schematic diagram of an information push device based on a long-connection channel provided in the third embodiment of this application. The included units are used for execution... Figure 2 The steps in the corresponding embodiments. Please refer to the details. Figure 2 The relevant descriptions in the corresponding embodiments are shown below. For ease of explanation, only the parts relevant to this embodiment are shown. See also... Figure 8The information push device 8 based on a long connection channel includes:
[0125] The acquisition unit 81 is used to acquire target information to be pushed to the target client; wherein, the target information includes the identity information corresponding to the target client;
[0126] The first determining unit 82 is used to determine the connection manager corresponding to the target client based on the identity information, and to determine the multiple long connection channels that the target client has established through the connection manager;
[0127] The second determining unit 83 is used to determine the target long connection channel from the multiple established long connection channels according to the load balancing strategy.
[0128] Push unit 84 is used to push target information to the target client based on the target long connection channel.
[0129] Furthermore, the second determining unit 83 includes:
[0130] The third determining unit is used to determine the target connection manager from multiple connection managers according to the first load balancing strategy, and to determine the target long connection channel from the long connection channels corresponding to the target client under the target connection manager.
[0131] Furthermore, the third determining unit is specifically used for: if the target client under the target connection manager corresponds to one long connection channel, then determining one long connection channel corresponding to the target client under the target connection manager as the target long connection channel; if the target client under the target connection manager corresponds to multiple long connection channels, then determining the target long connection channel from the multiple long connection channels corresponding to the target client under the target connection manager according to the second load balancing strategy.
[0132] Furthermore, the second determining unit 83 includes:
[0133] The fourth determining unit is used to determine that the connection manager corresponding to the target client is the target connection manager;
[0134] The fifth determining unit is used to determine the target long connection channel from multiple long connection channels corresponding to the target client under the target connection manager according to the second load balancing strategy.
[0135] Furthermore, the device 8 also includes:
[0136] The type matching unit is used to determine the type-matching long connection channel from multiple established long connection channels based on the target client type; wherein, the same identity information corresponds to multiple client types, and the client type is bound to at least one established long connection channel;
[0137] The second determining unit 83 is specifically used for: determining the target long connection channel from the long connection channels that match the type according to the load balancing strategy.
[0138] Furthermore, the device 8 also includes:
[0139] The tag matching unit is used to determine the tag-matching long connection channel from multiple established long connection channels based on the target client tag; wherein, the same identity information corresponds to multiple tags, and each tag and the client type corresponding to the tag are bound to at least one established long connection channel;
[0140] The second determining unit 83 is specifically used to: determine the target long connection channel from the long connection channels that are matched by the load balancing strategy.
[0141] Further, the first determining unit 82 is specifically used to: obtain long connection channel data corresponding to the identity information from the mapping table in the cache database; wherein, each long connection channel data includes at least the address of the connection manager, and the long connection channel data is registered to the mapping table by each connection manager; determine the connection manager corresponding to the target client based on the connection manager address in the long connection channel data corresponding to the identity information, and determine the multiple long connection channels that the target client has established through the connection manager.
[0142] The information push device and the information push method based on long connection channels provided in this embodiment belong to the same concept. The implementation process is detailed in the method embodiment and will not be repeated here.
[0143] Please see Figure 9 , Figure 9 This is a schematic diagram of the server provided in the fourth embodiment of this application. Figure 9 As shown, the server 9 in this embodiment includes a processor 90, a memory 91, and a computer program 92 stored in the memory 91 and executable on the processor 90, such as an information push program based on a long-connection channel. When the processor 90 executes the computer program 92, it implements the steps in the various information push method embodiments based on long-connection channels described above, for example... Figure 2 Steps S101 to S104 are shown. Alternatively, when the processor 90 executes the computer program 92, it implements the functions of each module / unit in the above-described device embodiments, for example... Figure 8 The functions of the acquisition unit 81 to the push unit 84 are shown.
[0144] For example, the computer program 92 can be divided into one or more modules / units, which are stored in the memory 91 and executed by the processor 90 to complete this application. The one or more modules / units can be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of the computer program 92 in the server 9. For example, the computer program 92 can be divided into an acquisition unit, a first determination unit, a second determination unit, and a push unit, with the specific functions of each unit as follows:
[0145] The acquisition unit is used to acquire target information to be pushed to the target client; wherein, the target information includes the identity information corresponding to the target client;
[0146] The first determining unit is used to determine the connection manager corresponding to the target client based on the identity information, and to determine the multiple long connection channels that the target client has established through the connection manager;
[0147] The second determining unit is used to determine the target long connection channel from the multiple established long connection channels according to the load balancing strategy;
[0148] The push unit is used to push target information to the target client based on the target long connection channel.
[0149] The server 9 may include, but is not limited to, a processor 90 and a memory 91. Those skilled in the art will understand that... Figure 9 This is merely an example of server 9 and does not constitute a limitation on server 9. It may include more or fewer components than shown, or combine certain components, or different components. For example, server 9 may also include input / output devices, network access devices, buses, etc.
[0150] The processor 90 may be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.
[0151] The memory 91 can be an internal storage unit of the server 9, such as a hard drive or memory. The memory 91 can also be an external storage device of the server 9, such as a plug-in hard drive, Smart Media Card (SMC), Secure Digital (SD) card, or Flash Card. Furthermore, the server 9 can include both internal storage units and external storage devices. The memory 91 is used to store the computer program and other programs and data required by the server 9. The memory 91 can also be used to temporarily store data that has been output or will be output.
[0152] It should be noted that the information interaction and execution process between the above-mentioned devices / units are based on the same concept as the method embodiments of this application. For details on their specific functions and technical effects, please refer to the method embodiments section, and they will not be repeated here.
[0153] This application also provides a network device, which includes: at least one processor, a memory, and a computer program stored in the memory and executable on the at least one processor, wherein the processor executes the computer program to implement the steps in any of the above method embodiments.
[0154] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps described in the various method embodiments above.
[0155] This application provides a computer program product that, when run on a mobile terminal, enables the mobile terminal to implement the steps described in the above-described method embodiments.
[0156] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of this application can be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include at least: any entity or device capable of carrying computer program code to a photographing device / terminal device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium. Examples include USB flash drives, portable hard drives, magnetic disks, or optical disks. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electrical carrier signals or telecommunication signals.
[0157] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0158] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0159] In the embodiments provided in this application, it should be understood that the disclosed apparatus / network devices and methods can be implemented in other ways. For example, the apparatus / network device embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0160] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0161] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.
Claims
1. An information push method based on a long-connection channel, characterized in that, The method, applied to servers in a microservice cluster, includes: Multiple long-lived connection channels are established between a client and a microservice cluster, and different long-lived connection channels are maintained by one or more connection managers; Obtain target information to be pushed to the target client; wherein the target information includes the identity information corresponding to the target client; wherein the same identity information corresponds to multiple client types, and the client type is bound to at least one of the established long connection channels; Based on the identity information, determine the connection manager corresponding to the target client, and determine the multiple long connection channels that the target client has established through the connection manager; The target long connection channel is determined from the multiple established long connection channels according to the load balancing strategy; The target information is pushed to the target client based on the target long connection channel.
2. The information push method based on a long connection channel as described in claim 1, characterized in that, The target client corresponds to multiple connection managers; The step of determining the target long-lived connection channel from the established multiple long-lived connection channels according to the load balancing strategy includes: The target connection manager is determined from the plurality of connection managers according to the first load balancing strategy, and the target long connection channel is determined from the long connection channels corresponding to the target client under the target connection manager.
3. The information push method based on a long connection channel as described in claim 2, characterized in that, Determining the target long connection channel from the long connection channels corresponding to the target client under the target connection manager includes: If the target client under the target connection manager corresponds to a long connection channel, then the long connection channel corresponding to the target client under the target connection manager is determined to be the target long connection channel; If the target client under the target connection manager has multiple long connection channels, then the target long connection channel is determined from the multiple long connection channels corresponding to the target client under the target connection manager according to the second load balancing strategy.
4. The information push method based on a long connection channel as described in claim 1, characterized in that, The target client corresponds to a connection manager; The step of determining the target long-lived connection channel from the established multiple long-lived connection channels according to the load balancing strategy includes: The connection manager corresponding to the target client is identified as the target connection manager; The target long connection channel is determined from multiple long connection channels corresponding to the target client under the target connection manager according to the second load balancing strategy.
5. A method for information push based on a long connection channel as described in any one of claims 1 to 4, characterized in that, The target information also includes the target client type. Before determining the target long connection channel from the multiple established long connection channels according to the load balancing strategy, the process includes: Based on the target client type, determine the long connection channel that matches the type from the multiple established long connection channels; The step of determining the target long-lived connection channel from the established multiple long-lived connection channels according to the load balancing strategy includes: The target long connection channel is determined from the long connection channels that match the type according to the load balancing strategy.
6. A method for information push based on a long connection channel as described in any one of claims 1 to 4, characterized in that, The target information also includes a target marker. Before determining the target long connection channel from the multiple established long connection channels according to the load balancing strategy, the process includes: Based on the target client tag, a matching long connection channel is determined from the multiple established long connection channels; wherein, the same identity information corresponds to multiple tags, and each tag and the client type corresponding to the tag are bound to at least one of the established long connection channels; The step of determining the target long-lived connection channel from the established multiple long-lived connection channels according to the load balancing strategy includes: The target long connection channel is determined from the long connection channels that match the tags according to the load balancing strategy.
7. A method for information push based on a long connection channel as described in any one of claims 1 to 4, characterized in that, The step of determining the connection manager corresponding to the target client based on the identity information, and determining the multiple long-term connection channels established by the target client through the connection manager, includes: Retrieve the long connection channel data corresponding to the identity information from the mapping table in the cache database; wherein, each long connection channel data includes at least the connection manager address, and the long connection channel data is the data registered by each connection manager to the mapping table; Based on the connection manager address in the long connection channel data corresponding to the identity information, determine the connection manager corresponding to the target client, and determine the multiple long connection channels that the target client has established through the connection manager.
8. An information push system based on a long-connection channel, characterized in that, include: The system comprises a microservice cluster, a connection manager cluster, and a client, wherein the microservice cluster includes several servers and the connection manager cluster includes several connection managers. Each of the aforementioned clients is used to establish multiple long-lived connection channels with the server through the connection manager; The server is used to execute the information push method based on a long connection channel as described in any one of claims 1 to 7.
9. An information push device based on a long connection channel, characterized in that, The information push device is configured on a server in a microservice cluster, including: The acquisition unit is used to acquire target information to be pushed to the target client; wherein the target information includes the identity information corresponding to the target client; wherein a client establishes multiple long connection channels with the microservice cluster, and different long connection channels are maintained by one or more connection managers; the same identity information corresponds to multiple client types, and the client type is bound to at least one of the established long connection channels; The first determining unit is configured to determine the connection manager corresponding to the target client based on the identity information, and to determine the multiple long connection channels that the target client has established through the connection manager; The second determining unit is used to determine the target long connection channel from the multiple established long connection channels according to the load balancing strategy; The push unit is used to push the target information to the target client based on the target long connection channel.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
System and method based on connection multiplexing and capable of improving server concurrent processing capacity
CN103067359A
Message pushing method and device, computer equipment and storage medium
CN110300050A
