Dynamic routing message queue transceiving method and device

Through the tangential programming technology, dynamically manages the producers and consumers of message queues, solving the problems of complex configuration and high coupling in traditional message queue architectures, and achieving flexible configuration and efficient management.

CN119484462AActive Publication Date: 2025-02-18GUANGDONG SOUTH SMART MEDIA TECH CO LTD
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202411541196.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-31
Publication Date
2025-02-18
Estimated Expiration
2044-10-31

AI Technical Summary

Technical Problem

Traditional message queue architecture is complex and error-prone in configuration management. The message sender and receiver are highly coupled, making it difficult to achieve flexible message routing and load balancing, and the configuration and code coupling are high, making it difficult to maintain.

Method used

Through tangent-oriented programming technology, intercept method objects containing specific annotations, dynamically manage producers and consumers, and realize flexible configuration and routing of message queues. The specific steps include reading preset configuration information, building a message sending unit and receiving unit, dynamic routing encapsulation, and obtaining a collection of producers and consumers.

Benefits of technology

It realizes flexible configuration of message queues, reduces system coupling, improves the flexibility of the extended system and message management efficiency, and reduces the need for code modification.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119484462A_ABST
    Figure CN119484462A_ABST
Patent Text Reader

Abstract

The invention discloses a dynamic routing message queue transmitting and receiving method and device. The method comprises the following steps: intercepting a method object containing a first annotation through a section class; wherein the first annotation comprises message sending unit information or message receiving unit information; when the first annotation is message sending unit information, selecting a corresponding message sending unit from a producer set according to the message sending unit information, and sending a message in the corresponding method object to a corresponding message queue through the message sending unit; and when the first annotation is message receiving unit information, adding the corresponding method object into a consumer set, and according to the message receiving unit information contained in the first annotation, taking the method object as a message receiving unit to process the message of the corresponding message queue. Through the message queue management method and device, the coupling degree of the service code and the queue calling logic in the message receiving and sending process can be reduced, and meanwhile the message queue management efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer software, and in particular to a method and device for sending and receiving a dynamic routing message queue. Background Art

[0002] With the vigorous development of distributed systems and microservice architectures, message queue middleware has become a core component for realizing key functions such as system decoupling, asynchronous communication, and traffic peak shaving.

[0003] However, the traditional message queue architecture requires the configuration of multiple message queue clients during configuration management, which makes management complex and error-prone. At the same time, the message sender and receiver are highly coupled, making it difficult to perform flexible message routing and load balancing. The configuration and code are highly coupled, making them difficult to maintain.

[0004] Therefore, how to achieve flexible configuration of message queues to reduce system coupling is a technical problem that needs to be solved at present. Summary of the invention

[0005] The present application provides a method and device for sending and receiving a dynamic routing message queue to solve the technical problem of how to achieve flexible configuration of the message queue to reduce the degree of system coupling.

[0006] In order to solve the above technical problems, in a first aspect, an embodiment of the present application provides a method for sending and receiving a dynamic routing message queue, comprising:

[0007] Intercepting a method object containing a first annotation through a section class; wherein the first annotation includes message sending unit information or message receiving unit information;

[0008] When the first annotation is message sending unit information, according to the message sending unit information, a corresponding message sending unit is selected from the producer set, and the message in the corresponding method object is sent to the corresponding message queue through the message sending unit;

[0009] When the first annotation is message receiving unit information, the corresponding method object is added to the consumer collection, and according to the message receiving unit information included in the first annotation, the method object is used as a message receiving unit to process the message of the corresponding message queue.

[0010] Compared with the prior art, the embodiments of the present application have the following beneficial effects: through aspect-oriented programming technology, the calling logic of the message queue is decoupled from the business code, and the code is integrated in a zero-intrusive manner, thereby reducing the coupling degree of the system; in addition, through aspect-oriented programming technology, producers and consumers are dynamically managed separately without modifying the code, which not only improves the flexibility of the expansion system, but also reduces the coupling degree of the message sender and receiver to realize the reception and sending of messages.

[0011] In some embodiments of the first aspect of the present application, before intercepting the method object containing the first annotation through the aspect class, it also includes:

[0012] Reading preset configuration information, and constructing a plurality of message sending units and a plurality of message receiving units according to the configuration information;

