CN116546055A - Service message processing method and device, storage medium and electronic device - Google Patents
Service message processing method and device, storage medium and electronic device Download PDFInfo
- Publication number
- CN116546055A CN116546055A CN202310658412.3A CN202310658412A CN116546055A CN 116546055 A CN116546055 A CN 116546055A CN 202310658412 A CN202310658412 A CN 202310658412A CN 116546055 A CN116546055 A CN 116546055A
- Authority
- CN
- China
- Prior art keywords
- message
- messages
- service messages
- service
- sub
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000003672 processing method Methods 0.000 title description 8
- 238000012545 processing Methods 0.000 claims abstract description 90
- 238000000034 method Methods 0.000 claims abstract description 57
- 238000004590 computer program Methods 0.000 claims description 9
- 230000004044 response Effects 0.000 claims description 6
- 238000012795 verification Methods 0.000 claims description 6
- 238000010586 diagram Methods 0.000 description 10
- 230000002045 lasting effect Effects 0.000 description 4
- 230000005540 biological transmission Effects 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 238000005406 washing Methods 0.000 description 2
- XLYOFNOQVPJJNP-UHFFFAOYSA-N water Substances O XLYOFNOQVPJJNP-UHFFFAOYSA-N 0.000 description 2
- 230000006978 adaptation Effects 0.000 description 1
- 238000004140 cleaning Methods 0.000 description 1
- 238000010411 cooking Methods 0.000 description 1
- 238000013500 data storage Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000002688 persistence Effects 0.000 description 1
- 239000011435 rock Substances 0.000 description 1
- 239000000779 smoke Substances 0.000 description 1
- 238000010408 sweeping Methods 0.000 description 1
- 238000012546 transfer Methods 0.000 description 1
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/12—Protocols specially adapted for proprietary or special-purpose networking environments, e.g. medical networks, sensor networks, networks in vehicles or remote metering networks
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/28—Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
- H04L12/2803—Home automation networks
- H04L12/2816—Controlling appliance services of a home automation network by calling their functionalities
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L47/00—Traffic control in data switching networks
- H04L47/50—Queue scheduling
- H04L47/62—Queue scheduling characterised by scheduling criteria
- H04L47/6295—Queue scheduling characterised by scheduling criteria using multiple queues, one for each individual QoS, connection, flow or priority
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/50—Network services
- H04L67/60—Scheduling or organising the servicing of application requests, e.g. requests for application data transmissions using the analysis and optimisation of the required network resources
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D30/00—Reducing energy consumption in communication networks
- Y02D30/50—Reducing energy consumption in communication networks in wire-line communication networks, e.g. low power modes or reduced link rate
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Health & Medical Sciences (AREA)
- Computing Systems (AREA)
- General Health & Medical Sciences (AREA)
- Medical Informatics (AREA)
- Automation & Control Theory (AREA)
- Computer And Data Communications (AREA)
Abstract
The application discloses a method and a device for processing service messages, a storage medium and an electronic device, and relates to the technical field of smart families, wherein the method for processing the service messages comprises the following steps: responding to a consumption request initiated by a consumption terminal, and acquiring an order message carried in the consumption request; storing a plurality of groups of service messages obtained by grouping the order messages into different message queues, wherein each message queue stores a group of service messages; aiming at each message queue, a plurality of threads called from a thread pool are used for carrying out parallel processing on the sub-service messages in each message queue, and the technical problem of how to improve the processing efficiency of the service messages is solved by adopting the technical scheme.
Description
Technical Field
The present application relates to the technical field of smart home, and in particular, to a method and apparatus for processing a service message, a storage medium, and an electronic device.
Background
At present, with the continuous update of intelligent household appliance technology, the business demand of people on intelligent household appliances is continuously increased, so that the probability of occurrence of business peaks of intelligent household appliances is greatly increased. Because during the service peak of the intelligent household appliance, the service message is often unable to be processed in time due to backlog of the service message, which reduces the processing information of the service message and affects the use experience of the user.
Accordingly, in the related art, there is a technical problem of how to improve the processing efficiency of the service message.
Aiming at the technical problem of how to improve the processing efficiency of the service message in the related art, no effective solution is proposed yet.
Disclosure of Invention
The embodiment of the application provides a processing method, a device, a storage medium and an electronic device for service messages, which are used for at least solving the technical problem of how to improve the processing efficiency of the service messages in the related technology.
According to an embodiment of the present application, there is provided a method for processing a service message, including: responding to a consumption request initiated by a consumption terminal, and acquiring an order message carried in the consumption request; storing a plurality of groups of service messages obtained by grouping the order messages into different message queues, wherein each message queue stores a group of service messages; for each message queue, sub-service messages in each message queue are processed in parallel by using a plurality of threads called from a thread pool.
In one exemplary embodiment, the plurality of sets of service messages are obtained by: acquiring a first numerical value corresponding to the number of the preset groups of the order message, and determining identification information contained in the order message; carrying out hash encryption on the identification information to obtain a hash value of the identification information; and performing remainder taking operation on the first numerical value by using the hash value to obtain a residual value, and grouping the order information according to the residual value to obtain the plurality of groups of business information.
In an exemplary embodiment, grouping the order messages according to the remainder value to obtain the plurality of sets of service messages includes: under the condition that the order message contains different identification information, obtaining a plurality of residual values corresponding to hash values of the different identification information; obtaining a group of identical residuals in the plurality of residuals, wherein the group of identical residuals at least comprises two identical residuals; determining a group of business messages corresponding to the same residual value from the order message; and aiming at a plurality of groups of identical residual values in the plurality of residual values, obtaining the plurality of groups of service messages.
In an exemplary embodiment, storing the plurality of sets of service messages grouped into the order messages in different message queues includes: acquiring the same identification information corresponding to the hash value with the same residual value from all the identification information contained in the order message; determining the same group of service messages containing the same identification information, and storing the same group of service messages into the same message queue; and/or, for different groups of service messages respectively containing different identification information, respectively storing the different groups of service messages into different message queues.
In an exemplary embodiment, after storing the plurality of sets of service messages obtained by grouping the order messages in different message queues, the method further comprises: acquiring sub-service messages of a group of service messages stored in each message queue; carrying out service rule verification on the sub-service messages in each message queue, wherein the service rule represents the legality of the execution sequence of the sub-service messages, and the execution sequence of the sub-service messages is consistent with the generation sequence of the sub-service messages; and under the condition that the fact that sub-business messages in any one of the different message queues are not verified by the business rules is determined, sending a prompt message to the consumer, wherein the prompt message is used for prompting that the sub-business messages in any one of the message queues are not verified by the business rules.
In an exemplary embodiment, the parallel processing of the sub-service messages in each message queue using the plurality of threads includes: determining a second value corresponding to the queue length of each message queue and a third value corresponding to the number of sub-service messages in each message queue; determining the processing sequence of the sub-service messages in each message queue according to the enqueuing time of the sub-service messages in each message queue under the condition that the second value is not smaller than the third value; and processing the sub-business messages in each message queue in parallel by using the threads based on the processing sequence.
In an exemplary embodiment, the parallel processing of the sub-service messages in each message queue using the plurality of threads includes: determining the dequeue time of the sub-service messages in each message queue according to the enqueue time of the sub-service messages in each message queue; sequentially taking out the sub-service messages in each message queue based on the sequence of the dequeue time; after the sub-service messages in each message queue are sequentially taken out, determining a fourth value corresponding to the number of the sub-service messages in each message queue and a fifth value corresponding to the length of each message queue; determining the processing sequence of the sub-service messages in each message queue according to the enqueuing time of the sub-service messages in each message queue under the condition that the fifth value is larger than the fourth value; and processing the sub-business messages in each message queue in parallel by using the threads based on the processing sequence.
According to another embodiment of the embodiments of the present application, there is also provided a processing apparatus for a service message, including: the request response module is used for responding to a consumption request initiated by a consumption end and acquiring an order message carried in the consumption request; the message storage module is used for storing a plurality of groups of service messages obtained by grouping the order messages into different message queues, wherein each message queue stores a group of service messages; and the parallel processing module is used for processing the sub-business messages in each message queue in parallel by using a plurality of threads called from the thread pool aiming at each message queue.
According to yet another aspect of the embodiments of the present application, there is also provided a computer readable storage medium having a computer program stored therein, wherein the computer program is configured to perform the above-mentioned method of processing a service message when running.
According to still another aspect of the embodiments of the present application, there is further provided an electronic device, including a memory, a processor, and a computer program stored on the memory and capable of running on the processor, where the processor executes the method for processing a service message according to the foregoing computer program.
In the embodiment of the application, in response to a consumption request initiated by a consumption terminal, an order message carried in the consumption request is acquired; storing a plurality of groups of service messages obtained by grouping the order messages into different message queues, wherein each message queue stores a group of service messages; for each message queue, carrying out parallel processing on sub-service messages in each message queue by using a plurality of threads called from a thread pool; by adopting the technical scheme, the technical problem of how to improve the processing efficiency of the service message is solved, and the processing efficiency of the service message is further improved.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the application and together with the description, serve to explain the principles of the application.
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings that are required to be used in the description of the embodiments or the prior art will be briefly described below, and it will be obvious to those skilled in the art that other drawings can be obtained from these drawings without inventive effort.
Fig. 1 is a schematic diagram of a hardware environment of a method for processing a service message according to an embodiment of the present application;
FIG. 2 is a flow chart of a method of processing a business message according to an embodiment of the present application;
FIG. 3 is a schematic diagram (one) of a method for processing a service message according to an embodiment of the present application;
fig. 4 is a schematic diagram (ii) of a method for processing a service message according to an embodiment of the present application;
FIG. 5 is a schematic diagram of a message queue according to an embodiment of the present application;
FIG. 6 is a flow diagram of a method of processing a business message according to an embodiment of the present application;
fig. 7 is a block diagram of a service message processing apparatus according to an embodiment of the present application.
Detailed Description
In order to make the present application solution better understood by those skilled in the art, the following description will be made in detail and with reference to the accompanying drawings in the embodiments of the present application, it is apparent that the described embodiments are only some embodiments of the present application, not all embodiments. All other embodiments, which can be made by one of ordinary skill in the art based on the embodiments herein without making any inventive effort, shall fall within the scope of the present application.
It should be noted that the terms "first," "second," and the like in the description and claims of the present application and the above figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that embodiments of the present application described herein may be implemented in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
According to one aspect of the embodiments of the present application, a method for processing a service message is provided. The business message processing method is widely applied to full-house intelligent digital control application scenes such as intelligent Home (Smart Home), intelligent Home equipment ecology, intelligent Home (Intelligence House) ecology and the like. Alternatively, in the present embodiment, the above-described processing method of the service message may be applied to a hardware environment constituted by the terminal device 102 and the server 104 as shown in fig. 1. As shown in fig. 1, the server 104 is connected to the terminal device 102 through a network, and may be used to provide services (such as application services and the like) for a terminal or a client installed on the terminal, a database may be set on the server or independent of the server, for providing data storage services for the server 104, and cloud computing and/or edge computing services may be configured on the server or independent of the server, for providing data computing services for the server 104.
The network may include, but is not limited to, at least one of: wired network, wireless network. The wired network may include, but is not limited to, at least one of: a wide area network, a metropolitan area network, a local area network, and the wireless network may include, but is not limited to, at least one of: WIFI (Wireless Fidelity ), bluetooth. The terminal device 102 may not be limited to a PC, a mobile phone, a tablet computer, an intelligent air conditioner, an intelligent smoke machine, an intelligent refrigerator, an intelligent oven, an intelligent cooking range, an intelligent washing machine, an intelligent water heater, an intelligent washing device, an intelligent dish washer, an intelligent projection device, an intelligent television, an intelligent clothes hanger, an intelligent curtain, an intelligent video, an intelligent socket, an intelligent sound box, an intelligent fresh air device, an intelligent kitchen and toilet device, an intelligent bathroom device, an intelligent sweeping robot, an intelligent window cleaning robot, an intelligent mopping robot, an intelligent air purifying device, an intelligent steam box, an intelligent microwave oven, an intelligent kitchen appliance, an intelligent purifier, an intelligent water dispenser, an intelligent door lock, and the like.
In this embodiment, a method for processing a service message is provided and applied to the terminal device, and fig. 2 is a flowchart of a method for processing a service message according to an embodiment of the present application, where the flowchart includes the following steps:
step S202, responding to a consumption request initiated by a consumption end, and acquiring an order message carried in the consumption request;
step S204, storing a plurality of groups of service messages obtained by grouping the order messages into different message queues, wherein each message queue stores a group of service messages;
step S206, for each message queue, using a plurality of threads called from the thread pool to process the sub-business messages in each message queue in parallel.
Through the steps, an order message carried in a consumption request is obtained in response to the consumption request initiated by a consumption terminal; storing a plurality of groups of service messages obtained by grouping the order messages into different message queues, wherein each message queue stores a group of service messages; aiming at each message queue, a plurality of threads called from a thread pool are used for carrying out parallel processing on the sub-service messages in each message queue, so that the technical problem of how to improve the processing efficiency of the service messages in the related technology is solved, and the processing efficiency of the service messages is further improved.
In one exemplary embodiment, the plurality of sets of service messages may be obtained by: acquiring a first numerical value corresponding to the number of the preset groups of the order message, and determining identification information contained in the order message; carrying out hash encryption on the identification information to obtain a hash value of the identification information; and performing remainder taking operation on the first numerical value by using the hash value to obtain a residual value, and grouping the order information according to the residual value to obtain the plurality of groups of business information.
The identification information included in the order message is a unique identification of the order message, and may be understood as an order number of the order message, for example.
For the above process of performing the remainder operation on the first value by using the hash value to obtain the remainder value, for example, if the first value is 50, performing the remainder operation on 50 by using the hash value, that is, hash%50, and if hash% 50=0, determining the order message corresponding to the hash value with the remainder value of 0 as a set of service messages.
In an exemplary embodiment, further, for the process of grouping the order messages according to the residual value to obtain the multiple sets of service messages, the following implementation steps are proposed: step S11, when the order message contains different identification information, a plurality of residual values corresponding to hash values of the different identification information are obtained; step S12, obtaining a group of identical residual values in the plurality of residual values, wherein the group of identical residual values at least comprises two identical residual values; step S13, a group of business messages corresponding to the same group of residual values are determined from the order messages; step S14, aiming at a plurality of groups of identical residual values in the plurality of residual values, obtaining the plurality of groups of service messages.
Optionally, for the same remainder, corresponding to the same identification information; alternatively, the order message may be divided into multiple sets of service messages according to different residual values according to the embodiment.
In an exemplary embodiment, further, there is further provided an implementation scheme for storing multiple sets of service messages obtained by grouping the order messages into different message queues, including the specific steps of: step S21, obtaining the same identification information corresponding to the hash value with the same residual value from all the identification information contained in the order message; step S22, determining the same group of service messages containing the same identification information, and storing the same group of service messages into the same message queue; step S23, and/or, for different sets of service messages respectively including different identification information, storing the different sets of service messages to different message queues respectively.
In an exemplary embodiment, after the technical solution of storing the multiple sets of service messages obtained by grouping the order messages in different message queues in the step S204 is performed, the following procedure is further provided: acquiring sub-service messages of a group of service messages stored in each message queue; carrying out service rule verification on the sub-service messages in each message queue, wherein the service rule represents the legality of the execution sequence of the sub-service messages, and the execution sequence of the sub-service messages is consistent with the generation sequence of the sub-service messages; and under the condition that the fact that sub-business messages in any one of the different message queues are not verified by the business rules is determined, sending a prompt message to the consumer, wherein the prompt message is used for prompting that the sub-business messages in any one of the message queues are not verified by the business rules.
Under the condition that the fact that sub-business messages in any one of the different message queues are not verified by the business rule is determined, sub-business messages in other message queues can be stored in a lasting mode; wherein the other message queues represent message queues of the different message queues divided by the any one message queue.
And under the condition that the service messages in each message queue pass the service rule verification, the service messages in the different message queues are stored in a lasting mode.
In an exemplary embodiment, for the process of using the multiple threads to process the sub-service messages in each message queue in parallel in the step S206, the following steps may be specifically implemented: step S31, determining a second value corresponding to the queue length of each message queue and a third value corresponding to the number of sub-service messages in each message queue; step S32, under the condition that the second value is not smaller than the third value, determining the processing sequence of the sub-service messages in each message queue according to the enqueuing time of the sub-service messages in each message queue; and step S33, the sub-business messages in each message queue are processed in parallel by using the threads based on the processing sequence.
The process of determining the processing sequence of the service message in each message queue according to the enqueuing time of the service message in each message queue may be understood as determining the processing sequence of the service message in each message queue according to the sequence of the enqueuing time of the service message in each message queue, for example, the earlier the enqueuing time is, the earlier the processing sequence is.
In an exemplary embodiment, the above technical solution of using the multiple threads to process the sub-service messages in each message queue in parallel in step S206 may further include the following implementation steps: step S41, determining the dequeue time of the sub-service messages in each message queue according to the enqueue time of the sub-service messages in each message queue; step S42, sub-service messages in each message queue are sequentially taken out based on the sequence of the dequeue time; step S43, after the sub-service messages in each message queue are sequentially fetched, determining a fourth value corresponding to the number of the sub-service messages in each message queue and a fifth value corresponding to the length of each message queue; step S44, determining the processing sequence of the sub-service messages in each message queue according to the enqueuing time of the sub-service messages in each message queue under the condition that the fifth value is larger than the fourth value; and step S45, the sub-business messages in each message queue are processed in parallel by using the threads based on the processing sequence.
In order to better understand the process of the service message processing method, the implementation method flow of the service message processing is described below in conjunction with the optional embodiment, but is not limited to the technical solution of the embodiment of the present application.
In this embodiment, a method for processing a service message is provided, fig. 3 is a schematic diagram (one) of a method for processing a service message according to an embodiment of the present application, as shown in fig. 3, a plurality of consumers (i.e. consumers b, c, d of fig. 3) are deployed on a rock mq cloud end as a consumer group, one consumer group subscribes to the same Topic (Topic), and for an order message, the service message "order creation, order payment, order completion" can be obtained based on the order generation order "create order- > order completion". For each consumption end, there is a corresponding service end to orderly consume the service message, specifically, for the service message of 'order creation, order payment, order completion', each consumption end also needs to consume according to the order. And simultaneously, for a plurality of order messages generated by a group of consumers, parallel consumption can be realized by using a plurality of corresponding consumers.
For a dockmq cloud server, the following concepts need to be described:
1. message (Message): representing the physical carrier of the information transfer.
2. Theme (Topic): is the basic unit of the RocketMQ for subscribing the messages, and represents a set of one type of messages, the same topic can contain a plurality of messages, and one consumer can subscribe and consume the messages of the same topic only.
3. Message Queue (Queue): representing the physical entity of the message store.
4. Message identification (key): the unique identification associated with the business specified by the user, for example, for an order message, the message identification may be understood as the order number of the order message.
In this embodiment, a method for processing a service message is provided, fig. 4 is a schematic diagram (two) of a method for processing a service message according to an embodiment of the present application, and as shown in fig. 4, taking consumer side consumer c as an example, grouping order messages. The message identification (i.e., the identification information described above) of the order message is obtained, with the estimated grouping being 80 groups. Encrypting the message identifier according to the MD5 algorithm, obtaining a hash value of the message identifier, and modulo the hash value and 80 to obtain the remainder value with the value range of [0, 79 ]. If hash% 80=1, the corresponding order message is determined to be a set of service messages and stored to the redisqueue_1 queue. If hash% 80=0, the corresponding order message is determined to be a set of service messages and stored in the redisqueue_0 queue.
In one embodiment, the sub-service messages stored in the message queue are described in conjunction with fig. 5, and fig. 5 is a schematic diagram of the message queue according to an embodiment of the present application, where the message queue includes sub-service messages such as "order 1 create", "order 1 pay", "order 1 complete", and the like, as shown in fig. 5. And storing the received service message into the message queue from the tail of the message queue according to the principle of right-in and left-out, and carrying out persistence on the message queue. When the sub-service messages need to be fetched from the message queue, sub-service messages such as 'order 1 creation', 'order 1 payment', 'order 1 completion' and the like are fetched from the head of the message queue in sequence.
Further, after fetching the sub-service message, the multithreading scheduling module may be used to invoke multiple threads from the thread pool, thereby using multiple sub-service messages for parallel processing. For example, 80 threads are started, each thread is assigned a message queue, and then service logic is sequentially executed for the 80 message queues of redis_queue_0 through redis_queue_79, each message queue having assigned threads to process sub-service messages according to the first-in-first-out queue characteristics.
In this embodiment, each time a sub-service message is completed, it is popped from the queue. And for each message queue, scanning is continued, and each service message is stored in the message queue and is processed.
According to the embodiment, the service message is efficiently processed through the threads, so that service message consumption and a service message processing process are decoupled, backlog probability of the service message is reduced, and the processing efficiency of the service message is improved.
Compared with the processing method of the service message provided in fig. 3, the processing method of the service message provided in fig. 4 can simultaneously use a plurality of threads to process the service message in parallel when the service execution time is longer or the service is at a peak, thereby improving the execution efficiency.
In one embodiment, fig. 6 is a flowchart of a method for processing a service message according to an embodiment of the present application, as shown in fig. 6, after the system service is started, steps S601 to S607, and steps S602 to S606 may be performed simultaneously until the system service is stopped.
Specifically, steps S601 to S607 are as follows:
step S601, starting a multithreading task;
step S603, using a plurality of threads to process the sub-business messages in the message queue in parallel;
step S605, popping the processed sub-business messages from the head of the message queue in turn;
in step S607, business logic is executed.
Steps S602 to S606 are as follows:
step S602, subscribing the theme by the consumer;
step S604, the consumer receives the order information corresponding to the theme and divides the order information into a plurality of groups of business information; in step S604, the order message is divided into a plurality of groups of service messages according to the message identifier of the order message and the remainder result of the number of groups;
step S606, storing the multiple groups of service messages to multiple message queues. In this step, when each group of service messages is stored in the message queue, the service messages are stored in the message queue from the tail of the message queue according to the first-in first-out principle, so as to ensure that the sub-service messages at the tail of the message queue are stored most recently.
Through the steps, business message consumption and business message understanding are coupled, backlog probability of the business message is reduced, and execution efficiency of the business message is improved through multithreading processing of the business message.
From the description of the above embodiments, it will be clear to a person skilled in the art that the method according to the above embodiments may be implemented by means of software plus the necessary general hardware platform, but of course also by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk), comprising several instructions for causing a terminal device (which may be a mobile phone, a computer, a server, or a network device, etc.) to perform the method of the embodiments of the present application.
Fig. 7 is a block diagram of a service message processing apparatus according to an embodiment of the present application, as shown in fig. 7, including:
a request response module 72, configured to respond to a consumption request initiated by a consumption end, and obtain an order message carried in the consumption request;
a message storage module 74, configured to store a plurality of sets of service messages obtained by grouping the order messages into different message queues, where each message queue stores a set of service messages;
a parallel processing module 76, configured to, for each message queue, use a plurality of threads called from the thread pool to process sub-service messages in the message queue in parallel.
By the device, an order message carried in a consumption request is acquired in response to the consumption request initiated by a consumption terminal; storing a plurality of groups of service messages obtained by grouping the order messages into different message queues, wherein each message queue stores a group of service messages; aiming at each message queue, a plurality of threads called from a thread pool are used for carrying out parallel processing on the sub-service messages in each message queue, so that the technical problem of how to improve the processing efficiency of the service messages in the related technology is solved, and the processing efficiency of the service messages is further improved.
In an exemplary embodiment, the message storage module 74 further includes an obtaining unit configured to obtain the plurality of sets of service messages by: acquiring a first numerical value corresponding to the number of the preset groups of the order message, and determining identification information contained in the order message; carrying out hash encryption on the identification information to obtain a hash value of the identification information; and performing remainder taking operation on the first numerical value by using the hash value to obtain a residual value, and grouping the order information according to the residual value to obtain the plurality of groups of business information.
The identification information included in the order message is a unique identification of the order message, and may be understood as an order number of the order message, for example.
For the above process of performing the remainder operation on the first value by using the hash value to obtain the remainder value, for example, if the first value is 50, performing the remainder operation on 50 by using the hash value, that is, hash%50, and if hash% 50=0, determining the order message corresponding to the hash value with the remainder value of 0 as a set of service messages.
In an exemplary embodiment, further, the obtaining unit is further configured to perform the following implementation steps: step S11, when the order message contains different identification information, a plurality of residual values corresponding to hash values of the different identification information are obtained; step S12, obtaining a group of identical residual values in the plurality of residual values, wherein the group of identical residual values at least comprises two identical residual values; step S13, a group of business messages corresponding to the same group of residual values are determined from the order messages; step S14, aiming at a plurality of groups of identical residual values in the plurality of residual values, obtaining the plurality of groups of service messages.
Optionally, for the same remainder, corresponding to the same identification information; alternatively, the order message may be divided into multiple sets of service messages according to different residual values according to the embodiment.
In an exemplary embodiment, further, the obtaining unit is further configured to perform: step S21, obtaining the same identification information corresponding to the hash value with the same residual value from all the identification information contained in the order message; step S22, determining the same group of service messages containing the same identification information, and storing the same group of service messages into the same message queue; step S23, and/or, for different sets of service messages respectively including different identification information, storing the different sets of service messages to different message queues respectively.
In an exemplary embodiment, further, the processing apparatus for a service message further includes a sending module, configured to: acquiring sub-service messages of a group of service messages stored in each message queue; carrying out service rule verification on the sub-service messages in each message queue, wherein the service rule represents the legality of the execution sequence of the sub-service messages, and the execution sequence of the sub-service messages is consistent with the generation sequence of the sub-service messages; and under the condition that the fact that sub-business messages in any one of the different message queues are not verified by the business rules is determined, sending a prompt message to the consumer, wherein the prompt message is used for prompting that the sub-business messages in any one of the message queues are not verified by the business rules.
Under the condition that the fact that sub-business messages in any one of the different message queues are not verified by the business rule is determined, sub-business messages in other message queues can be stored in a lasting mode; wherein the other message queues represent message queues of the different message queues divided by the any one message queue.
And under the condition that the service messages in each message queue pass the service rule verification, the service messages in the different message queues are stored in a lasting mode.
In an exemplary embodiment, the parallel processing module 76 further includes a first processing unit for performing the following steps: step S31, determining a second value corresponding to the queue length of each message queue and a third value corresponding to the number of sub-service messages in each message queue; step S32, under the condition that the second value is not smaller than the third value, determining the processing sequence of the sub-service messages in each message queue according to the enqueuing time of the sub-service messages in each message queue; and step S33, the sub-business messages in each message queue are processed in parallel by using the threads based on the processing sequence.
The process of determining the processing sequence of the service message in each message queue according to the enqueuing time of the service message in each message queue may be understood as determining the processing sequence of the service message in each message queue according to the sequence of the enqueuing time of the service message in each message queue, for example, the earlier the enqueuing time is, the earlier the processing sequence is.
In an exemplary embodiment, the parallel processing module 76 further includes a second processing unit, configured to perform the following implementation steps: step S41, determining the dequeue time of the sub-service messages in each message queue according to the enqueue time of the sub-service messages in each message queue; step S42, sub-service messages in each message queue are sequentially taken out based on the sequence of the dequeue time; step S43, after the sub-service messages in each message queue are sequentially fetched, determining a fourth value corresponding to the number of the sub-service messages in each message queue and a fifth value corresponding to the length of each message queue; step S44, determining the processing sequence of the sub-service messages in each message queue according to the enqueuing time of the sub-service messages in each message queue under the condition that the fifth value is larger than the fourth value; and step S45, the sub-business messages in each message queue are processed in parallel by using the threads based on the processing sequence.
Embodiments of the present application also provide a storage medium including a stored program, wherein the program performs the method of any one of the above when run.
Alternatively, in the present embodiment, the above-described storage medium may be configured to store program code for performing the steps of:
s1, responding to a consumption request initiated by a consumption terminal, and acquiring an order message carried in the consumption request;
s2, storing a plurality of groups of service messages obtained by grouping the order messages into different message queues, wherein each message queue stores a group of service messages;
s3, for each message queue, using a plurality of threads called from the thread pool to process the sub-service messages in each message queue in parallel.
Embodiments of the present application also provide an electronic device comprising a memory having a computer program stored therein and a processor arranged to run the computer program to perform the steps of any of the method embodiments described above.
Optionally, the electronic apparatus may further include a transmission device and an input/output device, where the transmission device is connected to the processor, and the input/output device is connected to the processor.
Alternatively, in the present embodiment, the above-described processor may be configured to execute the following steps by a computer program:
s1, responding to a consumption request initiated by a consumption terminal, and acquiring an order message carried in the consumption request;
s2, storing a plurality of groups of service messages obtained by grouping the order messages into different message queues, wherein each message queue stores a group of service messages;
s3, for each message queue, using a plurality of threads called from the thread pool to process the sub-service messages in each message queue in parallel.
Alternatively, in the present embodiment, the storage medium may include, but is not limited to: a U-disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a removable hard disk, a magnetic disk, or an optical disk, or other various media capable of storing program codes.
Alternatively, specific examples in this embodiment may refer to examples described in the foregoing embodiments and optional implementations, and this embodiment is not described herein.
It will be appreciated by those skilled in the art that the modules or steps of the application described above may be implemented in a general purpose computing device, they may be centralized on a single computing device, or distributed across a network of computing devices, or they may alternatively be implemented in program code executable by computing devices, such that they may be stored in a memory device for execution by the computing devices and, in some cases, the steps shown or described may be performed in a different order than what is shown or described, or they may be implemented as individual integrated circuit modules, or as individual integrated circuit modules. Thus, the present application is not limited to any specific combination of hardware and software.
The foregoing is merely a preferred embodiment of the present application and it should be noted that modifications and adaptations to those skilled in the art may be made without departing from the principles of the present application and are intended to be comprehended within the scope of the present application.
Claims (10)
1. A method for processing a service message, comprising:
responding to a consumption request initiated by a consumption terminal, and acquiring an order message carried in the consumption request;
storing a plurality of groups of service messages obtained by grouping the order messages into different message queues, wherein each message queue stores a group of service messages;
for each message queue, sub-service messages in each message queue are processed in parallel by using a plurality of threads called from a thread pool.
2. The method for processing service messages according to claim 1, wherein said plurality of sets of service messages are obtained by:
acquiring a first numerical value corresponding to the number of the preset groups of the order message, and determining identification information contained in the order message;
carrying out hash encryption on the identification information to obtain a hash value of the identification information;
and performing remainder taking operation on the first numerical value by using the hash value to obtain a residual value, and grouping the order information according to the residual value to obtain the plurality of groups of business information.
3. The method for processing service messages according to claim 2, wherein grouping the order messages according to the remainder value to obtain the plurality of sets of service messages comprises:
under the condition that the order message contains different identification information, obtaining a plurality of residual values corresponding to hash values of the different identification information;
obtaining a group of identical residuals in the plurality of residuals, wherein the group of identical residuals at least comprises two identical residuals;
determining a group of business messages corresponding to the same residual value from the order message;
and aiming at a plurality of groups of identical residual values in the plurality of residual values, obtaining the plurality of groups of service messages.
4. The method for processing service messages according to claim 2, wherein storing the plurality of sets of service messages obtained by grouping the order messages in different message queues includes:
acquiring the same identification information corresponding to the hash value with the same residual value from all the identification information contained in the order message;
determining the same group of service messages containing the same identification information, and storing the same group of service messages into the same message queue;
and/or, for different groups of service messages respectively containing different identification information, respectively storing the different groups of service messages into different message queues.
5. The method of processing service messages according to claim 1, wherein after storing a plurality of sets of service messages obtained by grouping the order messages in different message queues, the method further comprises:
acquiring sub-service messages of a group of service messages stored in each message queue;
carrying out service rule verification on the sub-service messages in each message queue, wherein the service rule represents the legality of the execution sequence of the sub-service messages, and the execution sequence of the sub-service messages is consistent with the generation sequence of the sub-service messages;
and under the condition that the fact that sub-business messages in any one of the different message queues are not verified by the business rules is determined, sending a prompt message to the consumer, wherein the prompt message is used for prompting that the sub-business messages in any one of the message queues are not verified by the business rules.
6. The method for processing the service message according to claim 1, wherein the parallel processing of the sub-service messages in each message queue using the plurality of threads comprises:
determining a second value corresponding to the queue length of each message queue and a third value corresponding to the number of sub-service messages in each message queue;
determining the processing sequence of the sub-service messages in each message queue according to the enqueuing time of the sub-service messages in each message queue under the condition that the second value is not smaller than the third value;
and processing the sub-business messages in each message queue in parallel by using the threads based on the processing sequence.
7. The method for processing the service message according to claim 1, wherein the parallel processing of the sub-service messages in each message queue using the plurality of threads comprises:
determining the dequeue time of the sub-service messages in each message queue according to the enqueue time of the sub-service messages in each message queue;
sequentially taking out the sub-service messages in each message queue based on the sequence of the dequeue time;
after the sub-service messages in each message queue are sequentially taken out, determining a fourth value corresponding to the number of the sub-service messages in each message queue and a fifth value corresponding to the length of each message queue;
determining the processing sequence of the sub-service messages in each message queue according to the enqueuing time of the sub-service messages in each message queue under the condition that the fifth value is larger than the fourth value;
and processing the sub-business messages in each message queue in parallel by using the threads based on the processing sequence.
8. A service message processing apparatus, comprising:
the request response module is used for responding to a consumption request initiated by a consumption end and acquiring an order message carried in the consumption request;
the message storage module is used for storing a plurality of groups of service messages obtained by grouping the order messages into different message queues, wherein each message queue stores a group of service messages;
and the parallel processing module is used for processing the sub-business messages in each message queue in parallel by using a plurality of threads called from the thread pool aiming at each message queue.
9. A computer readable storage medium, characterized in that the computer readable storage medium comprises a stored program, wherein the program when run performs the method of any of the preceding claims 1 to 7.
10. An electronic device comprising a memory and a processor, characterized in that the memory has stored therein a computer program, the processor being arranged to execute the method according to any of the claims 1 to 7 by means of the computer program.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310658412.3A CN116546055A (en) | 2023-06-05 | 2023-06-05 | Service message processing method and device, storage medium and electronic device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310658412.3A CN116546055A (en) | 2023-06-05 | 2023-06-05 | Service message processing method and device, storage medium and electronic device |
Publications (1)
Publication Number | Publication Date |
---|---|
CN116546055A true CN116546055A (en) | 2023-08-04 |
Family
ID=87447174
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202310658412.3A Pending CN116546055A (en) | 2023-06-05 | 2023-06-05 | Service message processing method and device, storage medium and electronic device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN116546055A (en) |
-
2023
- 2023-06-05 CN CN202310658412.3A patent/CN116546055A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN104156246B (en) | The method and device of gray scale upgrading | |
CN109587178A (en) | A kind of intelligent appliance encryption control system and method based on MQTT | |
US8606908B2 (en) | Wake-up server | |
CN106331783B (en) | A kind of resource allocation methods, device and intelligent television system | |
CN114938365B (en) | Function module updating method and device, storage medium and electronic device | |
CN111988345A (en) | Information synchronization method and device | |
CN116546055A (en) | Service message processing method and device, storage medium and electronic device | |
EP4042359A1 (en) | Distributed network with consensus mechanism | |
CN116107975A (en) | Control method and device of equipment, storage medium and electronic device | |
CN116361155A (en) | Method and device for testing software development kit, storage medium and electronic device | |
CN115174512A (en) | Message pushing method and device, storage medium and electronic device | |
CN115296958B (en) | Distribution method and device of equipment control tasks, storage medium and electronic device | |
CN115174513B (en) | Message pushing method and device, storage medium and electronic device | |
CN112511579A (en) | Event notification method, system, server device, computer storage medium | |
CN116418613A (en) | Message reflow processing method and device, storage medium and electronic device | |
WO2024016506A1 (en) | Gateway device control method and apparatus, and storage medium and electronic apparatus | |
CN116436991A (en) | Data message sending method and device, storage medium and electronic equipment | |
CN114866802B (en) | Video stream sending method and device, storage medium and electronic device | |
Liu et al. | Cooper: Expedite Batch Data Dissemination in Computer Clusters with Coded Gossips | |
CN116301767A (en) | Interface file generation method and device, storage medium and electronic device | |
CN116405564A (en) | Access request processing method, processing device, storage medium and electronic device | |
CN116366671A (en) | Data synchronization method and device, storage medium and electronic device | |
CN116578618A (en) | Method and device for generating target reflow instance, storage medium and electronic device | |
CN117579410A (en) | Control command distribution method and device, storage medium and electronic device | |
CN117707488A (en) | Function response method and device, storage medium and electronic device |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |