Distributed cache publishing and subscription method and system, and apparatus
ACCESS parses and routes subscription channels through the distributed cache proxy layer to realize publish and subscribe across shard nodes. This solves the problem that the native cluster cannot support cross-node publish and subscribe, avoids 'subscription storms', and automatically reconnects when the cluster changes. Subscribe to ensure that the application is transparent and imperceptible.
Patent Information
- Application Number
- PCT/CN2023/142747
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-12-12
- Filing Date
- 2023-12-28
- Publication Date
- 2024-10-10
AI Technical Summary
Native clusters do not support cross-node publishing and subscription, resulting in 'subscription storm' problems, affecting network and cluster performance, and causing subscription connections to be disconnected when nodes are switched or down, requiring manual re-subscription on the application side.
Through the distributed cache proxy layer ACCESS, receive publisher messages, disassemble the ACCSEE protocol, save to specific Redis shards, and automatically notify subscribers to implement cross-shard node publishing and subscription, cache subscription information, and periodically rehash and Reconnect.
It solves the pain points of cross-shard node publishing and subscription scenarios, avoids 'subscription storms', ensures that applications are transparent and unaware of cluster change operations, and improves development efficiency and performance.
Smart Images

Figure CN2023142747_10102024_PF_FP_ABST
Abstract
Description
A distributed cache publish-subscribe method, system, and device Technical Field
[0001] The present invention relates to the technical field of middleware, and in particular to a distributed cache publish-subscribe method, system and device. Background Art
[0002] ACCESS is a distributed cache access proxy middleware developed by China Telecom Tianyi Cloud. The middleware receives data processing requests from clients and then forwards them to the underlying cache storage shard nodes, such as the Redis backend storage in the cache.
[0003] Distributed cache is a NoSQL memory database software compatible with the Redis protocol. It can accept data query and storage requests from other client applications, and transmit them to the backend cache storage shard node through the ACCESS proxy middleware consistent hash sharding and respond.
[0004] Publish / subscribe (pub / sub) is a messaging communication model where a sender (pub) sends messages and subscribers (sub) receive them. Subscribers (e.g., clients) express their interest in receiving an event or a class of events through event subscriptions. Publishers (e.g., servers) can keep subscribers informed of events of interest.
[0005] To address the issue of native clusters not supporting cross-node publishing and subscription, that is, when subscribed channels fall on different shards, native clusters currently have no effective means to support cross-shard publishing and subscription. Furthermore, due to design flaws in native clusters based on publish-subscribe, the so-called "subscription storm" problem may occur when messages are published. When a node receives a PUBLISH command, it broadcasts the message to all nodes in the entire cluster. All nodes subscribed to the corresponding channel or mode will receive the message. The existing publish-subscribe model of native clusters will have a significant impact on network and cluster performance. In addition, when the backend cluster undergoes changes such as node switching, downtime and restart, the application side can sense the disconnection of the subscription connection and manually re-subscribe.
[0006] This application proposes a distributed cache publish-subscribe method, system and device.
[0007] Summary of the Invention
[0008] To achieve the above objectives, the present invention provides a distributed cache publish-subscribe method, system, and apparatus to solve the problem that native clusters do not support cross-node publish and subscribe.
[0009] In order to solve the above technical problems, the present invention provides a distributed cache publish-subscribe method, the method comprising:
[0010] Receive specific messages sent by publishers;
[0011] Perform ACCSEE protocol disassembly on the message sent by the publisher;
[0012] Disassemble the data according to the ACCSEE protocol and save the message to a specific Redis shard;
[0013] When a Redis shard receives a message, it automatically notifies the subscriber through ACCSEE.
[0014] Preferably, after the redis shard receives a message, before the redis shard automatically notifies the subscriber via ACCSEE, the user needs to subscribe to the channel.
[0015] Preferably, when a user subscribes to a channel:
[0016] The user sends a channel subscription request, which is sent to the distributed cache proxy layer, and the user's consistent hash is routed to the corresponding Redis shard;
[0017] When a user sends a multi-channel subscription request, the multi-channel subscription SUBSCRIBE consistent hash is used to route it to the corresponding Redis shard. The ACCESS proxy layer automatically simulates multiple subscription clients to subscribe to the corresponding data shard node on the backend.
[0018] ACCESS caches all channel subscription information.
[0019] Preferably, before disassembling the data according to the ACCSEE protocol and saving the message to a specific Redis shard, the method further includes:
[0020] Node selection is done through key-based hash sharding;
[0021] Set up a Redis cluster and configure node and shard mapping; each shard is independent of each other, and each shard node stores its own subscription channel.
[0022] Preferably, after ACCESS caches all channel subscription information, the method further includes:
[0023] Periodically re-consistently hash the cached subscription channel information and simulate different subscription systems to re-subscribe to the data shard nodes.
[0024] Preferably, after ACCESS caches all channel subscription information, the method also includes, when the distributed cache cluster undergoes change operations such as master-slave switching, node expansion, node downtime and restart, when Access detects that the shard node connection that caused the change operation is disconnected, it automatically re-consistently hashes the cached subscription channel information and simulates different subscribers to reconnect and subscribe to the data shard node.
[0025] Preferably, before performing ACCSEE protocol decomposition on the message sent by the publisher, the method further comprises: using Java to write and run the distributed cache proxy layer service ACCSEE.
[0026] Further preferably, the present application also includes a distributed cache publish-subscribe system, including:
[0027] Message receiving module: used to receive specific messages sent by publishers;
[0028] Protocol disassembly module: used to perform ACCSEE protocol disassembly on the message sent by the publisher;
[0029] Message cache module: used to disassemble data according to the ACCSEE protocol and save messages to specific Redis shards;
[0030] Message sending module: When a redis shard receives a message, the redis shard automatically notifies the subscriber through ACCSEE.
[0031] Further preferably, the present application further includes a server, characterized in that the server includes:
[0032] one or more processors;
[0033] a storage device for storing one or more programs,
[0034] When the one or more programs are executed by the one or more processors, the one or more processors implement the distributed cache publish-subscribe method according to any one of claims 1 to 7.
[0035] Further preferably, the present application also includes a computer storage medium, characterized in that a computer program is stored therein, and when the program is executed, the distributed cache publish-subscribe method as described in any one of claims 1-7 is implemented.
[0036] Compared with the prior art, the distributed cache publishing and subscription method, system and device of the embodiment of the present invention have the following beneficial effects: this method optimizes the self-developed distributed cache ACCESS proxy layer, and for distributed cache publishing and subscription application scenarios, the multi-channel subscription SUBSCRIBE of the application is consistently hashed and routed to the corresponding shard through the ACCESS proxy layer, thus solving the problem that the native cluster cannot support publishing and subscription across shard nodes, and directly routes the PUBLISH message published by the application's subscription channel to the real channel subscription shard node without broadcasting the message to all shard nodes in the cluster, thus solving the pain point problem of decentralized publishing scenarios of the native cluster. In addition, the method automatically reconnects for operations such as master-slave switching and expansion of the cluster backend, without affecting the loss of subscription channels on the application side, thus solving some scenarios that the native cluster cannot cover in terms of subscription channel stability. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0038] FIG1 is a structural diagram of a distributed cache publish-subscribe method provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0039] The following is a clear and complete description of the technical solutions in the embodiments of the present invention. Obviously, the embodiments described are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making any creative efforts are within the scope of protection of the present invention.
[0040] In the description of this application, it should be understood that the terms "center", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside", etc., indicating the orientation or position relationship, are based on the orientation or position relationship shown in the accompanying drawings, and are only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on this application.
[0041] The terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of the technical features being referred to. Thus, a feature specified as "first" or "second" may explicitly or implicitly include one or more of such features. Throughout this application, unless otherwise specified, "plurality" means two or more.
[0042] In the description of this application, it should be noted that, unless otherwise expressly specified or limited, the terms "mounted," "connected," and "connected" should be understood in a broad sense. For example, they can refer to fixed connections, detachable connections, or integral connections; mechanical connections or electrical connections; direct connections or indirect connections through an intermediate medium; and internal connections between two components. Those skilled in the art will understand the specific meanings of the above terms in this application based on the specific circumstances.
[0043] 1 , a method, system, and apparatus for distributed cache publishing and subscription according to a preferred embodiment of the present invention are provided to solve the problem that native clusters do not support cross-node publishing and subscription.
[0044] Existing native clusters lack effective support for cross-shard publish-subscribe when subscribed channels reside on different shards. Furthermore, due to design flaws in native clusters' publish-subscribe mechanism, a so-called "subscription storm" can occur when publishing messages. When a node receives a PUBLISH command, it broadcasts the message to all nodes in the cluster. All nodes subscribed to the corresponding channel or mode receive the message. This existing publish-subscribe model significantly impacts network and cluster performance. Furthermore, when the backend cluster experiences changes such as node switching or downtime restarts, applications can detect disconnected subscriptions and require manual re-subscription.
[0045] That is, native clusters have major flaws in the following scenarios:
[0046] Scenario 1: The "subscription storm" problem of the native cluster seriously affects the cluster processing performance.
[0047] Scenario 2: Native clusters lack effective means to support cross-shard nodes, especially in publish-subscribe scenarios.
[0048] Scenario 3: In the event of a native cluster failure, master-slave switchover, or other failure scenarios, the application side needs to republish and resubscribe, making it impossible to achieve transparent and imperceptible publishing and subscription.
[0049] In order to solve the above technical problems, the present invention provides a distributed cache publish-subscribe method, the method comprising:
[0050] Receive specific messages sent by publishers;
[0051] Perform ACCSEE protocol disassembly on the message sent by the publisher;
[0052] Disassemble the data according to the ACCSEE protocol and save the message to a specific Redis shard;
[0053] When a Redis shard receives a message, it automatically notifies the subscriber through ACCSEE.
[0054] Preferably, after the redis shard receives a message, before the redis shard automatically notifies the subscriber via ACCSEE, the user needs to subscribe to the channel.
[0055] Preferably, when a user subscribes to a channel:
[0056] The user sends a channel subscription request, which is sent to the distributed cache proxy layer, and the user's consistent hash is routed to the corresponding Redis shard;
[0057] When a user sends a multi-channel subscription request, the multi-channel subscription SUBSCRIBE consistent hash is used to route it to the corresponding Redis shard. The ACCESS proxy layer automatically simulates multiple subscription clients to subscribe to the corresponding data shard node on the backend.
[0058] ACCESS caches all channel subscription information.
[0059] Preferably, before disassembling the data according to the ACCSEE protocol and saving the message to a specific Redis shard, the method further includes:
[0060] Node selection is done through key-based hash sharding;
[0061] Set up a Redis cluster and configure node and shard mapping; each shard is independent of each other, and each shard node stores its own subscription channel.
[0062] Preferably, after ACCESS caches all channel subscription information, the method further includes:
[0063] Periodically re-consistently hash the cached subscription channel information and simulate different subscription systems to re-subscribe to the data shard nodes.
[0064] Preferably, after ACCESS caches all channel subscription information, the method also includes, when the distributed cache cluster undergoes change operations such as master-slave switching, node expansion, node downtime and restart, when Access detects that the shard node connection that caused the change operation is disconnected, it automatically re-consistently hashes the cached subscription channel information and simulates different subscribers to reconnect and subscribe to the data shard node.
[0065] Preferably, before performing ACCSEE protocol decomposition on the message sent by the publisher, the method further comprises: using Java to write and run the distributed cache proxy layer service ACCSEE.
[0066] In summary, the distributed cache publish-subscribe method provided by the embodiments of the present application is optimized for the above-mentioned scenario, specifically:
[0067] Regarding the "subscription storm" problem of the native cluster in scenario 1: The distributed cache cluster in this patent is different from the decentralized architecture of the native cluster. Each shard is independent of each other, and each shard node stores its own subscription channel. When a message is published, the designated redis shard node automatically notifies the application through Access, without the need to "broadcast" the message to all nodes in the cluster. This avoids the "subscription storm" problem in the native cluster and greatly reduces the cluster network congestion and performance bottlenecks caused by message publishing and subscription.
[0068] Regarding the cross-node subscription problem of the native cluster in scenario 2: the distributed cache proxy layer Access of this patent can intelligently parse the subscription channel protocol of the application, integrate the subscription information of different channels and simulate subscribers to subscribe to the corresponding data shard nodes in the backend, making up for the scenario where the native cluster JedisCluster cannot subscribe across shard nodes. The application can use the cluster in the same way as the stand-alone Redis mode, which greatly improves the application development efficiency.
[0069] Regarding the transparent perception problem of native cluster applications in scenario three: When the native cluster undergoes cluster changes such as master-slave switching and capacity expansion, the application's subscription connection will be directly disconnected. The patented distributed cache Access caches all subscription channel information of the application. When the backend data node goes down or switches or expands, Access detects that the connection of the shard node that generated the change operation is disconnected, and automatically re-consistently hashes the cached subscription channel information and simulates different subscribers to reconnect and subscribe to the data shard node, achieving application transparency and unawareness.
[0070] The above method is described in detail below by way of examples:
[0071] Example 1:
[0072] 1. Use Java to write and run the distributed cache proxy layer service Access.
[0073] 2. When Access receives REDIS publish-subscribe requests, the code location that initiates the response sends request and response events, which are received by the intelligent protocol processing module of the distributed cache proxy layer.
[0074] 3. The Access intelligent protocol processing module automatically parses the client's multi-channel subscription request protocol and routes it to the corresponding Redis shard based on the multi-channel subscription SUBSCRIBE consistent hash. The ACCESS proxy layer automatically simulates multiple subscription clients to subscribe to the corresponding data shard node on the backend (solving the problem that the native cluster cannot support operations across shard nodes).
[0075] 4. When a message is published in the subscribed channel, the corresponding Redis shard node automatically notifies the application through Access without "broadcasting" the message to all nodes in the cluster, avoiding the "subscription storm" problem in the native cluster.
[0076] 5. When the cluster undergoes changes such as master-slave switching, node expansion, node downtime and restart, Access detects that the shard node causing the change is disconnected, automatically re-consistently hashes the cached subscription channel information and simulates different subscribers to reconnect and subscribe to the data shard node, making the application transparent and unaware.
[0077] Furthermore, the present application also includes a distributed cache publish-subscribe system, comprising:
[0078] Message receiving module: used to receive specific messages sent by publishers;
[0079] Protocol disassembly module: used to perform ACCSEE protocol disassembly on the message sent by the publisher;
[0080] Message cache module: used to disassemble data according to the ACCSEE protocol and save messages to specific Redis shards;
[0081] Message sending module: When a redis shard receives a message, the redis shard automatically notifies the subscriber through ACCSEE.
[0082] Furthermore, the present application also includes a server, characterized in that the server includes:
[0083] one or more processors;
[0084] a storage device for storing one or more programs,
[0085] When the one or more programs are executed by the one or more processors, the one or more processors implement the distributed cache publish-subscribe method described in any embodiment.
[0086] The memory, as a computer-readable storage medium, can be used to store software programs, computer executable programs, and modules, such as the program instructions / modules corresponding to the distributed cache publish-subscribe method in the embodiments of the present invention (for example, the message receiving module, protocol disassembly module, message storage module, and message sending module in the distributed cache publish-subscribe system). The processor executes the various functional applications and data processing of the server by running the software programs, instructions, and modules stored in the memory, thereby implementing the aforementioned Redis-based multi-user publish-subscribe method.
[0087] The memory may primarily include a program storage area and a data storage area. The program storage area may store an operating system and at least one application required for a function; the data storage area may store data generated based on the use of the terminal, etc. Furthermore, the memory may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state memory device. In some instances, the memory may further include memory remotely located relative to the processor, and these remote memories may be connected to a server via a network. Examples of the aforementioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0088] The communication device can be used to receive messages from the user terminal and send messages to the user terminal.
[0089] Furthermore, the present application also includes a computer storage medium, characterized in that it stores a computer program, which, when executed, implements the distributed cache publish-subscribe method described in any embodiment.
[0090] In summary, the embodiments of the present invention provide a method, system and device for distributed cache publishing and subscription. Through the optimization of the self-developed distributed cache ACCESS proxy layer, for distributed cache publishing and subscription application scenarios, the ACCESS proxy layer routes the application's multi-channel subscription SUBSCRIBE consistent hash to the corresponding shard, solving the problem that the native cluster cannot support publishing and subscription across shard nodes, and directly routes the PUBLISH message published for the application's subscription channel to the real channel subscription shard node without broadcasting the message to all shard nodes in the cluster, solving the pain point problem of decentralized publishing scenarios in the native cluster. In addition, the cluster automatically reconnects for operations such as master-slave switching and expansion of the cluster backend, without affecting the loss of subscription channels on the application side, solving some scenarios that the native cluster cannot cover in terms of subscription channel stability.
[0091] The above is only an embodiment of the present invention, but it cannot limit the scope of the present invention. Any structural changes made according to the present invention should be deemed to fall within the scope of protection of the present invention and be subject to restrictions as long as they do not lose the essence of the present invention.
[0092] It should be noted that the system provided in the above embodiment is only illustrated by the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the modules or steps in the embodiments of the present invention can be further decomposed or combined. For example, the modules in the above embodiment can be combined into one module, or further divided into multiple sub-modules to complete all or part of the functions described above. The names of the modules and steps involved in the embodiments of the present invention are only for distinguishing the modules or steps and are not to be regarded as improper limitations of the present invention.
[0093] The term "comprise" or any other similar term is intended to cover non-exclusive inclusion such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed or inherent to such process, method, article, or apparatus.
[0094] Thus far, the technical solutions of the present invention have been described in conjunction with the preferred embodiments shown in the accompanying drawings. However, it will be readily understood by those skilled in the art that the scope of protection of the present invention is obviously not limited to these specific embodiments. Without departing from the principles of the present invention, those skilled in the art may make equivalent changes or substitutions to the relevant technical features, and the technical solutions after such changes or substitutions will fall within the scope of protection of the present invention.
[0095] The above description is merely a preferred embodiment of the present invention and is not intended to limit the scope of protection of the present invention.
Claims
1. A distributed cache publish-subscribe method, characterized in that: The method comprises: Receive specific messages sent by publishers; Perform ACCSEE protocol disassembly on the message sent by the publisher; Disassemble the data according to the ACCSEE protocol and save the message to a specific redis shard; When a redis shard receives a message, it automatically notifies the subscriber through ACCSEE.
2. The distributed cache publish-subscribe method according to claim 1, characterized in that: After the redis shard receives a message, the user needs to subscribe to the channel before the redis shard automatically notifies the subscriber through ACCSEE.
3. The distributed cache publish-subscribe method according to claim 2, characterized in that: When a user subscribes to a channel: The user sends a channel subscription request to the distributed cache proxy layer, which routes the user's consistent hash to the corresponding redis shard; When a user sends a multi-channel subscription request, the multi-channel subscription SUBSCRIBE consistent hash is routed to the corresponding redis shard, and the ACCESS proxy layer automatically simulates multiple subscription clients to subscribe to the corresponding data shard node on the backend; ACCESS caches all channel subscription information.
4. The distributed cache publish-subscribe method according to claim 1, characterized in that: Before disassembling the data according to the ACCSEE protocol and saving the message to a specific redis shard, the method further includes: Nodes are selected through key-based hash sharding; Set up a redis cluster and configure node and shard mapping; each shard is independent of each other, and each shard node stores its own subscription channel.
5. The distributed cache publish-subscribe method according to claim 3, characterized in that: After ACCESS caches all channel subscription information, the method further includes: Periodically re-consistently hash the cached subscription channel information and simulate different subscription systems to re-subscribe to the data shard nodes.
6. The distributed cache publish-subscribe method according to claim 5, characterized in that: After ACCESS caches all channel subscription information, the method also includes, when the distributed cache cluster undergoes change operations such as master-slave switching, node expansion, node downtime and restart, when Access detects that the shard node connection that caused the change operation is disconnected, it automatically re-consistently hashes the cached subscription channel information and simulates different subscribers to reconnect and subscribe to the data shard node.
7. The distributed cache publish-subscribe method according to claim 1, characterized in that: Before performing ACCSEE protocol decomposition on the message sent by the publisher, the method further comprises: using Java to write and run the distributed cache proxy layer service ACCSEE.
8. A distributed cache publish-subscribe system, characterized in that: include: Message receiving module: used to receive specific messages sent by publishers; Protocol disassembly module: used to perform ACCSEE protocol disassembly on the message sent by the publisher; Message cache module: used to disassemble data according to the ACCSEE protocol and save messages to specific redis shards; Message sending module: When a redis shard receives a message, the redis shard automatically notifies the subscriber through ACCSEE.
9. A server, characterized in that: The server comprises: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the distributed cache publishing and subscribing method as described in any one of claims 1 to 7.
10. A computer storage medium, characterized in that A computer program is stored, and when the program is executed, the distributed cache publishing and subscribing method as described in any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Fragment processing method and system
CN102377524A
Operation request processing method and device
CN110019049A
REDIS fragmentation method and device, computer equipment and storage medium
CN110347718A
Vehicle communication using publish-subscribe messaging protocol
US20190173951A1
Cited By
Publishing and subscribing method, system and equipment under multiple processors and storage medium
CN119583639A
Message interaction system suitable for contained deployment in regulation and control system
CN120692264A
SSE protocol-based high-concurrency real-time message pushing system and method
CN120785946A
Data management system and method based on time slices
CN121098929A