[0013] Performing dynamic routing encapsulation on all the message sending units to obtain a producer set of a dual dictionary structure;

[0014] Dynamic routing encapsulation is performed on all the message receiving units to obtain a consumer set in a single dictionary structure.

[0015] Compared with the prior art, the above embodiment has the following beneficial effects: by automatically reading the configuration file, the message sending unit (i.e., producer) and the message receiving unit (i.e., consumer) corresponding to the message queue are dynamically created and managed, thereby realizing the decoupling of configuration and business code and improving the subsequent maintenance and upgrade of the system; in addition, through dynamic routing encapsulation, subsequent dynamic routing is realized, thereby improving the management efficiency of the message sending unit and the message receiving unit.

[0016] In some embodiments of the first aspect of the present application, performing dynamic routing encapsulation on all the message sending units to obtain a producer set of a dual dictionary structure includes:

[0017] The producer set includes: a first dictionary and a second dictionary;

[0018] Using the name of each message sending unit as an index value, constructing a first dictionary with a single-layer structure;

[0019] The message sending units are grouped according to their names, and the group names are used as index values ​​of the first layer of the second dictionary, and the names of the message sending units are used as index values ​​of the second layer of the second dictionary to construct a double-layer second dictionary.

[0020] Compared with the prior art, the above embodiment has the following beneficial effects: by performing double-layer mapping on the message sending unit and the message receiving unit, the efficiency of the producer's dynamic routing is improved, and the reliability of message sending is further improved.

[0021] In some embodiments of the first aspect of the present application, selecting a corresponding producer from a producer set according to the message sending unit information included in the first annotation includes:

[0022] The message sending unit information includes: the name of the message sending unit;

[0023] According to the name of the message sending unit, determining whether there is a corresponding message sending unit in the second dictionary;

[0024] If the corresponding message sending unit exists in the second dictionary, the corresponding message sending unit is returned; otherwise, it is determined whether the corresponding message sending unit exists in the first dictionary;

[0025] If the corresponding message sending unit exists in the first dictionary, the corresponding message sending unit is returned; otherwise, the preset message sending unit is returned.

[0026] Compared with the prior art, the above embodiment has the following beneficial effects: first, through the second dictionary with a double-layer structure, dynamic routing is performed in combination with two index values, thereby effectively improving the routing efficiency of the message sending unit; in addition, in the entire routing process, two dictionaries are used for dynamic routing to ensure that available message sending units can be selected, thereby improving the reliability of subsequent message sending.

[0027] In some embodiments of the first aspect of the present application, according to the message receiving unit information included in the second annotation, using the method object as a message receiving unit to process the message of the corresponding message queue includes:

[0028] The message receiving unit information includes: the monitoring queue name and the message tag;

[0029] The message receiving unit is used to subscribe to messages of the message queue corresponding to the monitoring queue name, and the message receiving unit is used to process messages corresponding to the message tag.

[0030] Compared with the prior art, the above embodiment has the following beneficial effects: by including the queue name to be monitored and the message to be processed in the annotation, combined with aspect programming technology, the message can be processed flexibly, and the business code is decoupled from the message queue call logic to achieve zero-intrusive integration.

[0031] In a second aspect, an embodiment of the present application further provides a dynamic routing message queue transceiver device, including: an interception module, a message sending module, and a message processing module;

[0032] The interception module is used to intercept a method object containing a first annotation through a section class; wherein the first annotation includes message sending unit information or message receiving unit information;

[0033] The message sending module is used for selecting a corresponding message sending unit from a producer set according to the message sending unit information when the first annotation is message sending unit information, and sending the message corresponding to the method object to a corresponding message queue through the message sending unit;

[0034] The message processing module is used to add the corresponding method object to the consumer collection when the first annotation is message receiving unit information, and use the method object as a message receiving unit to process messages of the corresponding message queue according to the message receiving unit information contained in the first annotation.

[0035] In some embodiments of the second aspect of the present application, before intercepting the method object containing the first annotation through the aspect class, it also includes:

[0036] Reading preset configuration information, and constructing a plurality of message sending units and a plurality of message receiving units according to the configuration information;

[0037] Performing dynamic routing encapsulation on all the message sending units to obtain a producer set of a dual dictionary structure;

[0038] Dynamic routing encapsulation is performed on all the message receiving units to obtain a consumer set in a single dictionary structure.

[0039] In some embodiments of the second aspect of the present application, the dynamically routing encapsulating all the message sending units to obtain a producer set of a dual dictionary structure includes:

[0040] The producer set includes: a first dictionary and a second dictionary;

[0041] Using the name of each message sending unit as an index value, constructing a first dictionary with a single-layer structure;

[0042] The message sending units are grouped according to their names, and the group names are used as index values ​​of the first layer of the second dictionary, and the names of the message sending units are used as index values ​​of the second layer of the second dictionary to construct a double-layer second dictionary.

[0043] In some embodiments of the second aspect of the present application, selecting a corresponding message sending unit from a producer set according to the message sending unit information includes:

[0044] The message sending unit information includes: the name of the message sending unit;

[0045] According to the name of the message sending unit, determining whether there is a corresponding message sending unit in the second dictionary;

[0046] If the corresponding message sending unit exists in the second dictionary, the corresponding message sending unit is returned; otherwise, it is determined whether the corresponding message sending unit exists in the first dictionary;

[0047] If the corresponding message sending unit exists in the first dictionary, the corresponding message sending unit is returned; otherwise, the preset message sending unit is returned.

[0048] In some embodiments of the second aspect of the present application, the method object is used as a message receiving unit to process a message of a corresponding message queue according to the message receiving unit information included in the second annotation, including:

[0049] The message receiving unit information includes: the monitoring queue name and the message tag;

[0050] The message receiving unit is used to subscribe to messages of the message queue corresponding to the monitoring queue name, and the message receiving unit is used to process messages corresponding to the message tag. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] Figure 1 A flowchart of a dynamic routing message queue sending and receiving method provided in some embodiments of the present application;

[0052] Figure 2 A schematic diagram of a solution deployment process corresponding to a method for sending and receiving a state routing message queue provided in an embodiment of the present application;

[0053] Figure 3 This is a structural diagram of a dynamic routing message queue transceiver provided in some embodiments of the present application. DETAILED DESCRIPTION

[0054] The traditional message queue architecture requires the configuration of multiple message queue clients during configuration management, which makes management complex and error-prone. At the same time, the message sender and receiver are highly coupled, making it difficult to perform flexible message routing and load balancing. The configuration and code are highly coupled, making them difficult to maintain.

[0055] In order to solve the above technical problems, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0056] Embodiment 1

[0057] In the embodiment of the present application, the message sending unit is a module or component for generating or sending information, and the message receiving unit is a module or component for receiving or processing information. Usually in business development, the message sending unit is called a producer (Producer) and the message receiving unit is called a consumer (Consumer).

[0058] Please refer to Figure 1 , a dynamic routing message queue sending and receiving method provided in an embodiment of the present application, including S10 to S30, specifically:

[0059] S10: intercepting a method object containing a first annotation through an aspect class; wherein the first annotation includes message sending unit information or message receiving unit information.

[0060] Preferably, in some embodiments of the present application, any annotation mentioned in the embodiments of the present application can be intercepted by the following preferred implementation: with the help of Spring AOP framework, through aspect-oriented programming technology, an aspect class is constructed, and a corresponding interception method is set in the aspect class, and the aspect class is registered as a proxy, thereby realizing the interception of the corresponding method of each annotation. During the execution of the aspect method, Java reflection technology is used to extract the method object in the current call stack, and detect whether the method object carries any annotation. Once the existence of the annotation is detected, the parameter attributes contained in the annotation, such as the name and label of the producer or consumer, etc., will be further extracted through Java reflection, which will be used as the basis for selecting subsequent producer or consumer instances.

[0061] Furthermore, in some embodiments of the present application, before intercepting the method object containing the first annotation through the aspect class, the method further includes:

[0062] Reading preset configuration information, and constructing a plurality of message sending units and a plurality of message receiving units according to the configuration information;

[0063] Performing dynamic routing encapsulation on all the message sending units to obtain a producer set of a dual dictionary structure;

[0064] Dynamic routing encapsulation is performed on all the message receiving units to obtain a consumer set in a single dictionary structure.

