Establishing method of message publishing and subscribing system, computer medium and electronic equipment

By establishing a full connection between publisher and node and subscriber in the message publishing and subscription system, and combining hash values ​​to determine channel and node binding, the problems of high bandwidth cost and poor business continuity in cross-client room clusters are solved, and the problem of high bandwidth cost and poor business continuity in cross-client room clusters is realized Efficient message transmission and dynamic node adjustment.

CN119276930APending Publication Date: 2025-01-07WEBANK (CHINA)
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202411400815.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-09
Publication Date
2025-01-07

AI Technical Summary

Technical Problem

Existing message publishing and subscription systems have high bandwidth transmission costs in cross-computer room cluster deployments and affect business continuity when nodes increase or decrease.

Method used

By establishing a connection between the publisher and the node and the subscriber one by one in the message publishing and subscription system, the subscriber controls the subscription to each node and selects the target node to send messages based on the node load or storage capacity, and determines the channel and the hash value. Node binding enables efficient message push and dynamic node adjustment.

Benefits of technology

It saves network bandwidth consumption between nodes and ensures business continuity. Even if nodes increase or decrease, the system can still forward messages normally without re-establishing the connection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119276930A_ABST
    Figure CN119276930A_ABST
Patent Text Reader

Abstract

The invention discloses an establishment method of a message publishing and subscribing system, a computer medium and electronic equipment. The system comprises at least one publisher, a plurality of nodes and a plurality of subscribers, and the nodes do not communicate with one another; the method comprises the following steps: establishing connection between a publisher and any node; establishing connection between the nodes and subscribers one by one; controlling a subscriber to initiate subscription of the same specified channel to each node; sending a message of a specified channel to the connected node through a publisher in response to an instruction of publishing the message; and when the node receives the message, pushing the message to a subscriber who subscribes to the specified channel. Therefore, the network bandwidth required by communication between the nodes can be saved, and no matter which node the publisher sends the message of the specified channel to, the node can push the message to the subscriber who subscribes the specified channel; meanwhile, when the number of nodes in the system is increased or decreased, other nodes can complete message forwarding, and the continuity of services is not affected.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of message publishing and subscription, and in particular, relates to a method for establishing a message publishing and subscription system, a computer medium and an electronic device. Background Art

[0002] In software architecture, publish and subscribe is a messaging paradigm. In this paradigm, the sender of a message (or publisher) does not send the message directly to a specific receiver (or subscriber). Instead, the publisher sends the message to a specific channel, and then the system forwards the message to all subscribers who have subscribed to the channel.

[0003] In one message publishing and subscription scheme of the related art, after a node receives a message, it needs to broadcast the message to other nodes. However, this scheme will generate a lot of bandwidth transmission costs in cluster deployment across computer rooms. In another message publishing and subscription scheme of the related art, the publishing and subscription channels are routed to a node in the cluster according to fixed rules, so that the publisher and subscriber of the same channel are connected to the same node. However, in this scheme, when adding or removing nodes, the publisher and subscriber also need to re-establish the connection, which affects the continuity of the business.

[0004] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present application, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention

[0005] The purpose of the present invention is to provide a method for establishing a message publishing and subscription system, a computer medium and an electronic device, so as to solve the problems of high message transmission cost and poor business continuity in the related art.

[0006] According to one aspect of an embodiment of the present application, a method for establishing a message publishing and subscription system is provided, the system comprising: at least one publisher, multiple nodes, and multiple subscribers, the nodes do not communicate with each other; the method comprises:

[0007] Establish a connection between the publisher and any node;

[0008] Connect nodes and subscribers one by one;

[0009] Control the subscriber to initiate subscription to the same specified channel to each node;

[0010] In response to an instruction to publish a message, a message of a designated channel is sent to the connected node through the publisher;

[0011] When a node receives a message, it pushes the message to subscribers who have subscribed to the specified channel.

