Distributed message event subscription method, system, electronic device and storage medium

By using the method category in the subscriber method, the method of annotation of subscription themes and registering event subscription channels can solve the problem of high server resources in the distributed architecture, realized efficient distributed event subscriptions, and reduced system costs.

CN116016678BActive Publication Date: 2025-01-28广域铭岛数字科技有限公司 +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202211603875.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-13
Publication Date
2025-01-28
Estimated Expiration
2042-12-13

AI Technical Summary

Technical Problem

In the high concurrency and high throughput scenarios, the introduction of MQ message middleware such as KAFKA has resulted in large server resources occupancy and high system costs.

Method used

Through the method of the subscriber method class, the subscription theme is annotated. When loading the subscriber method class, the scanning method annotation obtains the corresponding subscription theme, and register the event subscription channel corresponding to the subscription theme to realize the event subscription between distributed nodes. Reduce server resources occupation.

Benefits of technology

In the absence of MQ messages such as Kafka, event subscriptions between distributed nodes were realized, reducing the cost of server resource occupation and subscription costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116016678B_ABST
    Figure CN116016678B_ABST
Patent Text Reader

Abstract

The present invention relates to the technical field of event subscription, and discloses a distributed message event subscription method, system, electronic device and storage medium. The method carries a subscription topic through a method annotation of a subscriber method class. When loading the subscriber method class, the method annotation is scanned to obtain a corresponding subscription topic, and an event subscription channel corresponding to the subscription topic is registered, so that the topic event corresponding to the subscription topic is monitored according to the event subscription channel, and the topic event is sent to a cluster node corresponding to the subscriber method class. The subscription topic is carried through a method annotation, and the event subscription channel of the subscription topic is registered when the method is loaded, so that event subscription between distributed nodes is realized without the need for MQ message middleware such as KAFKA, thereby reducing server resource occupation and subscription costs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of event subscription, and in particular to a distributed message event subscription method, system, electronic device and storage medium. Background Art

[0002] With the continuous rise of microservices and distributed architecture, the system has an increasingly strong demand for high concurrency and high throughput scenarios, and the deployment of multi-node distributed cluster nodes has become the norm. Since distributed cluster nodes involve asynchronous execution and state synchronization, the event bus of the distributed cluster nodes provides event synchronization to ensure the consistency of node data.

[0003] At the same time, because the event buses of frameworks such as SpringEvent, GuavaEventBus, and RxBus only support event communication within the same process of a single cluster node, multi-node event communication is usually solved based on MQ message middleware such as KAFKA. However, the introduction of MQ (MessageQueue) message middleware such as KAFKA (distributed publish-subscribe messaging system) occupies a large amount of server resources in the distributed architecture, resulting in high system costs. Summary of the invention

[0004] In order to provide a basic understanding of some aspects of the disclosed embodiments, a brief summary is given below. The summary is not an extensive review, nor is it intended to identify key / critical components or delineate the scope of protection of these embodiments, but rather serves as a prelude to the detailed description that follows.

[0005] In view of the above-mentioned shortcomings of the prior art, the present invention discloses a distributed message event subscription method, system, electronic device and storage medium to reduce server resource occupation.

[0006] The present invention provides a distributed message event subscription method, comprising: obtaining a distributed node group, the distributed node group comprising a plurality of cluster nodes, wherein a subscriber method class exists in the distributed node group, and a method annotation of the subscriber method class carries a subscription subject; if the subscriber method class is loaded, a subscription subject corresponding to the subscriber method class is obtained by scanning the method annotation; an event subscription channel is registered according to the subscription subject, the event subscription channel is used to monitor message events published by the cluster node according to the subscription subject; if a subject event corresponding to the subscription subject is monitored, the subject event is sent to the cluster node corresponding to the subscriber method class.

[0007] Optionally, the subscription topic corresponding to the subscriber method class is obtained by scanning the method annotation, including: determining the loading method corresponding to the subscriber method class as the target method; in response to intercepting the initialization of the target method, scanning the method annotation of the subscriber method class to obtain the subscription topic.

[0008] Optionally, registering an event subscription channel according to the subscription topic includes: the distributed node group also includes a cache server, wherein the cache server is respectively connected to each of the cluster nodes; and registering an event subscription channel corresponding to the subscription topic through the cache server.