[0065] By automatically reading the configuration file, the message sending unit (i.e., producer) and message receiving unit (i.e., consumer) corresponding to the message queue are dynamically created and managed, thereby decoupling the configuration from the business code and improving the subsequent maintenance and upgrade of the system; in addition, through dynamic routing encapsulation, subsequent dynamic routing is achieved, improving the management efficiency of the message sending unit and the message receiving unit.

[0066] Preferably, in some embodiments of the present application, configuration information can be read and producers and consumers can be generated in the following manner:

[0067] Through aspect programming technology, set appropriate annotations, and formulate configuration file parsing rules according to the configuration standards of Spring Boot Starter. The specific steps are as follows:

[0068] S11: By constructing a configuration class named MultipleRocketProperties and marking the configuration class with a second annotation, the second annotation may be @ConfigurationProperties(prefix="nfzmy.rocketmq.multiple"), the corresponding configuration data is read and parsed from the configuration file application.yml, and a mapping relationship between the configuration file and the configuration class fields is established; wherein the configuration class defines fields corresponding to the application.yml configuration file, and constructs a structure including global configuration and multiple producer and consumer specific configurations; wherein the global configuration includes: general settings for producers and consumers; the producer and consumer specific configurations include at least: the name, SSL configuration, subject, group ID, access key, security key, and name service address of each producer and consumer;

[0069] S12: When the project starts, Spring Boot's configuration binding mechanism scans all configuration classes with the second annotation. When a configuration class is scanned, it finds matching configuration items in the configuration file corresponding to the specified prefix from the annotation. For example, the second annotation in S11 will search for matching configuration items in the application.yml configuration file according to the prefix "nfzmy.rocketmq.multiple" specified in the second annotation. When the configuration item is found, Spring Boot uses the property converter to map the values ​​of these configuration items to the fields of the configuration class, thereby reading the configuration file content and converting it into a Java object.

[0070] S13: Create a class through the producer or consumer, receive the Java object instance in S12, obtain all specific configurations of the producer or consumer of the message queue (as shown in the specific configuration content in S11), and further create and initialize instances of each producer and consumer based on the received specific configuration, and pass all instances to the dynamic routing producer class or dynamic routing consumer class (the dynamic routing producer class specifically refers to the configuration information of the dynamic routing producer class in S14) to implement dynamic routing encapsulation of the producer or consumer.

[0071] Further, in some embodiments of the present application, the step of performing dynamic routing encapsulation on all the message sending units to obtain a producer set of a dual dictionary structure includes:

[0072] The producer set includes: a first dictionary and a second dictionary;

[0073] Using the name of each message sending unit as an index value, constructing a first dictionary with a single-layer structure;

[0074] The message sending units are grouped according to their names, and the group names are used as index values ​​of the first layer of the second dictionary, and the names of the message sending units are used as index values ​​of the second layer of the second dictionary to construct a double-layer second dictionary.

[0075] By performing double-layer mapping on the message sending unit and the message receiving unit, the efficiency of the producer's dynamic routing is improved, and the reliability of message sending is further improved.

[0076] Preferably, in some embodiments of the present application, after the producer is obtained through S13, the producer is dynamically routed and encapsulated through the following preferred implementation to obtain a producer set:

[0077] S14: A dynamic routing producer class is formulated, and the dynamic routing producer class adopts a double dictionary structure, namely, a first dictionary producerBeanMap and a second dictionary groupProducerBeanMap, which are respectively used to store and manage independent producer instances and a set of producer instances grouped by group name. In addition, the dynamic routing producer class also includes a main producer identifier, which is represented by the index value of the preset producer. The main producer is the producer instance that should be used by default;

[0078] S15: By implementing the InitializingBean and DisposableBean interfaces in the dynamic routing producer class, the initialization and destruction process of the producer is managed. During initialization, the dynamic routing producer class loads all producer configurations in the configuration class in S11, inputs the producer configuration to the producer creation class described in S13, initializes the producer, and obtains the producer instance;

[0079] S16: Add all producer instances obtained in S15 to the first dictionary, and use the name of the producer instance as the index value; group the producer instances according to the underscores in the names of all producer instances in S15, and use the group name as the first-level index value of all producer instances in the group, and further use the name of each producer instance in the group as the second-level index value of the corresponding producer instance, thereby obtaining the second dictionary.