[0012] In some embodiments of the present application, the method provided by the present application further includes: when the system has a newly added node, establishing a connection between the newly added node and the publisher, and establishing a connection between the newly added node and each subscriber.

[0013] In some embodiments of the present application, after establishing a connection between the newly added node and each subscriber, the method provided by the present application further includes: controlling each subscriber to subscribe to all designated channels subscribed by other nodes to the newly added node.

[0014] In some embodiments of the present application, the method provided by the present application further includes: in response to an instruction to delete the node to be deleted, marking the node to be deleted as an offline state.

[0015] In some embodiments of the present application, after the node to be deleted is marked as offline, the node to be deleted is an offline node, and the method provided by the present application also includes: controlling the publisher to stop sending messages to the offline node; and shutting down the connection between each subscriber and the offline node.

[0016] In some embodiments of the present application, before sending the message of the specified channel to the connected node through the publisher, the method provided by the present application also includes: selecting the target node corresponding to the message of the specified channel according to the load or storage capacity of the node.

[0017] In some embodiments of the present application, the method provided by the present application further includes: determining a target node corresponding to each channel according to a first hash value of the channel and a second hash value of the node address.

[0018] In some embodiments of the present application, the target node corresponding to each channel is determined based on the first hash value of the channel and the second hash value of the node address, including: calculating the first hash value of each channel and the second hash value of each node address; obtaining the target channel and target node with a smaller difference between the first hash value and the second hash value; and binding the target channel and the target node.

[0019] According to one aspect of an embodiment of the present application, a computer medium is provided, on which a computer program is stored. When the computer program is executed by a processor, a method for establishing a message publishing and subscribing system provided by any embodiment of the present application is implemented.

[0020] According to one aspect of an embodiment of the present application, an electronic device is provided, including: a processor; a memory for storing executable instructions of the processor; the processor executes the executable instructions to enable the electronic device to implement a method for establishing a message publishing and subscription system provided by any embodiment of the present application.

[0021] In the technical solution of the present application, the system to which the method for establishing a message publishing and subscription system is applicable includes: at least one publisher, multiple nodes and multiple subscribers, and the nodes do not communicate with each other; the method includes: establishing a connection between the publisher and any node; establishing a connection between the node and the subscriber one by one; controlling the subscriber to initiate a subscription to the same designated channel to each node; responding to the instruction of publishing a message, sending the message of the designated channel to the connected node through the publisher; when the node receives the message, the message is pushed to the subscriber who subscribes to the designated channel. In this way, the network bandwidth required for communication between nodes can be saved, and any node and all subscribers have established a connection. No matter which node the publisher sends the message of the designated channel to, the node can push the message to the subscriber who subscribes to the designated channel, without broadcasting the message between nodes and then forwarding it by the set node; in addition, when adding or reducing nodes in the system, there are other nodes that can complete the forwarding of the message, and it will not affect the continuity of the business.

[0022] It should be understood that the above general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] The drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present application, and together with the specification are used to explain the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0024] Figure 1 The schematic diagram of the message publishing and subscription system of the related technology is schematically shown.

[0025] Figure 2 A schematic diagram of a message publishing and subscription system in the related art is schematically shown.

[0026] Figure 3 A schematic diagram of a message publishing and subscription system provided by an embodiment of the present application is schematically shown.

[0027] Figure 4 The flowchart of the method for establishing a message publishing and subscription system provided in one embodiment of the present application is schematically shown.

[0028] Figure 5 A schematic diagram of a message publishing and subscription system provided by an embodiment of the present application is schematically shown.

[0029] Figure 6 A schematic diagram of a message publishing and subscription system provided by an embodiment of the present application is schematically shown.

[0030] Figure 7 A schematic diagram of a message publishing and subscription system provided by an embodiment of the present application is schematically shown.

[0031] Figure 8 The schematic diagram of the framework of an electronic device provided by an embodiment of the present application is schematically shown.