[0009] Optionally, the event subscription channel is used to listen to message events published by the cluster nodes based on the subscription topic by the following method: the method annotation also includes a subscription scope identifier; the subscription scope identifier corresponding to the subscription topic is determined by scanning the method annotation; the cluster nodes are matched according to the subscription identifier range to obtain a target listening node, wherein the target listening node includes at least a part of the cluster nodes; and the event subscription channel is used to listen to message events published by the target listening node.

[0010] Optionally, sending the topic event to the cluster node corresponding to the subscriber method class includes: establishing an event callback interface corresponding to the subscription topic in the cluster node corresponding to the subscriber method class, and storing the topic event in a preset event queue; reading the topic event through the event queue, and sending the read topic event to the cluster node corresponding to the subscriber method class by calling the event callback interface.

[0011] Optionally, the event queue includes at least one of the following: a first-in-first-out queue, used to read the subject events in a first-in-first-out order; a last-in-first-out queue, used to read the subject events in a last-in-first-out order.

[0012] Optionally, the method also includes: counting the amount of retained data of retained events, and counting the number of subscription nodes of subscriber nodes, wherein the retained events include subject events in a waiting-to-send state, and the subscriber nodes include cluster nodes corresponding to the subscriber method class; if the first preset condition or the second preset condition is met, a portion of the retained events are cached in a preset storage space, wherein the first preset condition includes that the amount of retained data is greater than or equal to a preset data threshold, and the second preset condition includes that the number of subscription nodes is greater than or equal to a preset number threshold; if the third preset condition and the fourth preset condition are met, extracting the retained events in the preset storage space, and sending the extracted retained events to the corresponding cluster nodes, wherein the third preset condition includes that the amount of retained data is less than the preset data threshold, and the second preset condition includes that the number of subscription nodes is less than the preset number threshold.

[0013] The present invention provides a distributed message event subscription system, comprising: an acquisition module, used to acquire a distributed node group, the distributed node group comprising multiple cluster nodes, wherein a subscriber method class exists in the distributed node group, and the method annotation of the subscriber method class carries a subscription topic; a scanning module, used to obtain the subscription topic corresponding to the subscriber method class by scanning the method annotation if the subscriber method class is loaded; a registration module, used to register an event subscription channel according to the subscription topic, and the event subscription channel is used to monitor the message events published by the cluster node according to the subscription topic; a subscription module, used to send the topic event to the cluster node corresponding to the subscriber method class if a topic event corresponding to the subscription topic is monitored.

[0014] The present invention provides an electronic device, comprising: a processor and a memory; the memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the electronic device executes the above method.

[0015] The present invention provides a computer-readable storage medium on which a computer program is stored: when the computer program is executed by a processor, the above method is implemented.

[0016] Beneficial effects of the present invention:

[0017] The subscription topic is carried by the method annotation of the subscriber method class. When loading the subscriber method class, the method annotation is scanned to obtain the corresponding subscription topic, and the event subscription channel corresponding to the subscription topic is registered, so that the topic events corresponding to the subscription topic are listened to according to the event subscription channel, and the topic events are sent to the cluster node corresponding to the subscriber method class. In this way, the subscription topic is carried by the method annotation, and the event subscription channel of the subscription topic is registered when the method is loaded, so that event subscription between distributed nodes is realized without the need for MQ message middleware such as KAFKA, reducing server resource usage and subscription costs. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 It is a flowchart of a distributed message event subscription method in an embodiment of the present invention;

[0019] Figure 2 It is a system framework for implementing a distributed message event subscription method in an embodiment of the present invention;

[0020] Figure 3 is a flow chart of another distributed message event subscription method in an embodiment of the present invention;

[0021] Figure 4 It is a structural diagram of a distributed message event subscription system in an embodiment of the present invention;

[0022] Figure 5 is a schematic diagram of an electronic device in an embodiment of the present invention. DETAILED DESCRIPTION

[0023] The following describes the embodiments of the present invention through specific examples, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the following embodiments and sub-samples in the embodiments can be combined with each other without conflict.

[0024] It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present invention, and thus the drawings only show components related to the present invention rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.

[0025] In the following description, numerous details are discussed to provide a more thorough explanation of the embodiments of the present invention. However, it is obvious to those skilled in the art that the embodiments of the present invention can be implemented without these specific details. In other embodiments, well-known structures and devices are shown in the form of block diagrams rather than in detail to avoid making the embodiments of the present invention difficult to understand.

[0026] The terms "first", "second", etc. in the specification and claims of the embodiments of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchanged where appropriate, so that the embodiments of the embodiments of the present disclosure described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions.

[0027] Unless otherwise stated, the term "plurality" means two or more.

[0028] In the embodiment of the present disclosure, the character " / " indicates that the preceding and following objects are in an "or" relationship. For example, A / B indicates: A or B.

[0029] The term "and / or" is a description of the association relationship between objects, indicating that three relationships can exist. For example, A and / or B means: A or B, or, A and B.

[0030] Combination Figure 1 As shown, the embodiment of the present disclosure provides a distributed message event subscription method, including:

[0031] Step S101, obtaining a distributed node group;

[0032] Wherein, the distributed node group includes multiple cluster nodes;

[0033] Among them, there is a subscriber method class in the distributed node group, and the method annotation of the subscriber method class carries the subscription topic;

[0034] Step S102: if the subscriber method class is loaded, the subscription topic corresponding to the subscriber method class is obtained by scanning the method annotation;

[0035] Step S103, registering an event subscription channel according to the subscription topic, where the event subscription channel is used to monitor message events published by cluster nodes according to the subscription topic;

[0036] Step S104: if a topic event corresponding to the subscribed topic is monitored, the topic event is sent to the cluster node corresponding to the subscriber method class.

[0037] The distributed message event subscription method provided by the embodiment of the present disclosure is adopted. The subscription topic is carried by the method annotation of the subscriber method class. When loading the subscriber method class, the method annotation is scanned to obtain the corresponding subscription topic, and the event subscription channel corresponding to the subscription topic is registered, so as to monitor the topic event corresponding to the subscription topic according to the event subscription channel, and send the topic event to the cluster node corresponding to the subscriber method class. In this way, the subscription topic is carried by the method annotation, and the event subscription channel of the subscription topic is registered when the method is loaded, thereby realizing event subscription between distributed nodes without the need for MQ message middleware such as KAFKA, reducing server resource occupation and subscription costs.

[0038] Optionally, the subscription topic corresponding to the subscriber method class is obtained by scanning the method annotation, including: determining the loading method corresponding to the subscriber method class as the target method; in response to the initialization of the intercepted target method, scanning the method annotation of the subscriber method class to obtain the subscription topic.

[0039] In some embodiments, the initialization of the target method is intercepted by AOP (Aspect Oriented Programming), and the method annotation of the subscriber method class is scanned to obtain the subscription subject; the target method and the subscription subject are added to a preset subscription cache queue.

[0040] In some embodiments, by using the responsive Reactor framework (an asynchronous application basic library based on JVM), based on the event model and FluxSink stream characteristics of the Reactor framework, and utilizing Spring's AOP programming ideas, the loading method initialization of all classes of BeanPostProcessor is intercepted, and all method classes that implement custom annotations are loaded to achieve the function of asynchronous callback of all messages.

[0041] In this way, by introducing the responsive programming framework Reactor, natural asynchronous non-blocking programming, natural streaming programming based on the event subscription model, and reusing the multiplexing principles of Netty, asynchronous event communication under high concurrency can effectively reduce the number of newly opened threads and context switching, causing efficiency and throughput problems. And by reusing the back pressure processing mechanism of Reactor, it can effectively solve problems such as data backlog under high concurrency.

[0042] Optionally, registering an event subscription channel according to a subscription topic includes: the distributed node group further includes a cache server, wherein the cache server is respectively connected to each cluster node; and registering an event subscription channel corresponding to the subscription topic through the cache server.

[0043] In some embodiments, each cluster node is connected to a Redis server of a Redis database through a Redis (RemoteDictionaryServer) client.

[0044] In some embodiments, the Redis database has a subscription publishing command for registering a subscription channel, and the subscription topic in the subscription cache queue is sent to the Redis database in the form of a subscription publishing command to register the subscription topic to the event subscription channel of the Redis database.