[0080] Preferably, in some embodiments of the present application, after obtaining the consumer through S13, the consumer is dynamically routed and packaged through the following preferred implementation to obtain a consumer set, wherein the consumer set includes: a third dictionary:

[0081] S17: By customizing the dynamic routing consumer class, the dynamic routing consumer class adopts a single dictionary structure, that is, the third dictionary consumerBeanMap;

[0082] S18: Manage the initialization and destruction process of consumers by implementing InitializingBean and DisposableBean interfaces in the dynamic routing consumer class. During initialization, the dynamic routing consumer class will load all consumer configurations in the configuration class in S11, input the consumer configurations into the consumer creation class described in S13, initialize the consumer, and obtain the consumer instance;

[0083] S19: Add all consumer instances obtained in S18 to the third dictionary, and use the name of the consumer instance as an index value to obtain the third dictionary.

[0084] S20: When the first annotation is message sending unit information, a corresponding message sending unit is selected from a producer set according to the message sending unit information, and the message in the method object is sent to a corresponding message queue through the message sending unit.

[0085] Further, in some embodiments of the present application, selecting a corresponding producer from a producer set according to the message sending unit information included in the first annotation includes:

[0086] The message sending unit information includes: the name of the message sending unit;

[0087] According to the name of the message sending unit, determining whether there is a corresponding message sending unit in the second dictionary;

[0088] If the corresponding message sending unit exists in the second dictionary, the corresponding message sending unit is returned; otherwise, it is determined whether the corresponding message sending unit exists in the first dictionary;

[0089] If the corresponding message sending unit exists in the first dictionary, the corresponding message sending unit is returned; otherwise, the preset message sending unit is returned.

[0090] Firstly, the second dictionary with a double-layer structure is combined with two index values ​​for dynamic routing, which effectively improves the routing efficiency of the message sending unit. In addition, in the entire routing process, two dictionaries are used for dynamic routing to ensure that available message sending units can be selected, thereby improving the reliability of subsequent message sending.

[0091] S30: When the first annotation is message receiving unit information, the corresponding method object is added to the consumer collection, and according to the message receiving unit information included in the first annotation, the method object is used as a message receiving unit to process the message of the corresponding message queue.

[0092] Further, in some embodiments of the present application, according to the message receiving unit information included in the second annotation, using the method object as a message receiving unit to process the message of the corresponding message queue includes:

[0093] The message receiving unit information includes: the monitoring queue name and the message tag;

[0094] The message receiving unit is used to subscribe to messages of the message queue corresponding to the monitoring queue name, and the message receiving unit is used to process messages corresponding to the message tag.

[0095] The annotation includes the name of the queue to be monitored and the message to be processed. Combined with aspect programming technology, messages can be processed flexibly, while the business code is decoupled from the message queue call logic to achieve zero-intrusive integration.

[0096] Preferably, in some embodiments of the present application, the first annotation can be defined by the following preferred embodiments: by defining different first annotations to respectively identify the producer and the consumer, and adding necessary parameter configurations in the first annotation, such as: message queue name and message tag, etc., a specific example is: when the first annotation is @MQChoose(value={"MQ1","MQ2"}), the producer is marked by the above first annotation, and the message of the producer will be sent to the message queues named "MQ1" and "MQ2"; when the first annotation is @MQMultipleListener(value="MQ",tag={"order1","order2"}), the consumer is marked by the above first annotation, and the consumer listens to the queue named "MQ" and only processes messages tagged "order1" and "order2".

[0097] Preferably, the method for sending and receiving a dynamic routing message queue provided in the embodiment of the present application can be packaged into an SDK (Software Development Kit) for flexible deployment, referring to Figure 2 , is a schematic diagram of a solution deployment process corresponding to a state routing message queue sending and receiving method provided in an embodiment of the present application, which includes:

[0098] S41: The developer integrates the SDK provided in this embodiment into the project, and adds the SDK dependency to the project's build configuration file, such as Maven's pom.xml file;

[0099] S42: The developer configures the relevant parameters of the SDK according to the specific requirements of the project and generates the corresponding configuration file, which needs to include the relevant configurations mentioned in S11;