[0032] Fig. 9 The structure block diagram of a computer system for implementing an electronic device according to an embodiment of the present application is schematically shown. DETAILED DESCRIPTION

[0033] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this application will be more comprehensive and complete and fully convey the concept of the example embodiments to those skilled in the art.

[0034] In addition, the features, structures or characteristics described in the present application may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present application. However, those skilled in the art will appreciate that the technical scheme of the present application can be put into practice without one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known methods, devices, realizations or operations are not shown or described in detail to avoid blurring the various aspects of the present application.

[0035] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.

[0036] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.

[0037] like Figure 1As shown in the figure, in a related message publishing and subscription scheme, the publisher sends the message to the specified channel, and the subscriber can subscribe to any number of channels to receive the message. The message is distinguished by channel, and the publisher and subscriber are unaware of each other's existence, so that publishing and subscription are decoupled from each other. The publisher can send the message to any node in the cluster at will without routing, and the node receiving the message can broadcast the message to other nodes, so that the subscribers who subscribe to the message channel on other nodes can receive the message. However, this scheme will generate a lot of bandwidth transmission costs in cluster deployment across computer rooms.

[0038] like Figure 2 As shown, in another related message publishing and subscription scheme, different channels are assigned to different nodes in the cluster. After receiving the message, the node no longer broadcasts the message in the cluster. Subscribers who want to receive messages from the specified channel need to be routed to the corresponding node first. Since the published and subscribed channels are routed to a node in the cluster according to fixed rules, the publisher and subscriber of the same channel are connected to the same node. This scheme does not require broadcasting messages in the cluster. Although it reduces the consumption of network bandwidth, when the cluster needs to increase or decrease nodes, the routing rules change accordingly due to the change in the number of nodes. Therefore, the nodes connected to the same channel before and after expansion and contraction by publishers and subscribers also need to be modified accordingly. That is, in this scheme, the connection needs to be disconnected when the routing rules are modified, which affects the continuity of the business.

[0039] It can be seen that the related technologies have the problems of high message transmission cost or poor business continuity. In order to solve the above problems, Figure 3 FIG. 1 is a schematic diagram of a message publishing and subscription system according to an embodiment of the present application, and FIG. Figure 4 The figure shows a flow chart of a method for establishing a message publishing and subscription system provided by the present application. The system can save the network bandwidth required for communication between nodes, and any node and all subscribers have established connections. No matter which node the publisher sends the message of the specified channel to, the node can push the message to the subscribers who have subscribed to the specified channel, without broadcasting the message between nodes and then forwarding it by the set node; in addition, when adding or reducing nodes in the system, there are other nodes that can complete the forwarding of messages, and it will not affect the continuity of the business.

[0040] See also Figure 3 , the system includes: at least one publisher, multiple nodes and multiple subscribers, and the nodes do not communicate with each other. In this system, a publisher establishes a connection with any node, and each node is connected to each subscriber. For example, the system includes a publisher, three nodes and two subscribers, where publisher A is connected to node 1, nodes 1, 2 and 3 are all connected to subscriber a, and nodes 1, 2 and 3 are all connected to subscriber b. It should be understood that Figure 3 The figure only illustrates the situation where publisher A establishes a connection with node 1, which does not limit publisher A to only connect to one node. Publisher A can also establish connections with nodes 2 and 3. Similarly, in the other figures, unless the nodes connected to the publisher are specifically stated, there is no specific restriction on the nodes connected to the publisher. For the simplicity of the schematic diagram, the connection relationship between the node and the publisher is omitted in some figures.

[0041] See also Figure 4 An embodiment of the present application provides a method for establishing a message publishing and subscription system. The method includes S410 to S450, and the specific steps are as follows.

[0042] S410: Establish a connection between the publisher and any node.

[0043] Specifically, the publisher can also be called the sender, and the publisher refers to the component responsible for publishing messages. The subscriber refers to the component that subscribes to messages of a specific channel and receives notifications when messages of the channel are published. The node is the intermediary responsible for forwarding the publisher's messages to the subscriber. A message refers to an information unit published by the publisher and received by the subscriber. This application does not impose specific restrictions on the type of message. A channel refers to a channel for transmitting messages. Establishing a connection between the publisher and any node allows the publisher to send messages to the node.

[0044] S420, establishing connections between nodes and subscribers one by one.

[0045] Specifically, connections are established between nodes and subscribers one by one to form a fully connected structure of nodes and subscribers. Then, no matter which node the publisher sends the message to, the node receiving the message can notify the subscribers who have subscribed to the channel message.

[0046] S430: Control the subscriber to initiate subscription to the same designated channel to each node.

[0047] Specifically, because nodes and subscribers are fully connected, a subscriber needs to subscribe to a specified channel on each node, otherwise the message of a channel may not be received. Suppose subscriber a subscribes to channel 01 and channel 02 on node 1, and subscriber a subscribes to only channel 01 on node 2. If publisher A sends a message of channel 02 to node 2, subscriber a will not be able to receive the message. When subscriber a subscribes to channel 01 and channel 02 on both node 1 and node 2, subscriber a can receive the message of channel 01 and channel 02 no matter which node publisher A sends the message of channel 01 and channel 02 to.

[0048] S440: In response to the instruction to publish the message, the message of the designated channel is sent to the connected node through the publisher.

[0049] Specifically, the instruction to send a message can be triggered by a user, a scheduled task, or automatically triggered by a task. After receiving the instruction to publish a message, the publisher sends the message of the specified channel to the connected node so that the node receives the new message.

[0050] S450: When the node receives the message, it pushes the message to the subscribers who subscribe to the specified channel.

[0051] Specifically, when a node receives a message, it means that the node is responsible for notifying the subscriber of the message, and thus the node is controlled to push the message to the subscriber who subscribes to the specified channel, so that the subscriber can receive the message.

[0052] In the technical solution of the present application, the system to which the method for establishing a message publishing and subscription system is applicable includes: at least one publisher, multiple nodes and multiple subscribers, and the nodes do not communicate with each other; the method includes: establishing a connection between the publisher and any node; establishing a connection between the node and the subscriber one by one; controlling the subscriber to initiate a subscription to the same designated channel to each node; responding to the instruction of publishing a message, sending the message of the designated channel to the connected node through the publisher; when the node receives the message, the message is pushed to the subscriber who subscribes to the designated channel. In this way, the network bandwidth required for communication between nodes can be saved, and any node and all subscribers have established a connection. No matter which node the publisher sends the message of the designated channel to, the node can push the message to the subscriber who subscribes to the designated channel, without broadcasting the message between nodes and then forwarding it by the set node; in addition, when adding or reducing nodes in the system, there are other nodes that can complete the forwarding of the message, and it will not affect the continuity of the business.

[0053] In some embodiments of the present application, the method provided by the present application further includes: when the system has a newly added node, establishing a connection between the newly added node and the publisher, and establishing a connection between the newly added node and each subscriber.

[0054] Specifically, when a new node is added to the system, a connection is established between the new node and the publisher, and between the new node and each subscriber, so that the publisher can send messages to the new node, and the new node is connected to each subscriber one by one, so that the new node can forward messages to subscribers who have subscribed to the corresponding channel. When the new node is connected to the publisher or subscriber, the connections on other nodes do not need to be disconnected. Even if the publisher does not refresh to the new node in time, the new message sent by the publisher can still be notified to the subscriber through the original node, which will not affect the normal publication of the message. Figure 5As shown, the system includes publisher A, node 1, node 2, node 3, subscriber a and subscriber b, wherein node 1, node 2 and node 3 are all connected to publisher A, and node 1, node 2 and node 3 are all connected to subscriber a and subscriber b. When a new node 4 is added to the system, publisher A can still send messages to node 1, node 2 or node 3 when the new node 4 is connected to the publisher and the new node 4 is connected to all subscribers.

[0055] In some embodiments of the present application, after establishing a connection between the newly added node and each subscriber, the method provided by the present application further includes: controlling each subscriber to subscribe to all designated channels subscribed by other nodes to the newly added node.

[0056] Specifically, control each subscriber to subscribe to all designated channels that have been subscribed to other nodes to the newly added node, ensure that each subscriber subscribes to the same channels in all nodes, and avoid being unable to receive messages notified by some nodes. For example, subscribers A and B both subscribe to the designated channels that have been subscribed to nodes 1, 2, and 3 to the newly added node 4.

[0057] In some embodiments of the present application, the method provided by the present application further includes: in response to an instruction to delete the node to be deleted, marking the node to be deleted as an offline state.

[0058] Specifically, the instruction to delete the node to be deleted can be triggered by the user selecting the node to be deleted, or it can be automatically triggered by the system according to the message transmission process. When the node is offline, it means that the node is no longer responsible for message transmission. The node to be deleted is marked as offline, and the cluster can be scaled down to optimize the cluster's message transmission process. Figure 6 As shown, the system includes publisher A, node 1, node 2, node 3, subscriber a and subscriber b, wherein node 1, node 2 and node 3 are all connected to publisher A, and node 1, node 2 and node 3 are all connected to subscriber a and subscriber b. After receiving an instruction to delete node 1, in response to the instruction, the node 1 to be deleted is marked as offline.

[0059] In some embodiments of the present application, after the node to be deleted is marked as offline, the node to be deleted is an offline node, and the method provided by the present application also includes: controlling the publisher to stop sending messages to the offline node; and shutting down the connection between each subscriber and the offline node.

[0060] For example, Figure 6As shown, the solid line indicates that the two parties are currently connected, and the dotted line indicates that the two parties are currently disconnected. After the node 1 to be deleted is marked as offline, the node 1 to be deleted is offline node 1, and publisher A is controlled to stop sending messages to offline node 1, and the connection between subscribers a and subscriber b and offline node 1 is cut off, so that publisher A no longer sends messages to offline node 1, and subscribers a or subscribers b will not obtain messages through offline node 1.

[0061] In some embodiments of the present application, before sending the message of the specified channel to the connected node through the publisher, the method provided by the present application also includes: selecting the target node corresponding to the message of the specified channel according to the load or storage capacity of the node.

[0062] Specifically, the load of a node can be understood as the amount of tasks that the node handles. If the load of a node is large, the node may process messages slowly, which may affect the transmission speed of the message. The storage capacity of a node refers to the capacity of the node to temporarily store data. If the storage capacity required to transmit a message exceeds the storage capacity of the node, it will also affect the transmission speed of the message. Therefore, when the publisher sends a message, the target node can be selected according to the load or storage capacity of the node to send the message of the specified channel to the node faster or more stably.

[0063] In some embodiments of the present application, the method provided by the present application further includes: determining a target node corresponding to each channel according to a first hash value of the channel and a second hash value of the node address.

[0064] Specifically, the first hash value of the channel can be the hash value of the channel address, and the second hash value of the node address can be the hash value of the node address, where the first and second are only for distinguishing specific hash values. This embodiment can adopt an algorithm similar to consistent hashing to implement node selection. Consistent hashing is an algorithm that can ensure that when machines are added or reduced, data migration between nodes is limited to two nodes and will not cause global network problems. According to the first hash value and the second hash value, the target node corresponding to each channel can be determined to avoid the problem of large amounts of data migration caused by dynamic changes in the number of nodes, which leads to a sharp increase in network communication pressure.

