Message processing method, device, equipment and storage medium
By instantiating the environment configuration object in the message queue middleware to generate a business switch and message queue, and using the consumer thread pool to process messages in batches, the problems of large code volume, high maintenance cost and low message processing efficiency in the existing technology are solved. Enables more efficient message processing and resource utilization.
Patent Information
- Application Number
- CN202110386257.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-04-12
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2041-04-12
AI Technical Summary
The existing message queue middleware has deficiencies in business maintenance and message processing efficiency, especially because the amqp calling method is a string, which results in a large amount of code and high maintenance costs. It lacks controllable batch consumption of messages, resulting in a waste of server resources and Message throughput is low.
By instantiating the environment configuration object, the business switch and message queue are generated, and the binding relationship is established. The message middleware is used to transmit the message into the switch, the message is transferred to the real-time message queue according to the delayed sending time, and the message is received through the subscriber and cached in Block queue, use consumer thread pool to read and process message data in batches, and dynamically adjust the size of the thread pool to improve efficiency.
It reduces development and business maintenance costs, improves business maintenance efficiency and code readability, reduces server resource consumption and pressure, and improves message processing efficiency.
Smart Images

Figure CN113064742B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of batch updating of big data technology, and in particular to a message processing method, device, equipment and storage medium. Background Art
[0002] Message queue middleware is an important component in distributed systems. It mainly solves problems such as application decoupling, asynchronous messaging, traffic peak shaving and message communication, and realizes high-performance, high-availability, scalable and eventually consistent architecture.
[0003] Message queue rabbitmq is one of the common message queue middlewares. Currently, only basic rabbitmq method calls are provided on the market. Common method call dependency packages include advanced message queue protocol amqp based on microframework springboot and message driver stream-rabbit based on security toolkit springcloud. The amqp dependency package is used directly in the project. Since the input parameter of the amqp call method is a string instead of an object, the method for creating a message queue needs to be called one by one or declared one by one in a class. Not only is the amount of code large, but the consumption server cannot be controlled according to the Internet Protocol address through class declaration, resulting in high business maintenance costs and low business maintenance efficiency. In addition, the existing message queue lacks controllable batch consumption messages, resulting in server resource waste and low message throughput. Summary of the invention
[0004] The present invention provides a message processing method, device, equipment and storage medium, which are used to improve business maintenance efficiency and code readability, and improve message processing efficiency.
[0005] To achieve the above-mentioned purpose, the first aspect of the present invention provides a message processing method, including: instantiating an environment configuration object, generating a business switch and a business message queue according to the environment configuration object through a preset consumer tool class, and establishing a corresponding binding relationship between the business switch and the business message queue, wherein the business message queue is a real-time message queue or a delayed message queue; passing the produced message to the business switch through a preset message middleware, passing the produced message to the business message queue through the business switch according to the binding relationship, when the produced message waits for a preset delayed sending time in the delayed message queue, passing the produced message whose delayed sending time expires to the real-time message queue, and the delayed sending time corresponding to the same delayed message queue is the same; receiving at least one produced message pushed by the real-time message queue through a preset subscriber, and caching the at least one produced message in a preset blocking queue; batch reading each batch of message data from the preset blocking queue every preset waiting time, creating an actual consumer thread in a preset consumer thread pool, and performing business processing on each batch of message data through the actual consumer thread.
[0006] Optionally, in a first implementation method of the first aspect of the present invention, the instantiated environment configuration object generates a business switch and a business message queue according to the environment configuration object through a preset consumer tool class, and establishes a corresponding binding relationship between the business switch and the business message queue, and the business message queue is a real-time message queue or a delayed message queue, including: instantiating the environment configuration object, and starting the preset consumer tool class, the environment configuration object includes a preset real-time switch name, a preset real-time message queue name, a preset delayed switch name, a preset delayed message queue name and a preset delayed sending duration, and the preset delayed sending duration One-to-one correspondence with the preset queue sequence number rule; generating a business switch and a business message queue according to the preset real-time switch name, the preset delayed switch name, the preset real-time message queue name and the preset delayed message queue name through the preset consumer tool class, the business switch includes a real-time switch and a delayed switch, and the business message queue includes a real-time message queue and a delayed message queue; based on the preset queue sequence number rule and the delayed sending duration corresponding to the queue sequence number rule, respectively set the delay sequence number and delay parameters of the delayed message queue, and establish a corresponding binding relationship between the business switch and the business message queue.
[0007] Optionally, in a second implementation method of the first aspect of the present invention, the produced message is transmitted to the business switch through the preset message middleware, and the produced message is transmitted to the business message queue through the business switch according to the binding relationship. When the produced message is waiting for a preset delayed sending time in the delayed message queue, the produced message whose delayed sending time expires is transmitted to the real-time message queue, and the delayed sending time corresponding to the same delayed message queue is the same, including: receiving a produced message sent by a preset producer tool class, and transmitting the produced message to the business switch through the preset message middleware, and the produced message carries an expected consumption time limit, and the expected consumption time limit is used for Indicate whether the produced message is a real-time message or a delayed message; determine the message category corresponding to the produced message based on the expected consumption time, and match the corresponding target switch from the business switch according to the message category, wherein the target switch is a real-time switch or a delayed switch; transmit the produced message to the corresponding business message queue through the target switch according to the binding relationship, and the delayed sending duration corresponding to the same delayed message queue is the same; when the produced message waits for a preset delayed sending duration in the delayed message queue, transmit the produced message with the expired delayed sending duration to the real-time switch, and store the produced message with the expired delayed sending duration into the real-time message queue through the real-time switch.
[0008] Optionally, in a third implementation method of the first aspect of the present invention, the at least one produced message pushed by the real-time message queue is received through a preset subscriber, and the at least one produced message is cached in a preset blocking queue, including: receiving at least one produced message pushed by the real-time message queue through a preset subscriber, and performing data format conversion on each produced message to obtain a converted message data set; writing the converted message data set to a preset blocking queue, and the preset blocking queue is a memory buffer.
[0009] Optionally, in a fourth implementation method of the first aspect of the present invention, each batch of message data is read in batches from the preset blocking queue at every preset waiting time, an actual consumer thread is created in the preset consumer thread pool, and business processing is performed on each batch of message data through the actual consumer thread, including: each batch of message data is read in batches from the preset blocking queue at every preset waiting time according to the preset maximum consumption quantity per batch, and the quantity of each batch of message data is less than or equal to the preset maximum consumption quantity per batch; an actual consumer thread is created in the preset consumer thread pool according to the preset maximum number of consumer threads, and each batch of message data is processed by the actual consumer thread to obtain a processing result, and the processing result is sent to the message middleware, so that the message middleware passes the message status corresponding to each produced message.
[0010] Optionally, in a fifth implementation of the first aspect of the present invention, each batch of message data is read from the preset blocking queue in batches at preset waiting time intervals, an actual consumer thread is created in the preset consumer thread pool, and business processing is performed on each batch of message data by the actual consumer thread. The message processing method also includes: periodically scanning the environment configuration object through a preset configuration change thread; when it is detected that there is a configuration information change in the environment configuration object, obtaining the changed environment configuration object, and passing the subscription status corresponding to the preset subscriber according to the changed environment configuration object, and changing the preset consumer thread pool size.
[0011] Optionally, in a sixth implementation of the first aspect of the present invention, each batch of message data is read in batches from the preset blocking queue at preset waiting time intervals, an actual consumer thread is created in a preset consumer thread pool, and after business processing is performed on each batch of message data by the actual consumer thread, the message processing method further includes: initializing the link identifier of the actual consumer thread; based on the link identifier of the actual consumer thread, recording all consumption process data of the actual consumer thread into a preset current thread local variable and a preset log printing object, respectively.
[0012] The second aspect of the present invention provides a message processing device, including: a generation module, which is used to instantiate an environment configuration object, generate a business switch and a business message queue according to the environment configuration object through a preset consumer tool class, and establish a corresponding binding relationship between the business switch and the business message queue, wherein the business message queue is a real-time message queue or a delayed message queue; an input module, which is used to input the produced message to the business switch through a preset message middleware, and input the produced message to the business message queue through the business switch according to the binding relationship. When the produced message waits for a preset delayed sending time in the delayed message queue, the produced message whose delayed sending time expires is input to the real-time message queue, and the delayed sending time corresponding to the same delayed message queue is the same; a cache module, which is used to receive at least one produced message pushed by the real-time message queue through a preset subscriber, and cache the at least one produced message in a preset blocking queue; a processing module, which is used to batch read each batch of message data from the preset blocking queue every preset waiting time, create an actual consumer thread in a preset consumer thread pool, and perform business processing on each batch of message data through the actual consumer thread.
[0013] Optionally, in a first implementation manner of the second aspect of the present invention, the generation module is specifically used to: instantiate an environment configuration object and start a preset consumer tool class, the environment configuration object including a preset real-time switch name, a preset real-time message queue name, a preset delayed switch name, a preset delayed message queue name and a preset delayed sending duration, wherein the preset delayed sending duration corresponds one-to-one to a preset queue sequence number rule; generate a business switch and a business message queue through the preset consumer tool class according to the preset real-time switch name, the preset delayed switch name, the preset real-time message queue name and the preset delayed message queue name, the business switch including a real-time switch and a delayed switch, and the business message queue including a real-time message queue and a delayed message queue; based on the preset queue sequence number rule and the delayed sending duration corresponding to the queue sequence number rule, respectively set the delay sequence number and delay parameters of the delayed message queue, and establish a corresponding binding relationship between the business switch and the business message queue.
[0014] Optionally, in a second implementation method of the second aspect of the present invention, the input module is specifically used to: receive a produced message sent by a preset producer tool class, and input the produced message to the business switch through a preset message middleware, wherein the produced message carries an expected consumption time limit, and the expected consumption time limit is used to indicate that the produced message is a real-time message or a delayed message; determine the message category corresponding to the produced message based on the expected consumption time limit, and match the corresponding target switch from the business switch according to the message category, wherein the target switch is a real-time switch or a delayed switch; input the produced message to the corresponding business message queue through the target switch according to the binding relationship, and the delayed sending time corresponding to the same delayed message queue is the same; when the produced message is waiting for a preset delayed sending time limit in the delayed message queue, the produced message with expired delayed sending time limit is input to the real-time switch, and the produced message with expired delayed sending time limit is stored in the real-time message queue through the real-time switch.
[0015] Optionally, in a third implementation method of the second aspect of the present invention, the cache module is specifically used to: receive at least one produced message pushed by the real-time message queue through a preset subscriber, and convert the data format of each produced message to obtain a converted message data set; write the converted message data set into a preset blocking queue, and the preset blocking queue is a memory buffer.
[0016] Optionally, in a fourth implementation method of the second aspect of the present invention, the processing module is specifically used to: read each batch of message data from the preset blocking queue in batches according to a preset maximum consumption quantity per batch at preset waiting time intervals, and the quantity of each batch of message data is less than or equal to the preset maximum consumption quantity per batch; create an actual consumer thread in a preset consumer thread pool according to the preset maximum number of consumer threads, and process each batch of message data through the actual consumer thread to obtain a processing result, and send the processing result to the message middleware, so that the message middleware passes the message status corresponding to each produced message.
[0017] Optionally, in a fifth implementation of the second aspect of the present invention, the message processing device also includes: a scanning module, used to periodically scan the environment configuration object through a preset configuration change thread; a change module, used to obtain the changed environment configuration object when it is detected that there is a configuration information change in the environment configuration object, and transmit the subscription status corresponding to the preset subscriber according to the changed environment configuration object, and change the preset consumer thread pool size.
[0018] Optionally, in a sixth implementation method of the second aspect of the present invention, the message processing device also includes: an initialization module for initializing the link identifier of the actual consumer thread; and a recording module for recording all consumption process data of the actual consumer thread, based on the link identifier of the actual consumer thread, into a preset current thread local variable and a preset log printing object respectively.
[0019] The third aspect of the present invention provides a message processing device, comprising: a memory and at least one processor, wherein the memory stores instructions; the at least one processor calls the instructions in the memory so that the message processing device executes the above-mentioned message processing method.
[0020] A fourth aspect of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores instructions, which, when executed on a computer, enable the computer to execute the above-mentioned message processing method.
[0021] In the technical solution provided by the present invention, an environment configuration object is instantiated, a business switch and a business message queue are generated according to the environment configuration object through a preset consumer tool class, and a corresponding binding relationship is established between the business switch and the business message queue, wherein the business message queue is a real-time message queue or a delayed message queue; a produced message is transmitted to the business switch through a preset message middleware, and the produced message is transmitted to the business message queue through the business switch according to the binding relationship, and when the produced message waits for a preset delayed sending time in the delayed message queue, the produced message whose delayed sending time expires is transmitted to the real-time message queue, and the delayed sending time corresponding to the same delayed message queue is the same; at least one produced message pushed by the real-time message queue is received through a preset subscriber, and the at least one produced message is cached in a preset blocking queue; each batch of message data is batch-read from the preset blocking queue at preset waiting time intervals, an actual consumer thread is created in a preset consumer thread pool, and business processing is performed on each batch of message data through the actual consumer thread. In the embodiment of the present invention, a business switch and a business message queue are created in the message middleware according to the environment configuration object through a preset consumer tool class, which reduces the development cost and business maintenance cost, and improves the business maintenance efficiency and code readability. By creating an actual consumer thread in a preset consumer thread pool, calling the actual consumer thread to batch consume each batch of message data in the blocking queue, the server resource consumption and pressure are reduced, and the message processing efficiency is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 A schematic diagram of an embodiment of a message processing method in an embodiment of the present invention;
[0023] Figure 2 A schematic diagram of another embodiment of the message processing method in an embodiment of the present invention;
[0024] Figure 3 A schematic diagram of an embodiment of a message processing device in an embodiment of the present invention;
[0025] Figure 4 A schematic diagram of another embodiment of a message processing device in an embodiment of the present invention;
[0026] Figure 5 The figure is a schematic diagram of an embodiment of a message processing device in an embodiment of the present invention. DETAILED DESCRIPTION
[0027] Embodiments of the present invention provide a message processing method, apparatus, device and storage medium for consuming messages in batches through consumer tools, reducing server resource consumption and pressure, and improving message processing efficiency.
[0028] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" or "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0029] For ease of understanding, the specific process of the embodiment of the present invention is described below. Figure 1 , an embodiment of the message processing method in the embodiment of the present invention includes:
[0030] 101. Instantiate an environment configuration object, generate a business switch and a business message queue according to the environment configuration object through a preset consumer tool class, and establish a corresponding binding relationship between the business switch and the business message queue. The business message queue is a real-time message queue or a delayed message queue.
[0031] Specifically, the server starts the preset consumer tool class and instantiates the environment configuration object; the server calls the preset consumer tool class, creates a business switch and a business message queue according to the environment configuration object, the business switch is a real-time switch and / or a delayed switch, the business message queue is a real-time message queue and / or a delayed message queue, and the business switch and the business message queue are mapped and bound one by one based on the preset routing rules, wherein the preset routing rules are used to indicate the configuration information for binding the business switch and the business message queue, and the preset routing rules can be dynamically configured according to the actual business application scenario. That is, there is a one-to-one correspondence between the real-time switch and the real-time message queue, there is a one-to-one correspondence between the delayed switch and the delayed message queue, and there is a many-to-one relationship between the delayed message queue and the real-time switch.
[0032] It is understandable that the execution subject of the present invention may be a message processing device, or a terminal or a server, which is not limited here. The embodiment of the present invention is described by taking a server as the execution subject as an example.
[0033] 102. The produced message is transmitted to the business switch through the preset message middleware, and the produced message is transmitted to the business message queue through the business switch according to the binding relationship. When the produced message is waiting for the preset delayed sending time in the delayed message queue, the produced message with the expired delayed sending time is transmitted to the real-time message queue. The delayed sending time corresponding to the same delayed message queue is the same.
[0034] Specifically, the server receives produced messages generated and sent by a preset producer tool class, where the produced messages are real-time messages or delayed messages; the server transmits the real-time messages or delayed messages to the real-time message queue or delayed message queue respectively according to the corresponding binding relationship through the business switch, and the delayed sending time in the same delayed message queue is the same. For example, messages A, B, C, D, E and F have been produced, and the corresponding delayed sending times are 5 seconds, 3 seconds, 3 seconds, 1 second, 5 seconds and 3 seconds respectively. The delay queue numbers include queue_005, queue_003 and queue_001, among which the delay queue number corresponding to the delayed sending time of 5 seconds is queue_005, the delay queue number corresponding to the delayed sending time of 3 seconds is queue_003, and the delay queue number corresponding to the delayed sending time of 1 second is queue_001. The server pushes the produced messages A and E to the delayed message queue with the delay queue number queue_005, the server pushes the produced messages B, C and F to the delayed message queue with the delay queue number queue_003, and the server pushes the produced message D to the delayed message queue with the delay queue number queue_001.
[0035] 103. Receive at least one produced message pushed by the real-time message queue through a preset subscriber, and cache the at least one produced message in a preset blocking queue.
[0036] The number of preset subscribers can be 0 or more, which is not limited here. When the number of preset subscribers is 0, the server determines not to consume temporarily and only uses it to temporarily store messages. When the concurrent peak is less than the expected threshold, the server resets the number of preset subscribers to be greater than 0 and consumes messages again. Specifically, the server receives at least one produced message from the real-time message queue through the preset subscriber, and the server stores at least one produced message in the preset blocking queue through the preset subscriber.
[0037] 104. Each batch of message data is read from the preset blocking queue in batches at preset waiting time intervals, an actual consumer thread is created in a preset consumer thread pool, and business processing is performed on each batch of message data through the actual consumer thread.
[0038] Specifically, the server periodically reads the preset maximum consumption quantity of each batch of data from the preset blocking queue according to the preset waiting time, and obtains the reading result; when the reading result is null, the server continues to perform the next data reading operation; when the reading result is not null, the server creates an actual consumer thread in the preset consumer thread pool, and the server performs business processing on each batch of message data through the actual consumer thread. It can be understood that the server can not only flexibly control the number of messages consumed in each batch, but also perform multi-threaded consumption of each batch of message data, thereby improving the message processing efficiency through batch processing.
[0039] Furthermore, the server stores each batch of message data in the blockchain database, which is not specifically limited here.
[0040] In the embodiment of the present invention, a business switch and a business message queue are created in the message middleware according to the environment configuration object through a preset consumer tool class, which reduces the development cost and business maintenance cost, and improves the business maintenance efficiency and code readability. By creating an actual consumer thread in a preset consumer thread pool, calling the actual consumer thread to batch consume each batch of message data in the blocking queue, the server resource consumption and pressure are reduced, and the message processing efficiency is improved.
[0041] See also Figure 2 Another embodiment of the message processing method in the embodiment of the present invention includes:
[0042] 201. Instantiate an environment configuration object, generate a business switch and a business message queue according to the environment configuration object through a preset consumer tool class, and establish a corresponding binding relationship between the business switch and the business message queue. The business message queue is a real-time message queue or a delayed message queue.
[0043] Among them, the environment configuration object is RabbitContext, which is used in the message middleware rabbitmq. The environment configuration object includes the preset maximum consumption quantity per batch and the preset maximum number of consumer threads. It can also include the preset waiting time and the Internet protocol address (IP) of the subscriber server. The preset waiting time is used to indicate the estimated waiting time for pulling the maximum number of messages.
[0044] Optionally, the server instantiates an environment configuration object and starts a preset consumer tool class, the environment configuration object includes a preset real-time switch name, a preset real-time message queue name, a preset delayed switch name, a preset delayed message queue name and a preset delayed sending duration, and the preset delayed sending duration corresponds to the preset queue sequence number rule one by one; the server generates a business switch and a business message queue according to the preset real-time switch name, the preset delayed switch name, the preset real-time message queue name and the preset delayed message queue name through the preset consumer tool class, the business switch includes a real-time switch and a delayed switch, and the business message queue includes a real-time message queue and a delayed message queue; the server sets the delay sequence number and delay parameters of the delayed message queue based on the preset queue sequence number rule and the delayed sending duration corresponding to the queue sequence number rule, and establishes a corresponding binding relationship between the business switch and the business message queue. It should be noted that the number of real-time switches and the number of real-time message queues are both 1, the number of delayed switches and the number of delayed message queues can be greater than or equal to 0, and in the same environment configuration object, the number of real-time switches and the number of real-time message queues are equal, and the number of delayed switches and the number of delayed message queues are equal.
[0045] 202. The produced message is transmitted to the business switch through the preset message middleware, and the produced message is transmitted to the business message queue through the business switch according to the binding relationship. When the produced message is waiting for the preset delayed sending time in the delayed message queue, the produced message with the expired delayed sending time is transmitted to the real-time message queue. The delayed sending time corresponding to the same delayed message queue is the same.
[0046] It should be noted that the produced message can be a real-time message. After the produced message reaches the specified time length (that is, the preset delayed sending time length) in the delay queue, the produced message will be transmitted to the real-time switch, and then the real-time switch will transmit it to the real-time message queue.
[0047] Optionally, first, the server receives the produced message sent by the preset producer tool class, and transmits the produced message to the business switch through the preset message middleware. The produced message carries the expected consumption time, and the expected consumption time is used to indicate that the produced message is a real-time message or a delayed message; then, the server determines the message category corresponding to the produced message based on the expected consumption time, and matches the corresponding target switch from the business switch according to the message category, and the target switch is a real-time switch or a delayed switch; then, the server transmits the produced message to the corresponding business message queue through the target switch according to the binding relationship, and the delayed sending time corresponding to the same delayed message queue is the same, that is, the server transmits the real-time message to the real-time switch, and then transmits the real-time message to the real-time message queue through the real-time switch, and the server transmits the delayed message to the delayed switch with the sequence number corresponding to the expected consumption time, and then transmits the delayed message to the corresponding delayed queue through the delayed switch. Finally, when the produced message is waiting for the preset delayed sending time in the delayed message queue, the server transmits the produced message with the expired delayed sending time to the real-time switch, and stores the produced message with the expired delayed sending time in the real-time message queue through the real-time switch.
[0048] It can be understood that the delayed sending time corresponding to the produced messages in the same message queue is the same; when the business message queue corresponding to the produced message is a delayed message queue, and the delayed sending time corresponding to the produced message expires, the server stores the produced message in the real-time switch through the message middleware, and stores the produced message with expired delayed sending time in the real-time message queue through the real-time switch. There is a preset binding rule between the delayed message queue and the corresponding real-time switch, wherein the preset binding rule is used to instruct the produced message in the delayed message queue to be transferred to the corresponding real-time message queue.
[0049] 203. Receive at least one produced message pushed by the real-time message queue through a preset subscriber, and cache the at least one produced message in a preset blocking queue.
[0050] Among them, at least one produced message may include a message that already exists in the real-time message queue, and may also include a message that is passed in from the delayed message queue. The real-time messages in the real-time message queue are processed by the preset subscribers, and the same subscriber can process multiple real-time messages at a time (that is, at least one produced message), and multiple subscribers can process the real-time messages in the same real-time message queue at the same time. For example, real-time message queue A has 3 preset subscribers, and each subscriber subscribes to 4 messages at a time. Therefore, the 3 preset subscribers can process up to 3*4, that is, 12 messages at a time, which improves the efficiency of real-time message processing.
[0051] Optionally, the server receives at least one produced message pushed by the real-time message queue through a preset subscriber, and performs data format conversion on each produced message to obtain a converted message data set; the server writes the converted message data set into a preset blocking queue, which is a memory buffer. It is understandable that for a distributed system, in order to be compatible with different formats of message middleware pushes by different dependency packages, the server performs data format conversion on each produced message. When the server sends a message through a preset producer tool class, the server converts the environment configuration object into a JS object notation JSON string, and then the server converts the JSON string into an object for processing through a preset consumer tool class.
[0052] 204. Each batch of message data is read from the preset blocking queue in batches at preset waiting time intervals, an actual consumer thread is created in a preset consumer thread pool, and business processing is performed on each batch of message data through the actual consumer thread.
[0053] Among them, the number of actual consumer threads can be 1 or multiple, which is not specifically limited here. When the number of message data in the preset blocking queue is 0, the number of actual consumer threads is 0. Optionally, the server reads each batch of message data from the preset blocking queue in batches according to the preset maximum consumption number of each batch at every preset waiting time, and the number of message data in each batch is less than or equal to the preset maximum consumption number of each batch; the server creates an actual consumer thread in the preset consumer thread pool according to the preset maximum number of consumer threads, and processes each batch of message data through the actual consumer thread to obtain the processing result, and sends the processing result to the message middleware, so that the message middleware passes the message status corresponding to each produced message. That is, when the actual consumer thread notifies the message middleware that the processing result is completed, the message middleware will push a new batch of messages to the preset blocking queue. The preset maximum consumption number of each batch is used to indicate the maximum number threshold of message data read in batches from the preset blocking queue each time, and the preset maximum number of consumer threads is used to indicate the maximum number threshold of the actual consumer threads. The preset maximum consumption number of each batch and the preset maximum number of consumer threads are pre-set in the environment configuration object and dynamically configured according to the actual application scenario.
[0054] Furthermore, the server initializes the link identifier of the actual consumer thread; based on the link identifier of the actual consumer thread, the server records all consumption process data of the actual consumer thread in the preset current thread local variable and the preset log printing object. It can be understood that the server records all consumption process data of the actual consumer thread in the preset current thread local variable and the preset log printing object MDC according to the link identifier of the actual message sender thread, so that all consumption processes can be tracked by the link, reducing the service maintenance cost.
[0055] 205. Periodically scan the environment configuration object through a preset configuration change thread.
[0056] Specifically, the server uses preset configuration variables to store configuration information of the environment configuration object, and the preset configuration variables include the maximum number of processing threads, the maximum number of single consumptions, and the subscriber Internet Protocol address; when the preset consumer tool class is started, the maximum number of processing threads, the maximum number of single consumptions, and the subscriber Internet Protocol address are respectively consistent with the corresponding variable values in the current environment configuration object; when the server periodically detects through a preset configuration change thread that the maximum number of processing threads, the maximum number of single consumptions, and the subscriber Internet Protocol address are respectively inconsistent with the corresponding variable values in the current environment configuration object, the server determines that there is a configuration information change in the environment configuration object.
[0057] 206. When it is detected that there is a configuration information change in the environment configuration object, the changed environment configuration object is obtained, and the subscription status corresponding to the preset subscriber is passed in according to the changed environment configuration object, and the preset consumer thread pool size is changed.
[0058] Specifically, when it is detected that there is a configuration information change in the environment configuration object, the server obtains the changed environment configuration object, and the server passes the subscription status of the preset subscriber according to the changed environment configuration object (that is, the maximum number of processing threads, the maximum number of single consumptions, and the subscriber Internet Protocol address), and changes the preset consumer thread pool size. Then, the server assigns the variables in the environment configuration object to the variables corresponding to the current thread for the next comparison. When the subscriber's Internet Protocol address is inconsistent with the current server's Internet Protocol address, the server cancels all subscribers (that is, the preset subscribers) in the real-time message queue in the environment configuration object; when the subscriber's Internet Protocol address is consistent with the current server's Internet Protocol address, and the number of threads and the number of subscribers are inconsistent, the server registers or cancels the subscribers in the real-time message queue in the environment configuration object; when the number of consumptions in each batch is inconsistent, the server cancels all subscribers and re-registers the subscribers in the real-time message queue in the environment configuration object. Furthermore, when messages have been produced and the preset maximum number of consumptions per batch has changed, the server reinitializes all subscribers in the real-time message queue in the environment configuration object through the preset configuration change thread; when the preset maximum number of consumer threads has changed, the server registers or unregisters some subscribers in the real-time message queue in the environment configuration object, and expands or reduces the preset consumer thread pool size.
[0059] In the embodiment of the present invention, a business switch and a business message queue are created in the message middleware according to the environment configuration object through a preset consumer tool class, which reduces the development cost and business maintenance cost, and improves the business maintenance efficiency and code readability. By creating an actual consumer thread in a preset consumer thread pool, calling the actual consumer thread to batch consume each batch of message data in the blocking queue, the server resource consumption and pressure are reduced, and the message processing efficiency is improved.
[0060] The message processing method in the embodiment of the present invention is described above. The message processing device in the embodiment of the present invention is described below. Figure 3 , an embodiment of a message processing device in an embodiment of the present invention includes:
[0061] The generation module 301 is used to instantiate the environment configuration object, generate the service switch and the service message queue according to the environment configuration object through the preset consumer tool class, and establish a corresponding binding relationship between the service switch and the service message queue, and the service message queue is a real-time message queue or a delayed message queue;
[0062] The input module 302 is used to input the produced message to the business switch through the preset message middleware, and input the produced message to the business message queue through the business switch according to the binding relationship. When the produced message is waiting for the preset delayed sending time in the delayed message queue, the produced message with the delayed sending time expired is input to the real-time message queue. The delayed sending time corresponding to the same delayed message queue is the same.
[0063] The cache module 303 is used to receive at least one produced message pushed by the real-time message queue through a preset subscriber, and cache the at least one produced message in a preset blocking queue;
[0064] The processing module 304 is used to batch read each batch of message data from the preset blocking queue every preset waiting time, create an actual consumer thread in the preset consumer thread pool, and perform business processing on each batch of message data through the actual consumer thread.
[0065] Furthermore, each batch of message data is stored in the blockchain database, which is not specifically limited here.
[0066] In the embodiment of the present invention, a business switch and a business message queue are created in the message middleware according to the environment configuration object through a preset consumer tool class, which reduces the development cost and business maintenance cost, and improves the business maintenance efficiency and code readability. By creating an actual consumer thread in a preset consumer thread pool, calling the actual consumer thread to batch consume each batch of message data in the blocking queue, the server resource consumption and pressure are reduced, and the message processing efficiency is improved.
[0067] See also Figure 4 Another embodiment of the message processing device in the embodiment of the present invention includes:
[0068] The generation module 301 is used to instantiate the environment configuration object, generate the service switch and the service message queue according to the environment configuration object through the preset consumer tool class, and establish a corresponding binding relationship between the service switch and the service message queue, and the service message queue is a real-time message queue or a delayed message queue;
[0069] The input module 302 is used to input the produced message to the business switch through the preset message middleware, and input the produced message to the business message queue through the business switch according to the binding relationship. When the produced message is waiting for the preset delayed sending time in the delayed message queue, the produced message with the delayed sending time expired is input to the real-time message queue. The delayed sending time corresponding to the same delayed message queue is the same.
[0070] The cache module 303 is used to receive at least one produced message pushed by the real-time message queue through a preset subscriber, and cache the at least one produced message in a preset blocking queue;
[0071] The processing module 304 is used to batch read each batch of message data from the preset blocking queue every preset waiting time, create an actual consumer thread in the preset consumer thread pool, and perform business processing on each batch of message data through the actual consumer thread.
[0072] Optionally, the generating module 301 may also be specifically used for:
[0073] Instantiate the environment configuration object and start the preset consumer tool class. The environment configuration object includes the preset real-time switch name, the preset real-time message queue name, the preset delayed switch name, the preset delayed message queue name and the preset delayed sending time. The preset delayed sending time corresponds to the preset queue sequence number rule one by one.
[0074] Generate a service switch and a service message queue through a preset consumer tool class according to a preset real-time switch name, a preset delayed switch name, a preset real-time message queue name, and a preset delayed message queue name, wherein the service switch includes a real-time switch and a delayed switch, and the service message queue includes a real-time message queue and a delayed message queue;
[0075] Based on the preset queue sequence number rule and the delayed sending duration corresponding to the queue sequence number rule, the delay sequence number and delay parameters of the delayed message queue are set respectively, and a corresponding binding relationship is established between the service switch and the service message queue.
[0076] Optionally, the input module 302 may also be specifically used for:
[0077] Receive the produced message sent by the preset producer tool class, and transmit the produced message to the business switch through the preset message middleware. The produced message carries the expected consumption time, which is used to indicate whether the produced message is a real-time message or a delayed message.
[0078] Determine the message category corresponding to the produced message based on the expected consumption time, and match the corresponding target switch from the service switch according to the message category. The target switch is a real-time switch or a delayed switch.
[0079] The generated message is transmitted to the corresponding business message queue through the target switch according to the binding relationship. The delayed sending time corresponding to the same delayed message queue is the same;
[0080] When a produced message is waiting for a preset delayed sending time in a delayed message queue, the produced message whose delayed sending time expires is transmitted to the real-time switch, and the produced message whose delayed sending time expires is stored in the real-time message queue through the real-time switch.
[0081] Optionally, the cache module 303 may also be specifically used for:
[0082] Receive at least one produced message pushed by the real-time message queue through a preset subscriber, and convert the data format of each produced message to obtain a converted message data set;
[0083] The converted message data set is written into a preset blocking queue, which is a memory buffer.
[0084] Optionally, the processing module 304 may also be specifically configured to:
[0085] At preset waiting time intervals, each batch of message data is read from the preset blocking queue according to the preset maximum consumption quantity of each batch, and the quantity of each batch of message data is less than or equal to the preset maximum consumption quantity of each batch;
[0086] According to the preset maximum number of consumer threads, actual consumer threads are created in the preset consumer thread pool, and each batch of message data is processed by the actual consumer threads to obtain the processing results, which are sent to the message middleware so that the message middleware passes the message status corresponding to each produced message.
[0087] Optionally, the message processing device further includes:
[0088] The scanning module 305 is used to periodically scan the environment configuration object through a preset configuration change thread;
[0089] The change module 306 is used to obtain the changed environment configuration object when it is detected that the environment configuration object has a configuration information change, and to pass the subscription status corresponding to the preset subscriber according to the changed environment configuration object, and to change the preset consumer thread pool size.
[0090] Optionally, the message processing device further includes:
[0091] Initialization module 307, used to initialize the link identifier of the actual consumer thread;
[0092] The recording module 308 is used to record all consumption process data of the actual consumer thread into a preset current thread local variable and a preset log printing object respectively based on the link identifier of the actual consumer thread.
[0093] In the embodiment of the present invention, a business switch and a business message queue are created in the message middleware according to the environment configuration object through a preset consumer tool class, which reduces the development cost and business maintenance cost, and improves the business maintenance efficiency and code readability. By creating an actual consumer thread in a preset consumer thread pool, calling the actual consumer thread to batch consume each batch of message data in the blocking queue, the server resource consumption and pressure are reduced, and the message processing efficiency is improved.
[0094] above Figure 3 and Figure 4 The message processing apparatus in the embodiment of the present invention is described in detail from the perspective of modularization. The message processing device in the embodiment of the present invention is described in detail from the perspective of hardware processing.
[0095] Figure 5 : is a structural diagram of a message processing device provided by an embodiment of the present invention. The message processing device 500 may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) 510 (for example, one or more processors) and a memory 520, and one or more storage media 530 (for example, one or more mass storage devices) storing application programs 533 or data 532. Among them, the memory 520 and the storage medium 530 can be short-term storage or permanent storage. The program stored in the storage medium 530 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the message processing device 500. Furthermore, the processor 510 can be configured to communicate with the storage medium 530 to execute a series of instruction operations in the storage medium 530 on the message processing device 500.
[0096] The message processing device 500 may also include one or more power supplies 540, one or more wired or wireless network interfaces 550, one or more input and output interfaces 560, and / or one or more operating systems 531, such as Windows Serve, Mac OS X, Unix, Linux, FreeBSD, etc. It will be appreciated by those skilled in the art that Figure 5 The structure of the message processing device shown does not constitute a limitation on the message processing device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0097] The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are executed on a computer, the computer executes the steps of the message processing method.
[0098] The present invention also provides a message processing device, which includes a memory and a processor. The memory stores instructions, and when the instructions are executed by the processor, the processor executes the steps of the message processing method in the above embodiments.
[0099] Furthermore, the computer-readable storage medium may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function, etc.; the data storage area may store data created according to the use of the blockchain node, etc.
[0100] The blockchain referred to in this invention is a new application mode of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0101] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0102] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program codes.
[0103] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A message processing method, characterized in that: The message processing method comprises: Instantiate an environment configuration object, generate a service switch and a service message queue according to the environment configuration object through a preset consumer tool class, and establish a corresponding binding relationship between the service switch and the service message queue, wherein the service message queue is a real-time message queue or a delayed message queue; Receive a produced message sent by a preset producer tool class, and pass the produced message to the business switch through a preset message middleware, wherein the produced message carries an expected consumption time limit, and the expected consumption time limit is used to indicate whether the produced message is a real-time message or a delayed message; determine the message category corresponding to the produced message based on the expected consumption time limit, and match the corresponding target switch from the business switch according to the message category, wherein the target switch is a real-time switch or a delayed switch; pass the produced message to the corresponding business message queue through the target switch according to the binding relationship, and the delayed sending time corresponding to the same delayed message queue is the same; when the produced message waits for a preset delayed sending time limit in the delayed message queue, pass the produced message with the expired delayed sending time limit to the real-time switch, and store the produced message with the expired delayed sending time limit into the real-time message queue through the real-time switch; Receiving at least one produced message pushed by the real-time message queue through a preset subscriber, and caching the at least one produced message in a preset blocking queue; Each batch of message data is read in batches from the preset blocking queue at preset waiting time intervals, an actual consumer thread is created in a preset consumer thread pool, and business processing is performed on each batch of message data through the actual consumer thread.
2. The message processing method according to claim 1, characterized in that: The instantiated environment configuration object generates a service switch and a service message queue according to the environment configuration object through a preset consumer tool class, and establishes a corresponding binding relationship between the service switch and the service message queue, wherein the service message queue is a real-time message queue or a delayed message queue, including: Instantiate an environment configuration object and start a preset consumer tool class, wherein the environment configuration object includes a preset real-time switch name, a preset real-time message queue name, a preset delayed switch name, a preset delayed message queue name, and a preset delayed sending duration, wherein the preset delayed sending duration corresponds to a preset queue sequence number rule one by one; Generate a service switch and a service message queue through the preset consumer tool class according to the preset real-time switch name, the preset delayed switch name, the preset real-time message queue name and the preset delayed message queue name, wherein the service switch includes a real-time switch and a delayed switch, and the service message queue includes a real-time message queue and a delayed message queue; Based on the preset queue sequence number rule and the delayed sending duration corresponding to the queue sequence number rule, the delay sequence number and delay parameters of the delayed message queue are set respectively, and a corresponding binding relationship is established between the service switch and the service message queue.
3. The message processing method according to claim 1, characterized in that: The receiving at least one produced message pushed by the real-time message queue through a preset subscriber, and caching the at least one produced message in a preset blocking queue, includes: Receive at least one produced message pushed by the real-time message queue through a preset subscriber, and perform data format conversion on each produced message to obtain a converted message data set; The converted message data set is written into a preset blocking queue, which is a memory buffer.
4. The message processing method according to claim 1, characterized in that: The method comprises: reading each batch of message data from the preset blocking queue in batches at preset waiting time intervals, creating an actual consumer thread in a preset consumer thread pool, and performing business processing on each batch of message data through the actual consumer thread, including: At preset waiting time intervals, each batch of message data is read from the preset blocking queue in batches according to the preset maximum consumption quantity per batch, and the quantity of each batch of message data is less than or equal to the preset maximum consumption quantity per batch; An actual consumer thread is created in a preset consumer thread pool according to the preset maximum number of consumer threads, and each batch of message data is processed by the actual consumer thread to obtain a processing result, and the processing result is sent to the message middleware, so that the message middleware passes in the message status corresponding to each produced message.
5. The message processing method according to any one of claims 1 to 4, characterized in that: After each batch of message data is read from the preset blocking queue at each preset waiting time, an actual consumer thread is created in a preset consumer thread pool, and each batch of message data is processed by the actual consumer thread, the message processing method further includes: Periodically scanning the environment configuration object through a preset configuration change thread; When it is detected that the environment configuration object has a configuration information change, the changed environment configuration object is obtained, and the subscription status corresponding to the preset subscriber is passed in according to the changed environment configuration object, and the preset consumer thread pool size is changed.
6. The message processing method according to any one of claims 1 to 4, characterized in that: After each batch of message data is read from the preset blocking queue at each preset waiting time, an actual consumer thread is created in a preset consumer thread pool, and each batch of message data is processed by the actual consumer thread, the message processing method further includes: Initialize the link identifier of the actual consumer thread; Based on the link identifier of the actual consumer thread, all consumption process data of the actual consumer thread are recorded in a preset current thread local variable and a preset log printing object respectively.
7. A message processing device, characterized in that: The message processing device comprises: A generation module, used to instantiate an environment configuration object, generate a service switch and a service message queue according to the environment configuration object through a preset consumer tool class, and establish a corresponding binding relationship between the service switch and the service message queue, wherein the service message queue is a real-time message queue or a delayed message queue; An input module is used to receive a produced message sent by a preset producer tool class, and to input the produced message into the business switch through a preset message middleware, wherein the produced message carries an expected consumption time limit, and the expected consumption time limit is used to indicate whether the produced message is a real-time message or a delayed message; based on the expected consumption time limit, a message category corresponding to the produced message is determined, and a corresponding target switch is matched from the business switch according to the message category, wherein the target switch is a real-time switch or a delayed switch; the produced message is input into the corresponding business message queue through the target switch according to the binding relationship, and the delayed sending time corresponding to the same delayed message queue is the same; when the produced message is waiting for a preset delayed sending time limit in the delayed message queue, the produced message with the expired delayed sending time limit is input into the real-time switch, and the produced message with the expired delayed sending time limit is stored into the real-time message queue through the real-time switch; A cache module, used for receiving at least one produced message pushed by the real-time message queue through a preset subscriber, and caching the at least one produced message in a preset blocking queue; The processing module is used to batch read each batch of message data from the preset blocking queue every preset waiting time, create an actual consumer thread in a preset consumer thread pool, and perform business processing on each batch of message data through the actual consumer thread.
8. A message processing device, characterized in that: The message processing device comprises: a memory and at least one processor, wherein instructions are stored in the memory; The at least one processor calls the instruction in the memory so that the message processing device executes the message processing method according to any one of claims 1 to 6.
9. A computer-readable storage medium having instructions stored thereon, characterized in that: When the instructions are executed by the processor, the message processing method according to any one of claims 1 to 6 is implemented.