[0045] In some embodiments, by reusing the publish-subscribe mode of the Redis database, by calling the Redis publish-subscribe command in the system program, a subscriber can have multiple channels, allowing each node to establish a connection with the Redis database, so that the node has the ability to communicate events in real time and broadcast to other nodes in real time. The Redis database has a high QPS (Queries-per-second), mature technology, and high stability. It can withstand data communication under high concurrency and ensure real-time asynchronous communication of data.

[0046] Optionally, an event subscription channel is used to listen to message events published by cluster nodes based on a subscription topic, including: the method annotation also includes a subscription scope identifier; the subscription scope identifier corresponding to the subscription topic is determined by scanning the method annotation; the cluster nodes are matched according to the subscription identifier range to obtain a target listening node, wherein the target listening node includes at least a part of the cluster nodes; and the event subscription channel is used to listen to message events published by the target listening node.

[0047] In some embodiments, the subscription scope identifier includes @local, @broker, and @Subscribe, wherein @local indicates local consumption, @broker indicates cluster consumption, and @Subscribe indicates local consumption and cluster consumption.

[0048] In some embodiments, through custom annotations @Subscribe, @broker, and @local, data is automatically obtained through AOP scanning, including the method that needs to subscribe to messages, whether to subscribe to local messages, cluster messages, or both, and the above subscriptions are written to the memory, and combined with the sink mechanism of the responsive programming Reactor framework, all subscription callbacks are added to the event consumption. In addition, in the memory queue, each push event can be filtered by topic rules in the queue to achieve advanced subscription methods such as fuzzy matching and rule matching, so as to achieve a more general distributed event communication method.

[0049] Optionally, sending the topic event to the cluster node corresponding to the subscriber method class includes: establishing an event callback interface corresponding to the subscription topic in the cluster node corresponding to the subscriber method class, and storing the topic event in a preset event queue; reading the topic event through the event queue, and sending the read topic event to the cluster node corresponding to the subscriber method class by calling the event callback interface.

[0050] In some embodiments, the read subject event is sent to the subscription method corresponding to the subscriber method class by means of a sink.

[0051] Optionally, the event queue includes at least one of the following: a first-in-first-out queue, used to read the subject events in a first-in-first-out order; a last-in-first-out queue, used to read the subject events in a last-in-first-out order.

[0052] In some embodiments, the Redis client is used to execute publish-subscribe commands and push data into a local FIFO (FirstInputFirstOutput) or LIFO (LastInputFirstOutput) queue. The local reads data from the queue in sequence to achieve sequential consumption.

[0053] Optionally, the method also includes: counting the amount of retained data of retained events, and counting the number of subscription nodes of subscriber nodes, wherein the retained events include subject events in a waiting-to-send state, and the subscriber nodes include cluster nodes corresponding to the subscriber method class; if the first preset condition or the second preset condition is met, a portion of the retained events are cached in a preset storage space, wherein the first preset condition includes that the amount of retained data is greater than or equal to a preset data threshold, and the second preset condition includes that the number of subscription nodes is greater than or equal to a preset number threshold; if the third preset condition and the fourth preset condition are met, the retained events in the preset storage space are extracted, and the extracted retained events are sent to the corresponding cluster nodes, wherein the third preset condition includes that the amount of retained data is less than the preset data threshold, and the second preset condition includes that the number of subscription nodes is less than the preset number threshold.

[0054] In some embodiments, topic events in a waiting-to-send state are cached based on back pressure rules to retain topic events that downstream nodes do not have time to consume, so that each topic event can be sent to the corresponding subscriber, ensuring the stability and consistency of event subscription.

[0055] Combination Figure 2As shown, an embodiment of the present disclosure provides a system framework for implementing a distributed message event subscription method, including a cluster node 201 and a cache database 202; the cluster node is used to send message events to the cache database; the cluster node is also used to scan the method annotation of the subscriber method class to obtain the subscription topic when loading the subscriber method class, and send the subscription topic to the cache database according to the subscription topic; the cache database is used to register an event subscription channel according to the received subscription topic, and listen to the message events sent by the cluster node through the event subscription channel to obtain the topic event corresponding to the subscription topic; the cache database is also used to send the topic event to the cluster node corresponding to the topic event by means of a sink.

[0056] The system framework for implementing the distributed message event subscription method provided by the embodiment of the present disclosure is adopted. The subscription topic is carried by the method annotation of the subscriber method class. When loading the subscriber method class, the method annotation is scanned to obtain the corresponding subscription topic, and the event subscription channel corresponding to the subscription topic is registered, so as to monitor the topic event corresponding to the subscription topic according to the event subscription channel, and send the topic event to the cluster node corresponding to the subscriber method class. In this way, the subscription topic is carried by the method annotation, and the event subscription channel of the subscription topic is registered when the method is loaded, thereby realizing event subscription between distributed nodes without the need for MQ message middleware such as KAFKA, reducing server resource occupancy and subscription costs.

[0057] Combination Figure 3 As shown, the embodiment of the present disclosure provides a distributed message event subscription method, including:

[0058] Step S301, the cluster node sends a message event to the cache server;

[0059] Step S302: The cluster node intercepts the loading method corresponding to the subscriber method class through AOP;

[0060] Step S303, the cluster node scans the method annotation of the subscriber method class to obtain the subscription topic;

[0061] Step S304, the cluster node sends a subscription topic to the cache server;

[0062] Step S305, the cache server registers an event subscription channel by subscribing to a topic;

[0063] Step S306, the cache server uses the event subscription channel to monitor the message event and obtains the topic event corresponding to the subscription topic;

[0064] Step S307: The cache server sends the topic event to the cluster node.

[0065] The distributed message event subscription method provided by the embodiment of the present disclosure is adopted. The subscription topic is carried by the method annotation of the subscriber method class. When loading the subscriber method class, the method annotation is scanned to obtain the corresponding subscription topic, and the event subscription channel corresponding to the subscription topic is registered, so as to monitor the topic event corresponding to the subscription topic according to the event subscription channel, and send the topic event to the cluster node corresponding to the subscriber method class. In this way, the subscription topic is carried by the method annotation, and the event subscription channel of the subscription topic is registered when the method is loaded, thereby realizing event subscription between distributed nodes without the need for MQ message middleware such as KAFKA, reducing server resource occupation and subscription costs.

[0066] Combination Figure 4 As shown, the embodiment of the present disclosure provides a distributed message event subscription system, including an acquisition module 401, a scanning module 402, a registration module 403, and a subscription module 404. The acquisition module 401 is used for the acquisition module, which is used to acquire a distributed node group, and the distributed node group includes multiple cluster nodes, wherein there is a subscriber method class in the distributed node group, and the method annotation of the subscriber method class carries the subscription topic; the scanning module 402 is used to obtain the subscription topic corresponding to the subscriber method class by scanning the method annotation if the subscriber method class is loaded; the registration module 403 is used to register an event subscription channel according to the subscription topic, and the event subscription channel is used to monitor the message events published by the cluster node according to the subscription topic; the subscription module 404 is used to send the topic event to the cluster node corresponding to the subscriber method class if the topic event corresponding to the subscription topic is monitored.

[0067] The distributed message event subscription system provided by the embodiment of the present disclosure is adopted. The subscription topic is carried by the method annotation of the subscriber method class. When loading the subscriber method class, the method annotation is scanned to obtain the corresponding subscription topic, and the event subscription channel corresponding to the subscription topic is registered, so as to monitor the topic event corresponding to the subscription topic according to the event subscription channel, and send the topic event to the cluster node corresponding to the subscriber method class. In this way, the subscription topic is carried by the method annotation, and the event subscription channel of the subscription topic is registered when the method is loaded, so that event subscription between distributed nodes is realized without the need for MQ message middleware such as KAFKA, reducing server resource occupation and subscription costs.

[0068] Figure 5 The structure diagram of the computer system suitable for implementing the electronic device of the embodiment of the present application is shown. It should be noted that: Figure 5 The computer system 500 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.

[0069] like Figure 5As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 502 or the program loaded from the storage part 508 to the random access memory (RAM) 503, such as executing the method in the above embodiment. In RAM503, various programs and data required for system operation are also stored. CPU501, ROM502 and RAM503 are connected to each other through a bus 504. Input / output (I / O) interface 505 is also connected to bus 504.

