A message processing method, apparatus and device

By creating method-level listeners for each method in the message consumer class and setting configuration parameters and priorities, the coupling and complexity issues in message processing are resolved, enabling efficient business processing.

CN116800624BActive Publication Date: 2026-04-07CHINA MOBILE (SUZHOU) SOFTWARE TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-24
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

In existing technologies, message processing is highly coupled and complex, resulting in low business processing efficiency, especially when multiple consumers consume messages simultaneously, making it difficult to guarantee speed and efficiency.

Method used

By creating method-level listeners for each method of the message consumer class, setting method-level listener configuration parameters and their priorities, method-level message listeners are established to independently handle different messages.

Benefits of technology

It reduces the coupling and complexity of message processing, improves the efficiency of business processing, and enables each business processing method to independently and accurately match and process messages.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116800624B_ABST
    Figure CN116800624B_ABST
Patent Text Reader

Abstract

This application discloses a message processing method, apparatus, and device. The method includes: obtaining at least one method corresponding to a message consumer class, and method-level listener configuration parameters and configuration parameter priorities for each method; creating method-level message listeners for each method based on the method-level message listener configuration parameters and configuration parameter priorities; and processing different messages sent by a message producer through the corresponding method-level message listeners. Thus, by establishing method-level message listeners for each business processing method according to the method-level message listener configuration parameters and configuration parameter priorities, each business processing method can independently complete message processing, achieving accurate matching and logical uniqueness between message and business processing method processing, thereby reducing the coupling and complexity of message processing and improving the efficiency of business processing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, and in particular to a message processing method, apparatus, and device. Background Technology

[0002] Message queue middleware has been widely adopted due to its low latency, high concurrency, and high reliability. Message queue-based middleware includes message producers and message consumers. It can listen for and receive messages (topics, tags, etc.) generated by message producers and send them to message consumers for consumption. For example, a cloud computing product ordering system can use message middleware to obtain various messages about different cloud computing products from the resource module (message producer), while business processing modules such as the order module and billing module (message consumers) retrieve different messages from the message queue middleware to perform corresponding business processing.

[0003] In related technologies, consumer terminals monitor messages produced by producers by adding message listeners (i.e., class listeners) to consumer classes. This method falls into two categories: one is where a consumer class receives a tag under a topic and performs unique logical processing on that tag, meaning each consumer class has only one business processing method. The number of consumer classes increases with the number of business processing methods, making it difficult to guarantee processing speed when multiple consumers consume messages simultaneously. The other is where a consumer class includes multiple processing methods corresponding to different business needs. A single consumer class receives different tags under the same topic, iterates through the tags to determine their types, and then performs different logical processing based on the business needs corresponding to each tag message. This increases message processing coupling and complexity, reducing processing efficiency. Summary of the Invention

[0004] To address the aforementioned technical problems, this application aims to provide a message processing method that can reduce the coupling and complexity of message processing and improve the efficiency of business processing.

[0005] The technical solution of the application embodiment is implemented as follows:

[0006] This application provides a message processing method, including:

[0007] Get at least one method corresponding to the message consumer class, and get the method-level listener configuration parameters and configuration parameter priority corresponding to each of the at least one method;

[0008] Based on the method-level listener configuration parameters and configuration parameter priority corresponding to each of the at least one method, create a method-level message listener corresponding to each of the at least one method;

[0009] The different messages sent by the message producer are processed by the method-level message listener corresponding to each of the at least one method.

[0010] This application provides a message processing apparatus, including:

[0011] The acquisition module is used to acquire at least one method corresponding to the message consumer class, and to acquire the method-level listener configuration parameters and configuration parameter priorities corresponding to each of the at least one method;

[0012] A module is created to create a method-level message listener for each of the at least one method, based on the method-level listener configuration parameters and configuration parameter priorities corresponding to each of the at least one method.

[0013] The processing module is used to process different messages sent by the message producer through the method-level message listener corresponding to each of the at least one method.

[0014] This application provides a message processing device, including:

[0015] Memory, used to store executable message processing instructions;

[0016] The processor, when executing executable message processing instructions stored in the memory, implements the message processing method provided in the embodiments of this application.

[0017] This application provides a computer-readable storage medium storing computer-executable message processing instructions configured to execute the message processing method provided in this application.

[0018] This application provides a message processing method, apparatus, device, and computer-readable storage medium. Using this technical solution, firstly, at least one method corresponding to a message consumer class, as well as the method-level listener configuration parameters and priority of each method, are obtained. Then, based on the method-level message listener configuration parameters and priority of each method, method-level message listeners are created for each method. Finally, different messages sent by the message producer are processed through the corresponding method-level message listeners. In this way, by establishing method-level message listeners for each business processing method according to the method-level message listener configuration parameters and priority, each business processing method can independently complete message processing, achieving accurate matching and logical uniqueness between message and business processing method processing, thereby reducing the coupling and complexity of message processing and improving the efficiency of business processing. Attached Figure Description

[0019] Figure 1A schematic diagram of a technical solution model for message processing of a listener-like device provided in an embodiment of this application;

[0020] Figure 2 A schematic flowchart of a message processing method provided for an embodiment of the application;

[0021] Figure 3 A flowchart illustrating a method for determining the configuration parameters of a target listener, as provided in an embodiment of this application.

[0022] Figure 4 This application provides a schematic diagram of a message processing method based on a method-level message listener using RocketMQ, as illustrated in an embodiment of the present application.

[0023] Figure 5 A flowchart illustrating a message processing method based on a method-level message listener using RocketMQ, provided in this embodiment of the application;

[0024] Figure 6 This is a schematic diagram of a technical solution model for message processing in a method-level message listener provided in an embodiment of this application.

