Message routing method, system and electronic device
By obtaining and comparing the description information of message queues through message routing methods, the target processor is determined and the message is sent, which solves the problem of high cost of accessing multiple message queues and realizes efficient management and flexible consumption of services.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- MAGIC CUBE MEDICAL TECH (SUZHOU) CO LTD
- Filing Date
- 2023-03-02
- Publication Date
- 2026-06-23
Smart Images

Figure CN116431359B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer software technology, and in particular to a message routing method, system, and electronic device. Background Technology
[0002] With the continuous emergence of message queue (MQ) technologies on the market, a single application often needs to connect to multiple different MQs.
[0003] Current implementations of applications connecting to message queues (MQ) typically involve writing separate access and consumption code for different MQs, with message consumption methods relying on hard-coding. This results in high implementation costs for applications connecting to multiple different MQs and significantly reduces the ability to effectively manage messages from different sources. Furthermore, since the cost of restarting services in production environments varies, there are currently no good methods to achieve hot switching and hot pausing of message consumption for services with high restart costs.
[0004] Therefore, there is an urgent need to provide a message routing method. Summary of the Invention
[0005] This invention provides a message routing method, system, and electronic device to address the deficiencies in the prior art.
[0006] This invention provides a message routing method, comprising:
[0007] After the message queue is accessed, the current message of the message queue is obtained, and the description information of the current message is determined;
[0008] The description information is compared with the pre-configured rule information to determine the target processor for processing the current message, and the current message is sent to the target processor.
[0009] According to a message routing method provided by the present invention, the step of obtaining the current message of the message queue includes:
[0010] Determine the link identifier of the current message and pass the link identifier into the message context of the current message.
[0011] According to a message routing method provided by the present invention, the step of sending the current message to the target processor includes:
[0012] Receive a forwarding request for the current message, the forwarding request including a forwarding target;
[0013] Extract the link identifier from the message context, encapsulate the link identifier, the current message, and the description information, and send the encapsulation result to the forwarding target.
[0014] According to a message routing method provided by the present invention, the step of sending the current message to the target processor includes:
[0015] Monitor the lifecycle of the current message;
[0016] If the target processor does not encounter any abnormalities in processing the current message, the lifecycle of the current message enters the deregistration phase.
[0017] If an exception occurs during the processing of the current message by the target processor, the lifecycle of the current message enters the exception handling phase.
[0018] The exception handling phase includes: sending an exception signal to the exception message queue to which the current message belongs, so as to notify the exception message queue to retry the message.
[0019] According to a message routing method provided by the present invention, the step of comparing the description information with pre-configured rule information to determine the target processor for processing the current message, and sending the current message to the target processor, includes:
[0020] The description information and the current message are transmitted to the routing resolver;
[0021] Based on the routing resolver, the description information is compared with the rule information to determine the target processor, and the current message is sent to the target processor.
[0022] According to a message routing method provided by the present invention, the routing parser is further configured with a log module;
[0023] The log module is used to record the message attributes of the current message.
[0024] According to a message routing method provided by the present invention, the step of determining the description information of the current message includes:
[0025] Based on the message context and description information of the current message, determine whether the current message is consumed repeatedly, and discard the current message that is consumed repeatedly.
[0026] According to a message routing method provided by the present invention, the step of comparing the description information with pre-configured rule information to determine the target processor for processing the current message includes:
[0027] Obtain the configuration information corresponding to the rule information;
[0028] The configuration information is parsed to obtain a rule object, and the rule object is stored as the rule information.
[0029] According to a message routing method provided by the present invention, the configuration information is obtained based on the following steps:
[0030] Retrieve message consumption rules and message routing rules;
[0031] Based on dynamic loading technology, the message consumption rules and message routing rules are converted into message queue access code rules;
[0032] The message queue access code rules are formatted and configured to obtain the configuration information.
[0033] The present invention also provides a message routing system, comprising:
[0034] The acquisition module is used to acquire the current message of the message queue after the message queue is accessed, and to determine the description information of the current message;
[0035] The routing module is used to compare the description information with pre-configured rule information, determine the target processor for processing the current message, and send the current message to the target processor.
[0036] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, implements the message routing method as described above.
[0037] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the message routing method as described above.
[0038] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the message routing method as described above.
[0039] This invention provides a message routing method, system, and electronic device. The method first obtains the current message in the message queue after it is accessed and determines the description information of the current message. Then, it compares the description information of the current message with pre-configured rule information to determine the target processor for processing the current message and sends the current message to the target processor. This routing method introduces pre-configured rule information, eliminating the need to write different access and consumption codes for different message queues (MQs). This allows message consumption to be implemented based on configured rule information, rather than hard-coded, significantly reducing the implementation cost of different MQs, improving the effective management of messages from different sources, facilitating the application of messages from different sources, and enabling services with high restart costs to have the ability to hot-swap and hot-pause message consumption. Attached Figure Description
[0040] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, those skilled in the art can obtain other drawings based on the drawings described below without creative effort.
[0041] Figure 1 This is one of the flowcharts illustrating the message routing method provided by the present invention;
[0042] Figure 2 This is the second flowchart illustrating the message routing method provided by the present invention;
[0043] Figure 3 This is a schematic diagram of the message routing system provided by the present invention;
[0044] Figure 4 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation
[0045] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0046] MQ, also known as Message Queuing, is a supporting software system based on queuing and message passing technologies. It provides synchronous or asynchronous, reliable message transmission for application systems in a network environment. MQ utilizes an efficient and reliable message passing mechanism for platform-independent data exchange and integrates distributed systems based on data communication. By providing message passing and message queuing models, it can extend inter-process communication in a distributed environment.
[0047] Currently available message queues (MQ) include RocketMQ, RabbitMQ, ActiveMQ, and Kafka. Message passing generally involves producers and consumers. Producers produce messages and send them to the MQ, while consumers read messages from the MQ and process them. Both producers and consumers need to connect to the MQ when interacting with it.
[0048] Current implementations of applications connecting to message queues (MQ) typically involve writing separate access and consumption code for different MQs, with message consumption methods relying on hard-coding. This results in high implementation costs for applications connecting to multiple different MQs and significantly reduces the ability to effectively manage messages from different sources. Furthermore, since the cost of restarting services in production environments varies, there are currently no good methods to achieve hot switching and hot pausing of message consumption for services with high restart costs.
[0049] Based on this, this embodiment of the invention provides a message routing method that can implement dynamic message routing for one or more message queues.
[0050] Figure 1 This is a flowchart illustrating a message routing method provided in an embodiment of the present invention, as shown below. Figure 1 As shown, the method includes:
[0051] S1, after the message queue is accessed, the current message of the message queue is obtained, and the description information of the current message is determined;
[0052] S2, compare the description information with the pre-configured rule information to determine the target processor for processing the current message, and send the current message to the target processor.
[0053] Specifically, the message routing method provided in this embodiment of the invention is executed by a message routing system. This message routing system can be configured within an application and / or service of a computer. The computer can be a local computer or a cloud computer; a local computer can be a PC, tablet, mobile phone, etc., without specific limitations. This message routing system can implement dynamic message routing. This message routing system can be implemented using Java or other programming languages, without specific limitations.
[0054] First, step S1 is executed. After the message queue is accessed, the message routing system obtains the current message in the message queue and determines the description information of the current message. The message queue is called MQ, and one or more message queues can be accessed. Each message queue establishes a connection with the message routing system to enable access to each message queue, and the message routing system can then pull messages from each message queue.
[0055] After a message queue is connected, the message routing system can pull the current message from the connected message queue. Then, the current message can be transformed to determine its description information, which may include the message's queue source (i.e., MQ source) and the message's topic name, etc.
[0056] Then, step S2 is executed. The message routing system compares the description information of the current message in each message queue with the pre-configured rule information to determine the target processor for processing the current message in each message queue. The rule information may include the correspondence between the message description information and the processor capable of processing the message. This rule information can be pre-configured through the configuration center. For example, the rule information can be represented as: {source:KAFKA,topic:topic,handler:[xxxHandler]}.
[0057] The comparison process is the process of determining the target processor. After determining the target processor for the current message of each message queue, the current message of each message queue is sent to the corresponding target processor so that the corresponding target processor can process the current message of each message queue.
[0058] The message routing method provided in this embodiment of the invention first obtains the current message in the message queue after the message queue is accessed, and determines the description information of the current message; then, it compares the description information of the current message with pre-configured rule information to determine the target processor for processing the current message, and sends the current message to the target processor. This routing method introduces pre-configured rule information, eliminating the need to write different access and consumption codes for different message queues (MQs). This allows message consumption to be implemented based on configured rule information, rather than hard-coded, significantly reducing the implementation cost of different MQs, improving the effective management of messages from different sources, facilitating the application of messages from different sources, and enabling services with high restart costs to have the ability to hot-swap and hot-pause message consumption.
[0059] Based on the above embodiments, the message routing method provided in this embodiment of the invention, after obtaining the current message of the message queue, includes:
[0060] The message encapsulator performs a unified message transformation on the current message to construct a message body object, which includes the content of the current message and the description information.
[0061] Specifically, in this embodiment of the invention, the message routing system may include a message wrapper. After receiving the current message from each message queue, the message routing system can send the current message to the message wrapper, which performs unified message transformation and constructs a message body object. This message body object includes the information content of the current message for each message queue and a description of each current message.
[0062] Based on the above embodiments, the message routing method provided in this embodiment of the invention, after obtaining the current message of the message queue, includes:
[0063] Determine the link identifier of the current message and pass the link identifier into the message context of the current message.
[0064] Specifically, in this embodiment of the invention, after obtaining the current messages of each message queue, the message routing system can also use a message wrapper to determine the trace identifier (TraceId) of each current message, which is a message attribute of the current message. Then, using the message wrapper, the trace identifier of each current message is passed into the message context of each current message, that is, the trace identifier of each current message is used as the message context attribute of each current message.
[0065] Understandably, if the link identifier for the current message does not exist, a new link identifier will be created for the current message. The existence of the link identifier for the current message can be used to construct the message link.
[0066] In this embodiment of the invention, the introduction of the link identifier of the current message can provide data support for the construction of the message link and meet the needs of message tracing.
[0067] Based on the above embodiments, the message routing method provided in this embodiment of the invention, wherein comparing the description information with pre-configured rule information to determine the target processor for processing the current message, and sending the current message to the target processor, includes:
[0068] The description information and the current message are transmitted to the routing resolver;
[0069] Based on the routing resolver, the description information is compared with the rule information to determine the target processor, and the current message is sent to the target processor.
[0070] Specifically, in this embodiment of the invention, the message routing system may further include a routing parser. The routing parser may call the rule information pre-configured in the message routing system. After the routing parser receives the message body object, that is, after receiving the current message of the message queue and the description information of the current message, it may compare the description information of the current message of each message queue with the rule information to determine the target processor of the current message of each message queue, and then send the current message of each message queue to the corresponding target processor.
[0071] Based on the above embodiments, the message routing method provided in this embodiment of the invention, after sending the current message to the target processor, includes:
[0072] Receive a forwarding request for the current message, the forwarding request including a forwarding target;
[0073] Extract the link identifier from the message context, encapsulate the link identifier, the current message, and the description information, and send the encapsulation result to the forwarding target.
[0074] Specifically, in this embodiment of the invention, after sending the current messages of each message queue to the corresponding target processor, a forwarding request for one or more current messages may be received. The forwarding request may include a forwarding target, which refers to the subject that needs the current message, such as other message queues or other processors.
[0075] After receiving a forwarding request for a current message, the message routing system can extract the link identifier from the message context of that current message. It then uses a message wrapper to re-encapsulate the link identifier, the current message itself, and its description, before sending the encapsulated result to the forwarding target. Because the encapsulated result contains the link identifier of the current message, messages originating from the same point can be linked together to form a message chain. This helps developers understand message forwarding methods and allows analysis software to visualize the message flow.
[0076] Based on the above embodiments, the message routing method provided in this embodiment of the invention, after sending the current message to the target processor, includes:
[0077] Monitor the lifecycle of the current message;
[0078] If the target processor does not encounter any abnormalities in processing the current message, the lifecycle of the current message enters the deregistration phase.
[0079] If an exception occurs during the processing of the current message by the target processor, the lifecycle of the current message enters the exception handling phase.
[0080] The exception handling phase includes: sending an exception signal to the exception message queue to which the current message belongs, so as to notify the exception message queue to retry the message.
[0081] Specifically, the message routing system's routing resolver can have a built-in monitoring module and a global exception handling module. The monitoring module can monitor the lifecycle of the current message in each message queue, while the global exception handling module can handle exceptions that occur during the processing of the current message in any message queue. Here, the lifecycle can include a live phase, a deregistration phase, and an exception handling phase. The message routing system enters the live phase when it receives the current message.
[0082] The monitoring module can receive signals from the target processor to indicate whether the processing of the current message is abnormal. If the monitoring module does not receive any abnormal signals, it determines that the target processor's processing of the current message is not abnormal, and the lifecycle of the current message enters the deregistration phase.
[0083] If the monitoring module receives an abnormal signal, it determines that the target processor's processing of the current message has encountered an anomaly, and the lifecycle of the current message enters the anomaly handling phase.
[0084] During the exception handling phase, the global exception handling module can send an exception signal to the exception message queue to which the current message belongs, so as to notify the exception message queue to retry the message, that is, to notify the exception message queue to retransmit the message.
[0085] Here, the global exception handling module can transmit the exception signal to the exception message queue by throwing an exception according to the pre-configured number of retries.
[0086] In this embodiment of the invention, by monitoring the lifecycle of the current message, the processing of the current message can be grasped in real time, and then timely action can be taken when an anomaly occurs in the processing of the current message.
[0087] Based on the above embodiments, the message routing method provided in this embodiment of the invention further includes a log module in the routing parser;
[0088] The log module is used to record the message attributes of the current message.
[0089] Specifically, in this embodiment of the invention, the routing resolver of the message routing system is further configured with a log module. This log module can record the message attributes of the current message to provide data support for the construction of message links. The message attributes may include the offset of the current message, the link identifier of the current message, etc.
[0090] Based on the above embodiments, the message routing method provided in this embodiment of the invention, after determining the description information of the current message, includes:
[0091] Based on the message context and description information of the current message, determine whether the current message is consumed repeatedly, and discard the current message that is consumed repeatedly.
[0092] Specifically, in this embodiment of the invention, the message routing system further includes a message filter. After determining the description information of the current message of each message queue, the message context of the current message of each message queue and the message body object converted by the message wrapper can be transmitted to the message filter. The message filter can use the message context and description information of the current message of each message queue to use distributed caching technology to determine whether the current message of each message queue is consumed repeatedly and discard the current message that is consumed repeatedly.
[0093] Here, the message context of the current message in each message queue can be distributed and cached first. Then, the cached message context is compared with the current message and its description information to determine whether there is a message in the message context with the same information content as the current message. If there is, the current message is considered to be a duplicate consumption and is discarded. Otherwise, the current message is considered to be a valid message and is sent to the message parser for subsequent operations.
[0094] The distributed caching technology used in this embodiment of the invention can utilize Redis, Memcache, ZooKeeper, and relational databases for caching.
[0095] In this embodiment of the invention, it is determined whether the current message is consumed repeatedly, and the current message that is consumed repeatedly is discarded, thus avoiding the repeated consumption of messages.
[0096] Based on the above embodiments, the message routing method provided in this embodiment of the invention includes, before comparing the description information with pre-configured rule information to determine the target processor for processing the current message, the following steps:
[0097] Obtain the configuration information corresponding to the rule information;
[0098] The configuration information is parsed to obtain a rule object, and the rule object is stored as the rule information.
[0099] Specifically, in this embodiment of the invention, the message routing system may further include a configuration center and a rule registrar. Rule information can be determined by first obtaining the configuration information corresponding to the rule information from the configuration center. This configuration information can be a fixed-format configuration file, which may be YAML format or other formats, without specific limitations here. The configuration center can be implemented using Nacos, Apollo, or configuration files, etc.
[0100] Understandably, if the configuration information in the configuration center changes, the configuration center will notify the application listening to that configuration information so that the application can obtain the configuration information in a timely manner.
[0101] Then, the configuration information is parsed using the rule registrar, which converts the fixed-format configuration file into a rule object, which is the required rule information.
[0102] Finally, this rule information can be stored in the memory of the message routing system to achieve pre-configuration of rule information in the message routing system. Here, a HashMap can be used to store this rule information in the memory of the message routing system.
[0103] The message routing system can also listen for changes in configuration information in the configuration center. If a change signal is received, it triggers the process of obtaining the configuration information corresponding to the rule information and using the configuration information to obtain the rule information, thereby enabling timely updates to the rule information.
[0104] In this embodiment of the invention, by using the configuration information of the configuration center to pre-configure the rule information in the message routing system, real-time message routing can be achieved, greatly reducing the time required for message routing and improving message routing efficiency.
[0105] Based on the above embodiments, the message routing method provided in this embodiment of the invention obtains the configuration information based on the following steps:
[0106] Retrieve message consumption rules and message routing rules;
[0107] Based on dynamic loading technology, the message consumption rules and message routing rules are converted into message queue access code rules;
[0108] The message queue access code rules are formatted and configured to obtain the configuration information.
[0109] Specifically, in this embodiment of the invention, the configuration center of the message routing system can obtain configuration information by dynamically retrieving message consumption rules and message routing rules from the rule base. This rule base can be maintained manually.
[0110] The configuration center utilizes dynamic loading technology to load / unload message queue access code rules, that is, to convert message consumption rules and message routing rules into message queue access code rules. This dynamic loading technology can be Java dynamic loading technology or Groovy dynamic loading technology; no specific limitation is made here. Here, loading can be understood as adding, and unloading as deleting. For example, with Java dynamic loading technology, Java can use JavaCompiler to compile the Java file containing message consumption rules and message routing rules into bytecode files, and use a class loader to implement dynamic loading and unloading of files.
[0111] Finally, the message queue access code rules are formatted and configured to obtain the configuration information corresponding to the rule information. Formatting can be done using YAML format, which involves converting the message queue access code rules into a YAML configuration file, i.e., the configuration information.
[0112] Based on the above embodiments, the message routing method provided in this embodiment of the invention further includes a message lifecycle management module in the message routing system, through which the lifecycle of each message can be summarized.
[0113] Based on the above embodiments, the message routing method provided in this embodiment of the invention describes the structure and data flow of the message routing system used to implement the method, as follows: Figure 2 As shown.
[0114] exist Figure 2 The message routing system includes a configuration center, rule registry, message encapsulator, message filter, route parser, and message lifecycle management module.
[0115] The configuration center provides configuration information to the rule registrar, which then uses the configuration information to generate and store rule information. The rule registrar then registers the rule information with the route resolver so that the route resolver can access the rule information.
[0116] When multiple message queues are connected, the message wrapper performs a unified message transformation on the current information of each message queue and constructs a message body object.
[0117] The message body object is passed to the message filter to filter the current message from repeated consumption, retaining the valid messages.
[0118] The message body object of a valid message is passed to the route resolver, where the built-in logging module, monitoring module, and global exception handling module perform logging, monitoring, and exception handling functions, respectively.
[0119] Finally, the routing resolver sends each valid message to the corresponding target processor for processing.
[0120] In summary, the message routing method provided in this embodiment of the invention abstracts and extracts the MQ access function and message consumption routing function after access, thereby enabling message reception, message encapsulation, message routing, and hot switching and hot pausing of consumption based on the configuration of the configuration center. This provides convenience for applications with single or multiple message sources and also provides data support for subsequent message tracing and message chain construction. Multiple MQs can be dynamically accessed using a simple configuration method, and consumption start / stop and consumption logic changes can be gracefully implemented without requiring service up / down.
[0121] like Figure 3 As shown, based on the above embodiments, this embodiment of the invention provides a message routing system, including:
[0122] The acquisition module 31 is used to acquire the current message of the message queue after the message queue is accessed, and to determine the description information of the current message;
[0123] The routing module 32 is used to compare the description information with pre-configured rule information, determine the target processor for processing the current message, and send the current message to the target processor.
[0124] Based on the above embodiments, the message routing system provided in this embodiment of the invention includes a message wrapper, used for:
[0125] Determine the link identifier of the current message and pass the link identifier into the message context of the current message.
[0126] Based on the above embodiments, the message routing system provided in this embodiment of the invention further includes a forwarding module, used for:
[0127] Receive a forwarding request for the current message, the forwarding request including a forwarding target;
[0128] Extract the link identifier from the message context, encapsulate the link identifier, the current message, and the description information, and send the encapsulation result to the forwarding target.
[0129] Based on the above embodiments, the message routing system provided in this embodiment of the invention further includes a routing resolver, which has a built-in monitoring module and a global exception handling module.
[0130] The monitoring module is used to monitor the lifecycle of the current message;
[0131] If the target processor does not encounter any abnormalities in processing the current message, the lifecycle of the current message enters the deregistration phase.
[0132] If an exception occurs during the processing of the current message by the target processor, the lifecycle of the current message enters the exception handling phase.
[0133] The global exception handling module is used to: during the exception handling phase, transmit an exception signal to the exception message queue to which the current message belongs, so as to notify the exception message queue to retry the message.
[0134] Based on the above embodiments, the message routing system provided in this embodiment of the invention further includes a routing resolver used for:
[0135] The description information is compared with the rule information to determine the target processor, and the current message is sent to the target processor.
[0136] Based on the above embodiments, the message routing system provided in this embodiment of the invention further includes a log module in the routing parser;
[0137] The log module is used to record the message attributes of the current message.
[0138] Based on the above embodiments, the message routing system provided in this embodiment of the invention further includes a message filter, used for:
[0139] Based on the message context and description information of the current message, determine whether the current message is consumed repeatedly, and discard the current message that is consumed repeatedly.
[0140] Based on the above embodiments, the message routing system provided in this embodiment of the invention further includes a message wrapper for:
[0141] Obtain the configuration information corresponding to the rule information;
[0142] The configuration information is parsed to obtain a rule object, and the rule object is stored as the rule information.
[0143] Based on the above embodiments, the message routing system provided in this embodiment of the invention further includes a configuration center, used for:
[0144] Retrieve message consumption rules and message routing rules;
[0145] Based on dynamic loading technology, the message consumption rules and message routing rules are converted into message queue access code rules;
[0146] The message queue access code rules are formatted and configured to obtain the configuration information.
[0147] Specifically, the functions of each module in the message routing system provided in this embodiment of the invention correspond one-to-one with the operation flow of each step in the above method-like embodiments, and the achieved effects are also the same. For details, please refer to the above embodiments, and this will not be repeated in this embodiment of the invention.
[0148] Figure 4 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 4 As shown, the electronic device may include a processor 410, a communications interface 420, a memory 430, and a communication bus 440, wherein the processor 410, the communications interface 420, and the memory 430 communicate with each other via the communication bus 440. The processor 410 can call logical instructions in the memory 430 to execute the message routing method provided in the above embodiments. This method includes: after a message queue is accessed, obtaining the current message of the message queue and determining the description information of the current message; comparing the description information with pre-configured rule information to determine a target processor for processing the current message, and sending the current message to the target processor.
[0149] Furthermore, the logical instructions in the aforementioned memory 430 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, 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 steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0150] On the other hand, the present invention also provides a computer program product, the computer program product including a computer program, which can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the message routing method provided in the above embodiments. The method includes: after a message queue is accessed, obtaining the current message of the message queue and determining the description information of the current message; comparing the description information with pre-configured rule information to determine a target processor for processing the current message, and sending the current message to the target processor.
[0151] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the message routing method provided in the above embodiments. The method includes: after a message queue is accessed, obtaining the current message of the message queue and determining the description information of the current message; comparing the description information with pre-configured rule information to determine a target processor for processing the current message, and sending the current message to the target processor.
[0152] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0153] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0154] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A message routing method, characterized in that, include: After the message queue is accessed, the current message of the message queue is obtained, and the description information of the current message is determined; The description information is compared with pre-configured rule information to determine the target processor for processing the current message, and the current message is sent to the target processor. The step of comparing the description information with pre-configured rule information to determine the target processor for processing the current message includes: Obtain the configuration information corresponding to the rule information; The configuration information is parsed to obtain a rule object, and the rule object is stored as the rule information. The configuration information is obtained based on the following steps: Retrieve message consumption rules and message routing rules; Based on dynamic loading technology, the message consumption rules and message routing rules are converted into message queue access code rules; The message queue access code rules are formatted and configured to obtain the configuration information.
2. The message routing method according to claim 1, characterized in that, The step of obtaining the current message in the message queue includes: Determine the link identifier of the current message and pass the link identifier into the message context of the current message.
3. The message routing method according to claim 2, characterized in that, The step of sending the current message to the target processor includes: Receive a forwarding request for the current message, the forwarding request including a forwarding target; Extract the link identifier from the message context, encapsulate the link identifier, the current message, and the description information, and send the encapsulation result to the forwarding target.
4. The message routing method according to claim 1, characterized in that, The step of sending the current message to the target processor includes: Monitor the lifecycle of the current message; If the target processor does not encounter any abnormalities in processing the current message, the lifecycle of the current message enters the deregistration phase. If an exception occurs during the processing of the current message by the target processor, the lifecycle of the current message enters the exception handling phase. The exception handling phase includes: sending an exception signal to the exception message queue to which the current message belongs, so as to notify the exception message queue to retry the message.
5. The message routing method according to claim 1, characterized in that, The step of comparing the description information with pre-configured rule information to determine the target processor for processing the current message, and sending the current message to the target processor, includes: The description information and the current message are transmitted to the routing resolver; Based on the routing resolver, the description information is compared with the rule information to determine the target processor, and the current message is sent to the target processor.
6. The message routing method according to claim 5, characterized in that, The route resolver is also configured with a log module; The log module is used to record the message attributes of the current message.
7. The message routing method according to any one of claims 1-6, characterized in that, The step of determining the description information of the current message includes: Based on the message context and description information of the current message, determine whether the current message is consumed repeatedly, and discard the current message that is consumed repeatedly.
8. A message routing system, characterized in that, include: The acquisition module is used to acquire the current message of the message queue after the message queue is accessed, and to determine the description information of the current message; The routing module is used to compare the description information with pre-configured rule information, determine the target processor for processing the current message, and send the current message to the target processor. Also includes: message wrappers, used for: Obtain the configuration information corresponding to the rule information; The configuration information is parsed to obtain a rule object, and the rule object is stored as the rule information. It also includes a configuration center for: Retrieve message consumption rules and message routing rules; Based on dynamic loading technology, the message consumption rules and message routing rules are converted into message queue access code rules; The message queue access code rules are formatted and configured to obtain the configuration information.