[0070] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, etc.; an output section 507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 510 as needed so that a computer program read therefrom is installed into the storage section 508 as needed.

[0071] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart 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 includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication section 509, and / or installed from a removable medium 511. When the computer program is executed by a central processing unit (CPU) 501, various functions defined in the system of the present application are executed.

[0072] 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, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, 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 signal medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a computer-readable computer program is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. A computer program contained on a computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.

[0073] The embodiments of the present disclosure further provide a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, any one of the methods in the embodiments is implemented.

[0074] The computer-readable storage medium in the embodiments of the present disclosure can be understood by ordinary technicians in the field: all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to the computer program. The aforementioned computer program can be stored in a computer-readable storage medium. When the program is executed, the execution includes the steps of the above-mentioned method embodiments; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk and other media that can store program codes.

[0075] The electronic device disclosed in this embodiment includes a processor, a memory, a transceiver and a communication interface. The memory and the communication interface are connected to the processor and the transceiver and complete communication with each other. The memory is used to store computer programs, the communication interface is used to communicate, and the processor and the transceiver are used to run the computer program so that the electronic device executes each step of the above method.

[0076] In this embodiment, the memory may include a random access memory (Random Access Memory, RAM for short), and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.

[0077] The above-mentioned processors can be general-purpose processors, including central processing units (CPU), graphics processing units (GPU), network processors (NP), etc.; they can also be digital signal processors (DSP), application specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.

[0078] The above description and accompanying drawings fully illustrate the embodiments of the present disclosure so that those skilled in the art can practice them. Other embodiments may include structural, logical, electrical, process and other changes. The embodiments represent possible changes only. Unless explicitly required, separate components and functions are optional, and the order of operation may vary. Parts and subsamples of some embodiments may be included in or replace parts and subsamples of other embodiments. Moreover, the words used in this application are only used to describe the embodiments and are not used to limit the claims. As used in the description of the embodiments and claims, unless the context clearly indicates, the singular forms of "a", "an" and "the" are intended to include plural forms as well. Similarly, the term "and / or" as used in this application refers to any and all possible combinations of listings containing one or more associated ones. In addition, when used in the present application, the term "comprise" and its variants "comprises" and / or comprising refer to the presence of a stated sub-sample, whole, step, operation, element, and / or component, but do not exclude the presence or addition of one or more other sub-samples, wholes, steps, operations, elements, components and / or groups of these. In the absence of further restrictions, the elements defined by the sentence "comprising a ..." do not exclude the presence of other identical elements in the process, method or device comprising the elements. In this article, each embodiment may focus on the differences from other embodiments, and the same and similar parts between the various embodiments may refer to each other. For the methods, products, etc. disclosed in the embodiments, if they correspond to the method part disclosed in the embodiments, then the relevant parts can refer to the description of the method part.

[0079] Those skilled in the art will appreciate that the units and algorithm steps of each example 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 performed in hardware or software may depend on the specific application and design constraints of the technical solution. Technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the embodiments of the present disclosure. Technicians can clearly understand that for the convenience and simplicity of description, the specific working process of the above-described system, device and unit can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0080] In the embodiments disclosed herein, the disclosed methods and products (including but not limited to devices, equipment, etc.) can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units can be only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some sub-samples can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between each other shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms. The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to implement this embodiment. In addition, each functional unit in the embodiment of the present disclosure may be integrated in a processing unit, or each unit may exist physically alone, or two or more units may be integrated in one unit.

[0081] The flowchart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to the embodiment of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. 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 consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. In the description corresponding to the flowchart and the block diagram in the accompanying drawings, the operations or steps corresponding to different boxes can also occur in a different order from the order disclosed in the description, and sometimes there is no specific order between different operations or steps. For example, two consecutive operations or steps can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. Each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented by a dedicated hardware-based system that performs the specified functions or actions, or may be implemented by a combination of dedicated hardware and computer instructions.

Claims