[0025] Figure 7 This is a schematic diagram of the composition structure of a message processing device provided in an embodiment of this application;

[0026] Figure 8 This is a schematic diagram of the composition structure of a message processing device provided in an embodiment of this application. Detailed Implementation

[0027] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings.

[0028] To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limitations on this application. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0029] In the following description, references to “some embodiments” or “other embodiments” describe a subset of all possible embodiments. However, it is understood that “some embodiments” or “other embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.

[0030] In the following description, the terms "first, second, third" are used merely to distinguish similar objects and do not represent a specific ordering of objects. It is understood that "first, second, third" may be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.

[0031] Unless otherwise defined, all technical and scientific terms used in this application have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains. The terminology used in this application is for the purpose of describing embodiments of this application only and is not intended to be limiting of this application.

[0032] With the continuous development of cloud computing, fully utilizing the autoscaling capabilities provided by the cloud environment and achieving loose coupling with specific cloud providers has become a challenge, giving rise to the concept of "cloud native." Cloud native applications can fully leverage the various advantages brought by the cloud computing model, and microservices are an important and popular implementation form.

[0033] Most current public and private cloud services employ small, focused, and autonomous microservices that can work collaboratively. These microservice modules have clearly defined service boundaries, meaning that the cost of communication between them is increasing. The demands and processing logic of microservices in cloud services are becoming increasingly complex, leading to higher requirements for low coupling, low complexity, high performance, low latency, high fault tolerance, high availability, high scalability, high reliability, and maintainability. Traditional synchronous calls are clearly insufficient to meet the complex and ever-changing environment of microservices. Therefore, asynchronous message-driven distributed message middleware like RocketMQ has emerged, transforming communication between different microservice modules into message production-listening-receiving-consumption, with loose coupling between message producers and consumers.

[0034] RocketMQ, a message queue platform, supports a publish-subscribe model. Producer applications create topics and send messages to them. Consumer applications subscribe to topics to receive messages. A message consumer, also known as a message subscriber, is responsible for receiving and consuming messages. A necessary condition for a consumer to consume messages is that it must receive messages, meaning it can receive messages produced by the subscribed producer.

[0035] Consumers listen to messages produced by producers by registering message listeners. In the technical implementation of Rocket MQ, in order for consumers to listen to messages produced by producers, message listeners are added to the class. Consumer instances must meet the following two conditions: (1) The consumer class must have a consumer listener annotation, where @RocketMQMessageListener is applied to the class; (2) The consumer class must implement the RocketMQListener interface, i.e., implements RocketMQListener.

[0036] In related technologies, consumers listen for messages using class listeners, specifically the natively supported class listener annotation @RocketMQ Message Listener, which operates on the class, meaning its scope is the class. Messages are listened for, filtered, and received by setting the server (NameServer), topic, and tag. The specific solution model is as follows: Figure 1 As shown.

[0037] Depend on Figure 1 As can be seen, one approach to class listeners is for each consumer class to implement an interface class, listening to messages of a single tag type under a single topic, and then performing precise and unique logical processing. In reality, a single consumer class may contain many business processing methods, implementing different business logic. This approach has certain drawbacks. To process messages, a consumer class can only have one business processing method. As the number of business processing methods increases, the number of consumer classes will also increase. Furthermore, because consumer groups are globally unique, the number of consumer groups will also increase, which invisibly increases the complexity of consumer instances. When multiple consumer groups or consumers consume messages simultaneously, it will slow down the business processing speed.

[0038] Another approach involves a consumer class receiving messages with different tags under the same topic, determining the tag type through a loop, and then performing logical processing based on the different business scenarios corresponding to the messages. This approach significantly increases code complexity, coupling, and reduces code extensibility and adaptability, making it difficult to guarantee the efficiency of business processing and also inconvenient for maintenance and management between different business processes.

[0039] In view of the above-mentioned problems in related technologies, this application provides a message processing method that can reduce the coupling and complexity of message processing and improve the efficiency of business processing.

[0040] The message middleware can be Kafka, RabbitMQ, RocketMQ, etc. The following uses RocketMQ as an example to illustrate the message processing method provided in this application's embodiments. Figure 2 The diagram shown is a flowchart of a message processing method provided in an embodiment of this application. The method includes the following steps:

[0041] S101. Obtain at least one method corresponding to the message consumer class, and obtain the method-level listener configuration parameters and configuration parameter priority corresponding to each of the at least one method.

[0042] It's important to note that message consumers are a crucial component of the RocketMQ message middleware. A message consumer class can be a method class corresponding to a message consumer. This class can be defined by the developer and can receive different messages, processing them through its corresponding methods. A message consumer class can define one or more methods, each performing different processing on the message. For example, in an e-commerce system, the message consumer class can retrieve product information (messages), such as product category and price. The corresponding methods could be, for instance, generating the quantity of a product based on its category, or generating a consumption order based on its price.

[0043] In some embodiments, the method-level listener configuration parameters corresponding to each method include at least one. The method-level listener configuration parameters may include parameters such as Name Server, Topic, Tag, Consumer Group, Consume Mode, Message Model, Maximum Consume Thread Max, and Maximum Consume Timeout. The method-level listener configuration parameters are applied to the method. By setting the method-level listener configuration parameters, the quantity, type, and content of messages required by different methods can be determined.

[0044] In some embodiments, the number of method-level listener configuration parameters corresponding to different methods may be different or the same. When the number and type of method-level message listener configuration parameters corresponding to multiple methods are the same, the setting values ​​of the method-level message listener configuration parameters corresponding to multiple methods may be the same or different. When the setting values ​​of the method-level listener configuration parameters corresponding to multiple methods are all the same, the messages received by the multiple methods are also the same, but the message processing logic may be different.

[0045] In some embodiments, the priority of configuration parameters can be preset, for example, it can be set by the developers. The priority of configuration parameters can be the priority corresponding to different levels of configuration parameters. For example, when the level of configuration parameters includes global level, class level and method level, the priority of configuration parameters can be that method level configuration parameters are greater than class level configuration parameters, and class level configuration parameters are greater than global level configuration parameters.

[0046] S102. Based on the method-level listener configuration parameters and configuration parameter priority corresponding to at least one method, create at least one method-level message listener corresponding to each method.

[0047] It should be noted that method-level message listeners are used to listen for and receive messages produced by the producer. In practice, the method-level message listener annotation @RocketMQ Method Message Listener can be defined and applied to different methods in the consumer class. The method-level listener annotation acts on the method, and by setting the listener configuration parameters in the method-level listener annotation, the method-level message listener can listen for and receive messages.

[0048] In some embodiments, after obtaining the method-level listener configuration parameters and configuration parameter priorities corresponding to each method, a method-level message listener corresponding to each method can be created based on the method-level listener configuration parameters and configuration parameter priorities.

[0049] S103. Process different messages sent by the message producer through at least one method-level message listener corresponding to each method.

[0050] In some embodiments, since the configuration parameters of the method-level listeners corresponding to different methods may be different, the messages received by the method-level message listeners corresponding to different methods may also be different. In some embodiments, the processing of messages sent by the producer may include filtering and classification.

[0051] For example, method-level message listeners A and B have identical configuration parameters except for their respective themes. Both listeners correspond to the theme "electronic products," but listener A's theme is "mobile phones," while listener B's theme is "computers." When listener A receives various electronic products from the producer, it filters out all electronic products except mobile phones and categorizes the received mobile phones. Similarly, when listener B receives various electronic products from the producer, it filters out all electronic products except mobile phones and categorizes the received mobile phones.

[0052] In the message processing method provided in this application embodiment, firstly, at least one method corresponding to the message consumer class, as well as the method-level listener configuration parameters and configuration parameter priorities corresponding to each method, are obtained; then, method-level message listeners corresponding to each method are created based on the method-level message listener configuration parameters and configuration parameter priorities corresponding to each method; finally, different messages sent by the message producer are processed through the corresponding method-level message listeners. In this way, by establishing method-level message listeners corresponding to each business processing method according to the method-level message listener configuration parameters and configuration parameter priorities, each business processing method can independently complete message processing, achieving accurate matching and logical uniqueness between message and business processing method processing, thereby reducing the coupling and complexity of message processing and improving the efficiency of business processing.

[0053] In some embodiments of this application, at least one method-level message listener is created based on the method-level listener configuration parameters and configuration parameter priorities corresponding to each method. That is, step S102 can also be implemented by the following steps S1201 to S1203. Each step is described in detail below.

[0054] S1201. Based on the priority of configuration parameters, obtain the class-level listener configuration parameters and global configuration parameters corresponding to the message consumer class.

[0055] In some embodiments, after obtaining the method-level listener configuration parameters, the class-level listener configuration parameters and global configuration parameters corresponding to the message consumer class can be obtained according to the priority of the configuration parameters. In practice, if the priority of the configuration parameters is class-level greater than global-level, then when obtaining the class-level listener configuration parameters and global configuration parameters corresponding to the consumer class, the class-level listener configuration parameters can be obtained first, and the global configuration parameters can be obtained only if the class-level listener configuration parameters do not meet the requirements.

[0056] S1202. Based on the method-level listener configuration parameters, class-level listener configuration parameters, and global configuration parameters corresponding to at least one method, determine the target listener configuration parameters corresponding to at least one method.

[0057] In some embodiments, after obtaining the method-level listener configuration parameters, class-level listener configuration parameters, and global configuration parameters corresponding to each method, the target listener configuration parameters for each method can be determined based on these parameters. In practice, the target listener configuration parameters may include at least one of the method-level, class-level, and global configuration parameters, or a combination of these parameters. For example, if there are five target listener configuration parameters, three may be method-level listener configuration parameters, and the other two may be class-level listener configuration parameters. This is merely an illustrative example, and the embodiments of this application do not limit the combination of target listener configuration parameters.

[0058] S1203. Based on the target listener configuration parameters corresponding to at least one method, create at least one method-level message listener corresponding to each method.

[0059] In some embodiments, after obtaining the target listener configuration parameters corresponding to each method, the method-level message listener corresponding to each method can be determined based on the target listener configuration parameters. Based on the target listener configuration parameters, the type and content of messages that can be obtained by each method can be determined. The method-level message listener created based on the target listener configuration parameters can listen to and receive the messages required by each method.

[0060] like Figure 3 The diagram shows a flowchart of a method for determining target listener configuration parameters according to an embodiment of this application. In some embodiments of this application, the configuration parameters are prioritized from high to low as method-level listener configuration parameters, class-level listener configuration parameters, and global configuration parameters. Based on this, the target listener configuration parameters corresponding to at least one method are determined based on the method-level listener configuration parameters, class-level listener configuration parameters, and global configuration parameters corresponding to each method. That is, step S1202 can also be implemented by the following steps S201 to S215. Each step is described in detail below.

[0061] S201. Obtain the target configuration parameters corresponding to the method-level listener configuration parameters of the i-th method in the message consumer class.

[0062] It should be noted that the target configuration parameters can be set by the developers. The target configuration parameters can be determined based on the function performed by the method. For example, if the function performed by the method is to generate order information for the user's purchased goods, the corresponding target configuration parameters may include information such as the quantity and price of the goods purchased by the user.

[0063] In some embodiments, a method-level listener configuration parameter may include one or more. When there are multiple method-level listener configuration parameters, when obtaining the method-level listener configuration parameters of a method, it is necessary to obtain the target configuration parameter corresponding to each method-level listener configuration parameter of that method. In some embodiments, if the message consumer class includes N methods, where N is a positive integer greater than or equal to 1, the target configuration parameter corresponding to each listener configuration parameter of the i-th (i = 1, 2, ..., N) method in the message consumer class can be obtained.

[0064] S202. Determine whether the configuration parameters of each method-level listener in the i-th method and their corresponding target configuration parameters all meet the consistency condition.

[0065] In some embodiments, the consistency condition can be that the method-level listener configuration parameters are the same as the corresponding target configuration parameters. For example, if the method-level listener configuration parameters of the i-th method include three parameters: Name Server, Topic, and Tag, with the topic being toiletries and the tag being towels; and the target configuration parameters also include three parameters: Name Server, Topic, and Tag, and the parameter settings corresponding to the Name Server, Topic, and Tag are consistent with the settings in the method-level listener configuration parameters, then it can be determined that each method-level listener configuration parameter of the i-th method and its corresponding target configuration parameter satisfy the consistency condition.

[0066] In some embodiments, if the configuration parameters of each method-level listener of the i-th method and their respective target configuration parameters meet the consistency condition, then proceed to step S203; otherwise, proceed to step S204.

[0067] S203. Determine the method listener configuration parameters corresponding to the i-th method as the target listener configuration parameters.

[0068] In some embodiments, if it is determined that each method-level listener configuration parameter of the i-th method satisfies the consistency condition with its corresponding target configuration parameter, then the method listener configuration parameter corresponding to the i-th method can be determined as the target listener configuration parameter.

[0069] S204. Determine that among the method-level listener configuration parameters corresponding to the i-th method, there is a first configuration parameter that satisfies the consistency condition with the corresponding target configuration parameter, and there are other configuration parameters that do not satisfy the consistency condition with the corresponding target configuration parameter, and obtain the class-level listener configuration parameters.

[0070] In some embodiments, if each method-level listener configuration parameter of the i-th method does not necessarily satisfy the consistency condition with its corresponding target configuration parameter, and it is determined that there is a first configuration parameter in the method-level listener configuration parameters corresponding to the i-th method that satisfies the consistency condition with the corresponding target configuration parameter, and there are also other configuration parameters that do not satisfy the consistency condition with the corresponding target configuration parameter, that is, some configuration parameters in the method-level listener configuration parameters corresponding to the i-th method are the same as the corresponding target configuration parameter, and some configuration parameters are the same as the corresponding target configuration parameter, it indicates that the target listener configuration parameter corresponding to the i-th method cannot be directly determined based solely on each method-level listener configuration parameter of the i-th method. In this case, the class-level listener configuration parameters can be further obtained.

[0071] S205. Determine whether the configuration parameters of the class-level listener and the configuration parameters of the first other target meet the consistency condition.

[0072] It should be noted that the first other target configuration parameter can be the target configuration parameter corresponding to the method-level listener configuration parameter of the i-th method, excluding the configuration parameter that satisfies the consistency condition with the first configuration parameter.

[0073] In some embodiments, after obtaining the class-level listener configuration parameters, if it is determined that the class-level listener configuration parameters and the first other target configuration parameters meet the consistency condition, and it is determined that there is a second configuration parameter in the class-level listener configuration parameters that meets the consistency condition with the first other target configuration parameters, then step S206 can be entered; otherwise, step S211 can be entered.

[0074] S206. Determine whether the sum of the number of the second configuration parameters and the number of the first configuration parameters is equal to the number of method-level listener configuration parameters corresponding to the i-th method.

[0075] In some embodiments, if the sum of the number of second configuration parameters and the number of first configuration parameters is equal to the number of method-level listener configuration parameters corresponding to the i-th method, step S207 can be executed; otherwise, if the sum of the number of second configuration parameters and the number of first configuration parameters is not equal to the number of method-level listener configuration parameters corresponding to the i-th method, and the sum of the number of second configuration parameters and the number of first configuration parameters is less than the number of method-level listener configuration parameters corresponding to the i-th method, then step S208 can be executed.

[0076] S207. The first configuration parameter and the second configuration parameter are determined as the target listener configuration parameters corresponding to the i-th method.

[0077] In some embodiments, the first configuration parameter may be the same as the corresponding target configuration parameter in the method-level listener configuration parameters corresponding to the i-th method, and the second configuration parameter may be the same as the corresponding first other target configuration parameter in the class-level listener configuration parameters corresponding to the i-th method. If the sum of the number of second configuration parameters and the number of first configuration parameters is equal to the number of method-level listener configuration parameters corresponding to the i-th method, it means that the target listener configuration parameter corresponding to the i-th method can be obtained by combining the method-level listener configuration parameters and the class-level listener configuration parameters. Therefore, the first configuration parameter and the second configuration parameter can be determined as the target listener configuration parameter corresponding to the i-th method.

[0078] S208, Get global configuration parameters.

[0079] In some embodiments, if the sum of the number of second configuration parameters and the number of first configuration parameters is less than the number of method-level listener configuration parameters corresponding to the i-th method, it means that even if the method-level listener configuration parameters and class-level listener configuration parameters are combined, the target listener configuration parameters corresponding to the i-th method cannot be obtained. In this case, global configuration parameters can be obtained to further determine whether there are configuration parameters in the global configuration parameters that meet the consistency condition with the corresponding target listener configuration parameters.

[0080] S209. Determine that there is a third configuration parameter in the global configuration parameters that satisfies the consistency condition with the other target configuration parameters. Then, determine whether the sum of the number of first configuration parameters, the number of second configuration parameters, and the number of third configuration parameters is equal to the number of method-level listener configuration parameters corresponding to the i-th method.

[0081] In some embodiments, the second other target configuration parameter is the target configuration parameter corresponding to the method-level listener configuration parameter of the i-th method, excluding the configuration parameters that satisfy the consistency condition with the first configuration parameter and the second configuration parameter. When it is determined that the sum of the number of the first configuration parameter, the number of the second configuration parameter, and the number of the third configuration parameter is equal to the number of method-level listener configuration parameters corresponding to the i-th method, step S210 can be executed; otherwise, step S215 is executed.

[0082] S210. The first configuration parameter, the second configuration parameter, and the third configuration parameter are determined as the target listener configuration parameters corresponding to the i-th method.

[0083] In some embodiments, when it is determined that the first configuration parameter, the second configuration parameter, and the third configuration parameter are all the same as the corresponding target configuration parameter, wherein the first configuration parameter, the second configuration parameter, and the third configuration parameter are all different from each other, and the sum of the number of the first configuration parameter, the number of the second configuration parameter, and the number of the third configuration parameter is equal to the number of method-level listener configuration parameters corresponding to the i-th method, it indicates that the target listener configuration parameter can be obtained by combining the first configuration parameter, the second configuration parameter, and the third configuration parameter. In this case, the first configuration parameter, the second configuration parameter, and the third configuration parameter can be determined as the target listener configuration parameter corresponding to the i-th method.

[0084] S211. Obtain global configuration parameters.

[0085] In some embodiments, when the class-level listener configuration parameters do not meet the consistency condition with the first other target configuration parameters, it indicates that there is no configuration parameter in the class-level listener configuration parameters that is the same as the first target configuration parameter. At this time, the global configuration parameters can be obtained to determine whether there is a configuration parameter in the global configuration parameters that is the same as the first other target configuration parameter.

[0086] S212. Determine whether the global configuration parameters and the first other target configuration parameters meet the consistency condition.

[0087] If it is determined that the global configuration parameters and the first other target configuration parameters meet the consistency condition, step S213 can be executed; otherwise, step S215 is executed.

[0088] S213. Determine that there is a third configuration parameter in the global configuration parameters that satisfies the consistency condition with the first other target configuration parameters, and determine whether the sum of the number of third configuration parameters and the number of first configuration parameters is equal to the number of method-level listener configuration parameters corresponding to the i-th method.

[0089] If it is determined that there is a third configuration parameter in the global configuration parameters that satisfies the consistency condition with the first other target configuration parameters, and the number of third configuration parameters and the number of first configuration parameters are equal to the number of method-level listener configuration parameters corresponding to the i-th method, then step S214 can be executed; otherwise, step S215 can be executed.

[0090] S214. Determine the first configuration parameter and the third configuration parameter as the target listener configuration parameters corresponding to the i-th method.

[0091] In some embodiments, the first configuration parameter is the same as the corresponding target configuration parameter, the third configuration parameter is the same as the corresponding first other target parameter, and the number of the third configuration parameters and the number of the first configuration parameters are equal to the number of method-level listener configuration parameters corresponding to the i-th method. This indicates that the target listener configuration parameters can be obtained by combining the first configuration parameters and the third configuration parameters. Therefore, the first configuration parameters and the third configuration parameters can be determined as the target listener configuration parameters corresponding to the i-th method.

[0092] S215. Update the target configuration parameters corresponding to the configuration parameters of each method-level listener in the i-th method to obtain the updated target configuration parameters.

[0093] In some embodiments, if the method-level listener configuration parameters, class-level listener configuration parameters, or global configuration parameters of the i-th method do not meet the consistency condition with the corresponding target listener configuration parameters; or if combining at least two types of configuration parameters among the method-level listener configuration parameters, class-level listener configuration parameters, and global configuration parameters of the i-th method fails to yield configuration parameters that meet the consistency condition with the target listener configuration parameters, then the target configuration parameters corresponding to each method-level listener configuration parameter of the i-th method can be updated to obtain the updated target configuration parameters.

[0094] S216. Determine that the configuration parameters of each method-level listener of the i-th method and their corresponding updated target configuration parameters meet the consistency condition, and determine the configuration parameters of the method-level listener corresponding to the i-th method as the target listener configuration parameters.

[0095] In some embodiments, when it is determined that each method-level listener configuration parameter of the i-th method and its corresponding updated target configuration parameter all satisfy the consistency condition, it can be said that each method-level listener configuration parameter of the i-th method and its corresponding updated target configuration parameter are the same. In this case, the method-level listener configuration parameter corresponding to the i-th method can be used as the target listener configuration parameter.

[0096] Understandably, by considering the configuration parameters of at least one method-level listener, class-level listener, and global configuration parameters corresponding to each method, as well as the priority of the configuration parameters, it is possible to obtain the target listener configuration parameters for at least one type of configuration parameter combination among the method-level listener configuration parameters, class-level listener configuration parameters, and global configuration parameters. Then, based on the target listener configuration parameters corresponding to each method, a method-level message listener can be created for each method, enabling each method to independently complete message listening and reception. This ensures accurate matching and logical uniqueness between messages and functional method processing, thereby improving the efficiency of business processing corresponding to each functional method.

[0097] In some embodiments of this application, after creating at least one method-level message listener corresponding to each method based on the method-level listener configuration parameters and configuration parameter priorities corresponding to at least one method (i.e., step S102), the following steps S301 to S303 can also be executed. Each step is described in detail below.

[0098] S301. Obtain the first message received by the method-level message listener corresponding to at least one method.

[0099] It should be noted that the first message can be a message produced by the message producer. The method-level message listeners corresponding to each method can listen to and receive the messages produced by the producer. In some embodiments, the first messages received by the method-level message listeners corresponding to different methods may be completely different, partially the same, or completely the same.

[0100] S302. The first message is preprocessed by at least one method-level message listener corresponding to each method to obtain the preprocessed first message corresponding to each method.

[0101] In one embodiment, preprocessing includes at least one of filtering and classifying the first message. When the method-level message listeners corresponding to different methods receive the first message, they can preprocess it. For example, when a method-level message listener receives a message with the subject "electronic products" and the tag set in the method-level listener's configuration parameters is "home appliances," the method-level message listener can filter or delete electronic products that do not belong to the category of home appliances in the received message and classify various types of home appliances.

[0102] S303. Perform logical processing on the preprocessed first message corresponding to at least one method to obtain the message processing result and send the message processing result.

[0103] In some embodiments, after preprocessing the first message, the preprocessed first message can be processed through the functional logic corresponding to each method to obtain the message processing result. For example, if the first message includes information on multiple goods purchased by the user, and if the functional logic corresponding to the method is to determine the total consumption amount, the total cost of each good can be determined based on the price information of the multiple goods purchased by the user, thus obtaining the message processing result.

[0104] In some embodiments, after obtaining the message processing result, the obtained result can be sent to the user terminal to provide feedback on the message processing result to the user.

[0105] In this embodiment, at least one method corresponding to the message consumer class is obtained, along with the method-level listener configuration parameters and priority of each method. Then, based on the method-level message listener configuration parameters and priority of each method, method-level message listeners are created for each method. Finally, different messages sent by the message producer are processed through the corresponding method-level message listeners. Thus, by establishing method-level message listeners for each business processing method according to the method-level message listener configuration parameters and priority, each business processing method can independently complete message processing, ensuring accurate matching and logical uniqueness between message and business processing method processing. This reduces the coupling and complexity of message processing and improves the efficiency of business processing.

[0106] The implementation process of the embodiments of this application in a practical application scenario will be described below.

[0107] In some embodiments, such as Figure 4 The diagram shown is a flowchart illustrating a message processing method based on a method-level message listener of RocketMQ, according to an embodiment of this application. The message processing method based on a method-level message listener of RocketMQ provided in this embodiment can be implemented through the following steps S401 to S404, each of which will be described in detail below.

[0108] S401. Obtain consumer global parameters (global configuration parameters), class-level message listener parameters (class-level listener configuration parameters), and method-level listener parameters (method-level listener configuration parameters), and obtain the priority of configuration parameters.

[0109] like Figure 5The diagram shows the message processing method flowchart of the RocketMQ method-level message listener provided in this application. In some embodiments, a method-level message listener annotation can be created before obtaining the global consumer parameters, class-level message listener parameters, and method-level listener parameters. In practice, developers can set a series of parameters for the method-level message listener annotation @RocketMQ Method Message Listener, including Name Server, Topic, Tag, Consumer Group, Consumption Mode, Message Model, Maximum Consumption Threads (Max), and Maximum Consumption Timeout. The listener annotation is used on the methods in the message consumer class, and necessary configuration parameters, such as the corresponding content for Name Server, Topic, and Tag, are set in the listener annotation. When the Java project starts, the method listener detector scans all methods annotated with listeners and submits them to the Spring lifecycle management, after which the global consumer parameters, class-level message listener parameters, and method-level listener parameters can be obtained.

[0110] In some embodiments, the priority of configuration parameters can be: method-level > class-level > global-level (the priority of configuration parameters from high to low is method-level listener configuration parameters, class-level listener configuration parameters, and global configuration parameters). The priority of configuration parameters can be preset and can be set by the developers. In some embodiments, such as Figure 6 As shown, a message consumer class corresponds to a class-level message listener annotation. A message consumer class may include multiple methods, such as... Figure 6 The consumer methods shown are 1 to M, where M is an integer greater than 1. Each method has a corresponding method-level listener annotation. When retrieving method-level listener parameters, the method-level listener parameters corresponding to each method in the message consumer class can be obtained. Furthermore, since method-level listener annotations are applied to methods in the message consumer class, the method-level listener parameters for each method may be different.

[0111] S402. Based on the consumer's global parameters, class-level message listener parameters, method-level listener parameters, and configuration parameter priorities, determine the consumer parameters corresponding to the method-level message listener (determine the target listener configuration parameters corresponding to at least one method).

[0112] In some embodiments, when the priority of configuration parameters is from high to low as: method level, class level, and global level, the high-priority configuration overrides the low-priority configuration. After obtaining the method-level listener configuration parameters, class-level message listener parameters, and global parameters corresponding to each method of the consumer, the consumer parameters corresponding to the method-level message listener of each method can be determined according to the configuration priority.

[0113] S403. Based on the consumer parameters corresponding to the method-level message listener, create a method-level message listener (based on the target listener configuration parameters corresponding to at least one method, create at least one method-level message listener corresponding to each method).

[0114] When creating a method-level message listener, the system first retrieves and checks whether the configuration parameters in the method-level listener meet the requirements of each consumer. If they do, the consumer's method message listener is created with that configuration. If the configuration parameters in the method-level listener do not meet the requirements, the system retrieves and checks whether a class-level listener exists and whether its parameters contain configuration parameters that the method-level listener does not meet the consumer's requirements. If it exists, the class-level listener's parameters are used to supplement the configuration, while other parameters remain based on the method-level listener's parameters. The consumer's method message listener is then created using the combined configuration. If a class-level message listener does not exist or its configuration parameters still do not meet the requirements, the system retrieves and checks whether a global consumer configuration exists. If it exists, its parameters are checked to see if they contain parameters that the method-level listener does not meet the consumer's requirements. If it exists, the global parameters are used to supplement the configuration, while other parameters remain based on the method-level listener's parameters. The consumer's method message listener is then created. If a global configuration does not exist or its global configuration parameters still do not meet the requirements, the consumer's method-level listener and consumer cannot be created. The parameters required by the consumer can be updated or corrected until a method-level listener that meets the consumer's needs is determined. The above process makes method-level listeners compatible with class-level listeners, allowing them to exist independently or together.

[0115] It is understood that in this embodiment of the application, the method-level message listener operates directly on the method, and each method can independently complete the listening and receiving of messages, achieving accurate matching between messages and functional method processing, and ensuring logical uniqueness. Through method-level listening, it is possible to listen for messages of different topics and tags in a single consumer class without performing loop judgments on different tags under the same topic. It directly and explicitly listens for messages of a certain tag type, processes unique logic, and avoids logical ambiguity, thereby reducing the coupling and complexity of message processing and facilitating later maintenance.

[0116] S404. Process messages produced by the producer through a method-level message listener.

[0117] In some embodiments, after creating the method-level message listener, a consumer for each method message listener is constructed according to the consumer parameters corresponding to the method-level message listener. The consumer is registered and started to realize message listening and receiving. The method-level message listener corresponding to each method listens to messages of different topics and tags produced by the producer, and filters and classifies the received messages (preprocessing the first message).

[0118] In other embodiments, after the method listener processes the messages produced by the producer, the corresponding method of the consumer performs logical processing of the messages to implement the different functions of each method. In some embodiments, consumers started according to the registration of the method listener are automatically stopped when the service stops.

[0119] It is understood that in the embodiments of this application, the scope of the listener based on the method level is the method. The consumer class can have multiple functional methods, each of which can belong to different consumer groups. The configuration of each method can be configured independently or belong to the same consumer group with the same configuration. The configuration can be very flexible and can reduce the number of consumer groups and the performance consumption of consumer instances, thereby improving the speed of message processing.

[0120] This application also provides a message processing apparatus. Figure 7 This is a schematic diagram of the composition structure of a message processing device provided in an embodiment of this application, as shown below. Figure 7 As shown, the message processing device 500 includes:

[0121] The acquisition module 501 is used to acquire at least one method corresponding to the message consumer class, and to acquire the method-level listener configuration parameters and configuration parameter priorities corresponding to each of the at least one method.

[0122] Module 502 is used to create a method-level message listener for each of the at least one method based on the method-level listener configuration parameters and configuration parameter priority for each of the at least one method.

[0123] The processing module 503 is used to process different messages sent by the message producer through the method-level message listener corresponding to each of the at least one method.

[0124] It should be noted that the description of the message processing device in this application is similar to the description of the method embodiment described above, and has similar beneficial effects as the method embodiment; therefore, it will not be repeated. For technical details not disclosed in this device embodiment, please refer to the description of the method embodiment in this application for understanding.

[0125] It should be noted that, in the embodiments of this application, if the above-described control method is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiments of this application, or the part that contributes to the related technology, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), magnetic disks, or optical disks. Thus, the embodiments of this application are not limited to any specific hardware and software combination.

[0126] Accordingly, embodiments of this application provide a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the message processing method provided in the above embodiments.

[0127] This application also provides a message processing device. Figure 8 This is a schematic diagram of the composition structure of a message processing device provided in an embodiment of this application, such as... Figure 8 As shown, the message processing device 600 includes: a memory 601, a processor 602, a communication interface 603, and a communication bus 604. The memory 601 stores executable message processing instructions; the processor 602 executes the executable message processing instructions stored in the memory to implement the message processing method provided in the above embodiment.

[0128] The descriptions of the message processing device and storage medium embodiments above are similar to those of the method embodiments above, and have similar beneficial effects. For technical details not disclosed in the message processing device and storage medium embodiments of this application, please refer to the descriptions of the method embodiments of this application for understanding.

[0129] It should be understood that the phrases "some embodiments" or "one embodiment" throughout the specification mean that a specific feature, structure, or characteristic related to an embodiment is included in at least one embodiment of this application. Therefore, "some embodiments" or "one embodiment" appearing throughout the specification do not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. It should be understood that in the various embodiments of this application, the sequence numbers of the above-described processes do not imply a sequential order of execution; the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application. The sequence numbers of the above-described embodiments are merely descriptive and do not represent the superiority or inferiority of the embodiments.

[0130] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0131] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple units or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, and the indirect coupling or communication connection between devices or units can be electrical, mechanical, or other forms.

[0132] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units. They may be located in one place or distributed across multiple network units. Some or all of the units may be selected to achieve the purpose of this embodiment according to actual needs.

[0133] In addition, each functional unit in the various embodiments of this application can be integrated into one processing unit, or each unit can be a separate unit, or two or more units can be integrated into one unit; the integrated unit can be implemented in hardware or in the form of hardware plus software functional units.

[0134] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media that can store program code, such as mobile storage devices, ROMs, magnetic disks, or optical disks.

[0135] Alternatively, if the integrated units described above are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, or the parts that contribute to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a product to execute all or part of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, ROMs, magnetic disks, or optical disks.

[0136] The above description is merely an embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A message processing method, characterized in that, include: Get at least one method corresponding to the message consumer class, and get the method-level listener configuration parameters and configuration parameter priority corresponding to each of the at least one method; Based on the method-level listener configuration parameters and configuration parameter priority corresponding to each of the at least one method, create a method-level message listener corresponding to each of the at least one method; The different messages sent by the message producer are processed by the method-level message listener corresponding to each of the at least one method.