[0065] In some embodiments of the present application, the target node corresponding to each channel is determined based on the first hash value of the channel and the second hash value of the node address, including: calculating the first hash value of each channel and the second hash value of each node address; obtaining the target channel and target node with a smaller difference between the first hash value and the second hash value; and binding the target channel and the target node.

[0066] Specifically, first calculate the first hash value of each channel and the second hash value of each node address, and compare the first hash value and the second hash value in pairs. For example, the first hash value of channel 01 is 5, the first hash value of channel 02 is 10, the second hash value of node 1 is 11, and the second hash value of node 2 is 6. The channels and nodes with closer first and second hash values ​​are channel 01 and node 2, channel 02 and node 1, respectively. Therefore, channel 01 and node 2 are bound, and channel 02 and node 1 are bound. Then, the message of channel 01 published by the publisher is notified to each subscriber through node 2, and the message of channel 02 published by the publisher is notified to each subscriber through node 1.

[0067] In another embodiment, Figure 7 As shown, the system includes multiple publishers, multiple nodes and multiple subscribers, and the nodes do not communicate with each other. Each publisher establishes a connection with at least one node, and each node is connected to each subscriber. For example, the system includes two publishers, three nodes and two subscribers, wherein publisher A is connected to node 1, publisher B is connected to node 2 and node 3, node 1, node 2 and node 3 are all connected to subscriber a, and node 1, node 2 and node 3 are all connected to subscriber b. In this way, publisher A can notify subscriber a and subscriber b of the message through node 1. Publisher B can notify subscriber a and subscriber b of the message through node 2, and can also notify subscriber a and subscriber b of the message through node 3.

[0068] The electronic equipment of this application is introduced below, such as Figure 8 As shown, the present application provides an electronic device 800, which includes: a processor 810 and a memory 820, the memory 820 is used to store executable instructions of the processor; the processor 810 executes the executable instructions to enable the electronic device to implement the method for establishing a message publishing and subscription system provided by any embodiment of the present application.

[0069] Specifically, the method for establishing the message publishing and subscription system provided by the present application is stored in the memory 820 of the electronic device, and the method for establishing the message publishing and subscription system is executed by the processor 810 to save the network bandwidth required for communication between nodes. Moreover, any node and all subscribers have established a connection. No matter which node the publisher sends the message of the specified channel to, the node can push the message to the subscriber who has subscribed to the specified channel, without broadcasting the message between nodes and then forwarding it by the set node. In addition, when nodes are added or reduced in the system, there are other nodes that can complete the forwarding of messages, and it will not affect the continuity of the business.

[0070] It should be known that the specific implementation content of the electronic device in the present application has been explained in detail in the corresponding method embodiment and will not be repeated here.

[0071] Fig. 9 The structure block diagram of a computer system for implementing an electronic device according to an embodiment of the present application is schematically shown.

[0072] It should be noted that Fig. 9 The computer system 900 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0073] like Fig. 9 As shown, the computer system 900 includes a processor 901, which can be a CPU (Central Processing Unit) or an MCU (Microcontroller Unit). The processor 901 can perform various appropriate actions and processes according to the program stored in the read-only memory 902 (Read-Only Memory, ROM) or the program loaded from the storage part 908 to the random access memory 903 (Random Access Memory, RAM). In the random access memory 903, various programs and data required for system operation are also stored. The processor 901, the read-only memory 902 and the random access memory 903 are connected to each other through a bus 904. The input / output interface 905 (Input / Output interface, i.e., I / O interface) is also connected to the bus 904.

[0074] The following components are connected to the input / output interface 905: an input section 906 including a keyboard, a mouse, etc.; an output section 907 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker; a storage section 908 including a hard disk, etc.; and a communication section 909 including a network interface card such as a LAN card, a modem, etc. The communication section 909 performs communication processing via a network such as the Internet. A drive 910 is also connected to the input / output interface 905 as needed. A removable medium 911, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 910 as needed so that a computer program read therefrom is installed into the storage section 908 as needed.

[0075] In particular, according to an embodiment of the present application, the process described in each method flow chart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer readable medium, and the computer program contains a program code for executing the method shown in the flow chart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication part 909, and / or installed from a removable medium 911. When the computer program is executed by the processor 901, various functions defined in the system of the present application are executed.

[0076] It should be noted that the computer-readable medium shown in the embodiment of the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by an instruction execution system, device or device or used in combination with it. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a computer-readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer readable signal media may also be any computer readable medium other than computer readable storage media, which may send, propagate, or transmit programs for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.

[0077] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the above-mentioned module, program segment or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0078] It should be noted that, although several modules or units of the equipment for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into being embodied by multiple modules or units.

[0079] Through the description of the above implementation methods, it is easy for those skilled in the art to understand that the example implementation methods described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation method of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a touch terminal, or a network device, etc.) to execute the implementation method according to the present application.

[0080] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary technical means in the art that are not disclosed in the present application.

[0081] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

Claims

1. A method for establishing a message publishing and subscription system, characterized in that: The system comprises: at least one publisher, multiple nodes and multiple subscribers, wherein the nodes do not communicate with each other; the method comprises: Establishing a connection between the publisher and any one of the nodes; Establish connections between the nodes and the subscribers one by one; Controlling the subscriber to initiate subscription to the same designated channel to each of the nodes; In response to an instruction to publish a message, sending the message of the designated channel to the connected node through the publisher; When the node receives the message, it pushes the message to the subscriber who subscribes to the designated channel.

2. The method for establishing a message publishing and subscription system according to claim 1, characterized in that: The method further comprises: When the system has a newly added node, the newly added node is connected to the publisher, and the newly added node is connected to each of the subscribers.

3. The method for establishing a message publishing and subscription system according to claim 2, characterized in that: After establishing a connection between the newly added node and each of the subscribers, the method further includes: Control each of the subscribers to subscribe to the newly added node for all designated channels that have been subscribed to other nodes.

4. The method for establishing a message publishing and subscription system according to claim 1, characterized in that: The method further comprises: In response to an instruction to delete a node to be deleted, the node to be deleted is marked as being in an offline state.

5. The method for establishing a message publishing and subscription system as claimed in claim 4, characterized in that: After marking the node to be deleted as being in an offline state, the node to be deleted is an offline node, and the method further includes: Control the publisher to stop sending messages to the offline node; The connection between each of the subscribers and the offline node is disconnected.

6. The method for establishing a message publishing and subscription system according to claim 1, characterized in that: Before sending the message of the designated channel to the connected node through the publisher, the method further includes: A target node corresponding to the message of the designated channel is selected according to the load or storage capacity of the node.

7. The method for establishing a message publishing and subscription system according to claim 1, characterized in that: The method further comprises: The target node corresponding to each channel is determined according to the first hash value of the channel and the second hash value of the node address.

8. The method for establishing a message publish-subscribe system as claimed in claim 7, characterized in that: The step of determining the target node corresponding to each channel according to the first hash value of the channel and the second hash value of the node address includes: Calculate and obtain a first hash value for each channel and a second hash value for each node address; Obtain a target channel and a target node having a smaller difference between the first hash value and the second hash value; The target channel and the target node are bound.

9. A computer readable medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for establishing a message publishing and subscribing system described in any one of claims 1 to 8 is implemented.

10. An electronic device, characterized in that: include: processor; A memory, configured to store executable instructions of the processor; The processor executes the executable instructions to enable the electronic device to implement the method for establishing a message publish-subscribe system as described in any one of claims 1 to 8 above.

Citation Information

Patent Citations

  • Instruction response method and device of Redis cluster proxy mode and electronic equipment

    CN114281410A

  • Cluster publishing and subscribing method, device and equipment and readable storage medium

    CN117834711A

  • Distributed cache publishing and subscribing method, system and device

    CN117857627A