1. A distributed message event subscription method, characterized in that: include: Acquire a distributed node group, the distributed node group including a plurality of cluster nodes, wherein a subscriber method class exists in the distributed node group, and a method annotation of the subscriber method class carries a subscription topic; If the subscriber method class is loaded, the subscription topic corresponding to the subscriber method class is obtained by scanning the method annotation; Register an event subscription channel according to the subscription topic, wherein the event subscription channel is used to monitor message events published by the cluster node according to the subscription topic; If a topic event corresponding to the subscription topic is monitored, the topic event is sent to the cluster node corresponding to the subscriber method class; The method comprises: monitoring the message events published by the cluster nodes according to the subscription topic, wherein the method annotation further comprises a subscription scope identifier; determining the subscription scope identifier corresponding to the subscription topic by scanning the method annotation; matching the cluster nodes according to the subscription scope identifier to obtain a target monitoring node, wherein the target monitoring node comprises at least a part of the cluster nodes; and monitoring the message events published by the target monitoring node using the event subscription channel; The subscription scope identifier includes at least one of local consumption and cluster consumption.

2. The method according to claim 1, characterized in that The subscription topic corresponding to the subscriber method class is obtained by scanning the method annotation, including: Determine the loading method corresponding to the subscriber method class as the target method; Using Spring's AOP programming concept, intercept the loading method initialization of the subscriber method class; In response to intercepting the initialization of the target method, by using the responsive Reactor framework, based on the event model and FluxSink stream characteristics of the Reactor framework, all method classes that implement method annotations are loaded to scan the method annotations of the subscriber method class to obtain the subscription topic.

3. The method according to claim 1, characterized in that: Registering an event subscription channel according to the subscription topic includes: The distributed node group further includes a cache server, wherein the cache server is respectively connected to each of the cluster nodes; Register an event subscription channel corresponding to the subscription topic through the cache server.

4. The method according to claim 1, characterized in that: Sending the subject event to the cluster node corresponding to the subscriber method class includes: Establishing an event callback interface corresponding to the subscription topic in the cluster node corresponding to the subscriber method class, and storing the topic event in a preset event queue; The subject event is read through the event queue, and the read subject event is sent to the cluster node corresponding to the subscriber method class by calling the event callback interface.

5. The method according to claim 4, characterized in that The event queue includes at least one of the following: A first-in-first-out queue, used to read the subject events in a first-in-first-out order; A last-in-first-out queue is used to read the subject events in a last-in-first-out order.

6. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: Counting the amount of retained data of the retained event and counting the number of subscriber nodes of the subscriber node, wherein the retained event includes a subject event in a waiting-to-send state, and the subscriber node includes a cluster node corresponding to the subscriber method class; If a first preset condition or a second preset condition is met, a portion of the retained events are cached in a preset storage space, wherein the first preset condition includes that the amount of retained data is greater than or equal to a preset data threshold, and the second preset condition includes that the number of subscription nodes is greater than or equal to a preset number threshold; If the third preset condition and the fourth preset condition are met, the retention events in the preset storage space are extracted, and the extracted retention events are sent to the corresponding cluster node, wherein the third preset condition includes that the amount of retained data is less than the preset data threshold, and the second preset condition includes that the number of subscribed nodes is less than the preset number threshold.

7. A distributed message event subscription system, characterized in that: include: An acquisition module, used for acquiring a distributed node group, the distributed node group including a plurality of cluster nodes, wherein a subscriber method class exists in the distributed node group, and a method annotation of the subscriber method class carries a subscription topic; A scanning module, for obtaining a subscription topic corresponding to the subscriber method class by scanning the method annotation if the subscriber method class is loaded; A registration module, used to register an event subscription channel according to the subscription topic, and the event subscription channel is used to monitor the message events published by the cluster node according to the subscription topic; The subscription module is used to send the subject event corresponding to the subscription subject to the cluster node corresponding to the subscriber method class if the subject event corresponding to the subscription subject is monitored; The event subscription channel monitors the message events published by the cluster node according to the subscription topic in the following manner, wherein the method annotation also includes a subscription scope identifier; the subscription scope identifier corresponding to the subscription topic is determined by scanning the method annotation; the cluster node is matched according to the subscription scope identifier to obtain a target listening node, wherein the target listening node includes at least a part of the cluster nodes; and the message events published by the target listening node are monitored by using the event subscription channel; The subscription scope identifier includes at least one of local consumption and cluster consumption.

8. An electronic device, characterized in that: include: Processor and memory; The memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the electronic device executes the method according to any one of claims 1 to 6.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.