2. The method according to claim 1, characterized in that, The step of creating a method-level message listener corresponding to each of the at least one method based on the method-level listener configuration parameters and configuration parameter priorities corresponding to each of the at least one method includes: Based on the priority of the configuration parameters, obtain the class-level listener configuration parameters and global configuration parameters corresponding to the message consumer class; Based on the method-level listener configuration parameters, class-level listener configuration parameters and global configuration parameters corresponding to each of the at least one method, determine the target listener configuration parameters corresponding to each of the at least one method. Based on the target listener configuration parameters corresponding to each of the at least one method, create a method-level message listener corresponding to each of the at least one method.

3. The method according to claim 2, characterized in that, The configuration parameters are prioritized from highest to lowest as follows: method-level listener configuration parameters, class-level listener configuration parameters, and global configuration parameters. The step of determining the target listener configuration parameters corresponding to each of the at least one method based on the method-level listener configuration parameters, class-level listener configuration parameters, and global configuration parameters corresponding to each of the at least one method includes: Obtain the target configuration parameters corresponding to the method-level listener configuration parameters of the i-th method in the message consumer class; If the configuration parameters of each method-level listener of the i-th method and their corresponding target configuration parameters are consistent, the configuration parameters of the method listener corresponding to the i-th method are determined as the target listener configuration parameters.

4. The method according to claim 3, characterized in that, The method further includes: Determine that there exists a first configuration parameter in the method-level listener configuration parameters corresponding to the i-th method that satisfies the consistency condition with the corresponding target configuration parameter, and that there exist other configuration parameters that do not satisfy the consistency condition with the corresponding target configuration parameter, and obtain the class-level listener configuration parameters; If it is determined that there is a second configuration parameter in the class-level listener configuration parameters that satisfies the consistency condition with the first other target configuration parameters, and the sum of the number of the second configuration parameters and the number of the first configuration parameters is equal to the number of method-level listener configuration parameters corresponding to the i-th method, then the first configuration parameter and the second configuration parameter are determined as the target listener configuration parameters corresponding to the i-th method. Wherein, the first other target configuration parameter is the target configuration parameter corresponding to the method-level listener configuration parameter of the i-th method, excluding the configuration parameter that satisfies the consistency condition with the first configuration parameter.

5. The method according to claim 4, characterized in that, The method further includes: Determine that there exists a second configuration parameter in the class-level listener configuration parameters that satisfies the consistency condition with the first other target configuration parameters, and that the sum of the number of the second configuration parameters and the number of the first configuration parameters is less than the number of method-level listener configuration parameters corresponding to the i-th method, and obtain the global configuration parameters; If it is determined that there is a third configuration parameter in the global configuration parameters that satisfies the consistency condition with the other second target configuration parameters, and the sum of the number of the first configuration parameters, the number of the second configuration parameters and the number of the third configuration parameters is equal to the number of method-level listener configuration parameters corresponding to the i-th method, then the first configuration parameter, the second configuration parameter and the third configuration parameter are determined as the target listener configuration parameters corresponding to the i-th method. Wherein, the second other target configuration parameter is the target configuration parameter corresponding to the method-level listener configuration parameter of the i-th method, excluding the configuration parameter that satisfies the consistency condition with the first configuration parameter and the second configuration parameter.

6. The method according to claim 4, characterized in that, The method further includes: If it is determined that the class-level listener configuration parameters do not meet the consistency condition with the first other target configuration parameters, the global configuration parameters are obtained. If it is determined that there exists a third configuration parameter in the global configuration parameters that satisfies the consistency condition with the first other target configuration parameters, and the sum of the number of the third configuration parameters and the number of the first configuration parameters is equal to the number of method-level listener configuration parameters corresponding to the i-th method, then the first configuration parameter and the third configuration parameter are determined as the target listener configuration parameters corresponding to the i-th method.

7. The method according to claim 6, characterized in that, The method further includes: If it is determined that the global configuration parameters do not satisfy the consistency condition with the first other target configuration parameters, the target configuration parameters corresponding to each method-level listener configuration parameter of the i-th method are updated to obtain the updated target configuration parameters. If the configuration parameters of each method-level listener of the i-th method and their corresponding updated target configuration parameters satisfy the consistency condition, the configuration parameters of the method-level listener corresponding to the i-th method are determined as the target listener configuration parameters.

8. The method according to claim 1, characterized in that, The method further includes: Obtain the first message received by the method-level message listener corresponding to each of the at least one method; The first message is preprocessed by the method-level message listener corresponding to each of the at least one method to obtain the preprocessed first message corresponding to each of the at least one method, wherein the preprocessing includes at least one of filtering processing and classification processing of the first message; Logical processing is performed on the preprocessed first message corresponding to each of the at least one method to obtain the message processing result, and the message processing result is sent.

9. A message processing device, characterized in that, include: The acquisition module is used to acquire at least one method corresponding to the message consumer class, and to acquire the method-level listener configuration parameters and configuration parameter priorities corresponding to each of the at least one method; A module is created to create a method-level message listener for each of the at least one method, based on the method-level listener configuration parameters and configuration parameter priorities corresponding to each of the at least one method. The processing module is used to process different messages sent by the message producer through the method-level message listener corresponding to each of the at least one method.

10. A message processing device, characterized in that, include: Memory, used to store executable message processing instructions; A processor, when executing executable message processing instructions stored in the memory, implements the method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Data processing method and device based on Canal

    CN111913853A

  • Message queue and consumer dynamic creation method and system

    CN113495797A