[0100] S43: After the project is started, the SDK is loaded. This can be done by using the @PostConstruct annotation of Spring to ensure that the SDK is initialized immediately after the project is started.

[0101] S44: Read configuration information through SDK;

[0102] S45: During the initialization process, the SDK creates a producer instance and a consumer instance according to the read configuration information, and loads the producer instance and the consumer instance into the corresponding collection;

[0103] S46: passing the created producer instance into the constructor of the dynamic routing producer routing class to complete the secondary encapsulation of the dynamic routing of the producer instance;

[0104] S47: The developer creates a producer service class and a consumer service class for sending and receiving messages. The above service classes will inherit or implement the interface or abstract class provided by the SDK to achieve data interaction with the SDK;

[0105] S48: The SDK implements the initialization of the aspect class internally. A special method is defined in the aspect class to intercept the message sending operation. The above method will automatically select the appropriate producer instance according to the parameters in the first annotation identified, and will also intercept the method of the first annotation with the message receiving unit information to ensure the correct reception and processing of the message;

[0106] S49: During the project startup phase, the SDK monitors the initialization process of the Bean in real time to identify the class that implements the listener interface and is annotated with MQMultipleListener, that is, the first annotation that identifies the consumer, and adds the class as a consumer to the consumer collection.

[0107] In summary, a dynamic routing message queue sending and receiving method provided in an embodiment of the present application has the following beneficial effects: through aspect-oriented programming technology, the calling logic of the message queue is decoupled from the business code, and zero-intrusive code integration is achieved, thereby reducing the coupling degree of the system; in addition, through aspect-oriented programming technology, producers and consumers are dynamically managed separately without modifying the code, which not only improves the flexibility of the expansion system, but also reduces the coupling degree of the message sender and receiver to realize the reception and sending of messages.

[0108] Embodiment 2

[0109] refer to Figure 3 , a dynamic routing message queue sending and receiving device provided in an embodiment of the present application, includes: an interception module 11, a message sending module 12 and a message processing module 13.

[0110] Furthermore, in some embodiments of the present application, the interception module 11 is used to intercept a method object containing a first annotation through an aspect class; wherein the first annotation includes message sending unit information or message receiving unit information; the message sending module 12 is used to select a corresponding message sending unit from a producer set according to the message sending unit information when the first annotation is message sending unit information, and send the message corresponding to the method object to a corresponding message queue through the message sending unit; the message processing module 13 is used to add the corresponding method object to a consumer set when the first annotation is message receiving unit information, and use the method object as a message receiving unit to process the message of the corresponding message queue according to the message receiving unit information contained in the first annotation.

[0111] Furthermore, in some embodiments of the present application, before intercepting the method object containing the first annotation through the aspect class, it also includes: reading preset configuration information, and constructing a plurality of message sending units and a plurality of message receiving units according to the configuration information; performing dynamic routing encapsulation on all the message sending units to obtain a producer set with a dual dictionary structure; performing dynamic routing encapsulation on all the message receiving units to obtain a consumer set with a single dictionary structure.

[0112] Furthermore, in some embodiments of the present application, the dynamic routing encapsulation of all the message sending units to obtain a producer set with a dual dictionary structure includes: the producer set includes: a first dictionary and a second dictionary; the name of each message sending unit is used as an index value to construct a first dictionary with a single-layer structure; according to the name of the message sending unit, the message sending units are grouped, and the group name is used as the index value of the first layer of the second dictionary, and the name of the message sending unit is used as the index value of the second layer of the second dictionary to construct a second dictionary with a double-layer structure.

[0113] Further, in some embodiments of the present application, selecting a corresponding message sending unit from a producer set according to the message sending unit information includes: the message sending unit information includes: the name of the message sending unit; judging whether a corresponding message sending unit exists in the second dictionary according to the name of the message sending unit; if a corresponding message sending unit exists in the second dictionary, returning the corresponding message sending unit; otherwise judging whether a corresponding message sending unit exists in the first dictionary; if a corresponding message sending unit exists in the first dictionary, returning the corresponding message sending unit; otherwise returning a preset message sending unit.

[0114] Further, in some embodiments of the present application, according to the message receiving unit information contained in the second annotation, the method object is used as a message receiving unit to process the messages of the corresponding message queue, including: the message receiving unit information includes: a listening queue name and a message tag; subscribing to the messages of the message queue corresponding to the listening queue name through the message receiving unit, and enabling the message receiving unit to process the messages corresponding to the message tag.

[0115] It can be understood that the above-mentioned device item embodiment corresponds to the method item embodiment of the present invention. A dynamic routing message queue sending and receiving device provided by the embodiment of the present invention can implement any method item embodiment of the present invention, that is, the dynamic routing message queue sending and receiving method provided in embodiment one.

[0116] Embodiment 3

[0117] Based on the above-mentioned embodiment of the dynamic routing message queue sending and receiving method, another embodiment of the present application provides a dynamic routing message queue sending and receiving terminal device, which includes a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, the dynamic routing message queue sending and receiving method of any embodiment of the present application is implemented.

[0118] Exemplarily, in this embodiment, the computer program may be divided into one or more modules, which are stored in the memory and executed by the processor to complete the present application. The one or more modules may be a series of computer program instruction segments capable of completing specific functions, which are used to describe the execution process of the computer program in the dynamic routing message queue transceiver device.

[0119] The dynamic routing message queue transceiver device may be a computing device such as a desktop computer, a notebook, a palm computer, a cloud server, etc. The dynamic routing message queue transceiver terminal device may include, but is not limited to, a processor and a memory.

[0120] The processor may be a central processing unit (CPU), or other general-purpose processors, 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, etc. The general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc. The processor is the control center of the dynamic routing message queue transceiver device, and uses various interfaces and lines to connect the various parts of the entire dynamic routing message queue transceiver device. The memory may be used to store the computer program and / or module, and the processor implements various functions of the dynamic routing message queue transceiver device by running or executing the computer program and / or module stored in the memory, and calling the data stored in the memory. The memory may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function, etc.; the data storage area may store data created according to the use of the mobile phone, etc. In addition, the memory may include high-speed random access memory and may also include non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.

[0121] Embodiment 4

[0122] Based on the above-mentioned embodiment of the dynamic routing message queue sending and receiving method, another embodiment of the present application provides a storage medium, wherein the storage medium includes a stored computer program, wherein when the computer program is running, the device where the storage medium is located is controlled to execute the dynamic routing message queue sending and receiving method of any embodiment of the present application.

[0123] In this embodiment, the storage medium is a computer-readable storage medium, and the computer program includes computer program code, which may be in source code form, object code form, executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium may be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.

[0124] The specific embodiments described above further describe the purpose, technical solutions and beneficial effects of the present application in detail. It should be understood that the above description is only a specific embodiment of the present application and is not intended to limit the scope of protection of the present application. It is particularly pointed out that for those skilled in the art, any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of protection of the present application.

Claims

1. A dynamic routing message queue sending and receiving method, characterized in that: include: Intercepting a method object containing a first annotation through a section class; wherein the first annotation includes message sending unit information or message receiving unit information; When the first annotation is message sending unit information, according to the message sending unit information, a corresponding message sending unit is selected from the producer set, and the message in the corresponding method object is sent to the corresponding message queue through the message sending unit; When the first annotation is message receiving unit information, the corresponding method object is added to the consumer collection, and according to the message receiving unit information included in the first annotation, the method object is used as a message receiving unit to process the message of the corresponding message queue.

2. A dynamic routing message queue sending and receiving method as claimed in claim 1, characterized in that: Before intercepting the method object containing the first annotation through the aspect class, it also includes: Reading preset configuration information, and constructing a plurality of message sending units and a plurality of message receiving units according to the configuration information; Performing dynamic routing encapsulation on all the message sending units to obtain a producer set of a dual dictionary structure; Dynamic routing encapsulation is performed on all the message receiving units to obtain a consumer set in a single dictionary structure.

3. A dynamic routing message queue sending and receiving method as claimed in claim 2, characterized in that: The step of performing dynamic routing encapsulation on all the message sending units to obtain a producer set of a dual dictionary structure includes: The producer set includes: a first dictionary and a second dictionary; Using the name of each message sending unit as an index value, constructing a first dictionary with a single-layer structure; The message sending units are grouped according to their names, and the group names are used as index values ​​of the first layer of the second dictionary, and the names of the message sending units are used as index values ​​of the second layer of the second dictionary to construct a double-layer second dictionary.

4. A dynamic routing message queue sending and receiving method as claimed in claim 3, characterized in that: The selecting a corresponding producer from a producer set according to the message sending unit information included in the first annotation includes: The message sending unit information includes: the name of the message sending unit; According to the name of the message sending unit, determining whether there is a corresponding message sending unit in the second dictionary; If the corresponding message sending unit exists in the second dictionary, the corresponding message sending unit is returned; otherwise, it is determined whether the corresponding message sending unit exists in the first dictionary; If the corresponding message sending unit exists in the first dictionary, the corresponding message sending unit is returned; otherwise, the preset message sending unit is returned.

5. A dynamic routing message queue sending and receiving method as claimed in claim 1, characterized in that: The method object is used as a message receiving unit according to the message receiving unit information included in the second annotation to process the message of the corresponding message queue, including: The message receiving unit information includes: the monitoring queue name and the message tag; The message receiving unit is used to subscribe to messages of the message queue corresponding to the monitoring queue name, and the message receiving unit is used to process messages corresponding to the message tag.

6. A dynamic routing message queue transceiver, characterized in that: include: Interception module, message sending module and message processing module; The interception module is used to intercept a method object containing a first annotation through a section class; wherein the first annotation includes message sending unit information or message receiving unit information; The message sending module is used for selecting a corresponding message sending unit from a producer set according to the message sending unit information when the first annotation is message sending unit information, and sending the message corresponding to the method object to a corresponding message queue through the message sending unit; The message processing module is used to add the corresponding method object to the consumer collection when the first annotation is message receiving unit information, and use the method object as a message receiving unit to process messages of the corresponding message queue according to the message receiving unit information contained in the first annotation.

7. A dynamic routing message queue transceiver as claimed in claim 6, characterized in that: Before intercepting the method object containing the first annotation through the aspect class, it also includes: Reading preset configuration information, and constructing a plurality of message sending units and a plurality of message receiving units according to the configuration information; Performing dynamic routing encapsulation on all the message sending units to obtain a producer set of a dual dictionary structure; Dynamic routing encapsulation is performed on all the message receiving units to obtain a consumer set in a single dictionary structure.

8. A dynamic routing message queue transceiver as claimed in claim 7, characterized in that: The step of performing dynamic routing encapsulation on all the message sending units to obtain a producer set of a dual dictionary structure includes: The producer set includes: a first dictionary and a second dictionary; Using the name of each message sending unit as an index value, constructing a first dictionary with a single-layer structure; The message sending units are grouped according to their names, and the group names are used as index values ​​of the first layer of the second dictionary, and the names of the message sending units are used as index values ​​of the second layer of the second dictionary to construct a double-layer second dictionary.

9. A dynamic routing message queue transceiver as claimed in claim 8, characterized in that: The selecting a corresponding message sending unit from a producer set according to the message sending unit information includes: The message sending unit information includes: the name of the message sending unit; According to the name of the message sending unit, determining whether there is a corresponding message sending unit in the second dictionary; If the corresponding message sending unit exists in the second dictionary, the corresponding message sending unit is returned; otherwise, it is determined whether the corresponding message sending unit exists in the first dictionary; If the corresponding message sending unit exists in the first dictionary, the corresponding message sending unit is returned; otherwise, the preset message sending unit is returned.

10. A dynamic routing message queue transceiver as claimed in claim 1, characterized in that: The method object is used as a message receiving unit according to the message receiving unit information included in the second annotation to process the message of the corresponding message queue, including: The message receiving unit information includes: the monitoring queue name and the message tag; The message receiving unit is used to subscribe to messages of the message queue corresponding to the monitoring queue name, and the message receiving unit is used to process messages corresponding to the message tag.

Citation Information

Patent Citations

  • Security auditing method based on aspect oriented programming (AOP) and annotation information system

    CN103559118A

  • Message queue configuration method and device, computer device and storage medium

    CN110032459A

  • Step-by-step anomaly detection method based on dictionary representation

    CN111027594A

  • Dynamic queue forwarding method and system based on RabbitMQ and ActiveMQ and storage medium

    CN111770029A

  • Dictionary agent section method for corrugated paper packaging industry and related equipment

    CN115563125A