A message queue processing method, device, equipment and storage medium
By parsing messages and establishing a doubly linked list queue in the MQTT client, combined with semaphore mechanism and time threshold management, the modularity and dynamic memory control issues of the MQTT client are solved, improving the flexibility and memory utilization efficiency of the message queue.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-02
- Publication Date
- 2026-03-27
AI Technical Summary
Existing MQTT client processing methods lack modularity, requiring modifications and coupling during porting or alteration. MQTT message queues also exhibit poor flexibility and cannot dynamically manage memory, leading to memory waste or overflow.
The messages are parsed and divided into request messages and requested messages. First and second message queues with a doubly linked list structure are established. The transmission type is determined and the corresponding message node is created. The message transmission is managed by a semaphore mechanism. Time thresholds are set for timeout monitoring and thread processing.
It improves the flexibility of MQTT message queues, makes better use of memory, reduces the coupling points of modification during porting and changes, provides a unified interface, and supports synchronous, asynchronous and timeout functions.
Smart Images

Figure CN115168066B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a message queue processing method and device, equipment and storage medium. BACKGROUND
[0002] Through the MQTT protocol, many MQTT server programs have been extended, such as basic connection, subscription, publishing, binding callback, disconnecting MQTT client programs, etc. However, the current client program only implements the basic functions described above, and cannot intelligently process messages such as synchronization, asynchronization, events, and timeout in actual production requirements.
[0003] The existing MQTT client processing method uses an array + function to realize the event, synchronization, asynchronization, and timeout processing of messages, or a general solution and idea is to use an array to store MQTT messages, and to realize the synchronization matching of MQTT messages by traversing or looping the array. For applications with a large number of messages, a simple message queue can be built, which can be based on list, queue templates to realize basic methods such as pop(), push(), etc.
[0004] However, the existing MQTT client processing method program is not strongly modularized, and is scattered in multiple files of the program. When porting or changing, there are many places that need to be modified and coupled, and it is difficult to debug. Moreover, the existing MQTT message queue has poor flexibility, and the memory occupation is fixed. When the number of messages is small, the memory is idle and wasted, and when the number of messages is large, it will overflow. Moreover, the operation mode is automatic traversal or loop, which is relatively backward. SUMMARY
[0005] Therefore, the present application provides a message queue processing method, device, equipment and storage medium, which solves the problems that the existing MQTT client processing method program needs to modify and couple many places when porting or changing, and is difficult to debug, and the MQTT message queue has poor flexibility and the memory cannot be dynamically regulated.
[0006] The present application provides a message queue processing method, which comprises the following steps:
[0007] Parsing the obtained message, dividing the message into a request message and a requested message, and creating a request message node and a requested message node;
[0008] Establishing a first message queue for storing messages and a second message queue for storing messages, the first message queue being used for storing the request message node, and the second message queue being used for storing the requested message node;
[0009] Determining whether the request message is a synchronous transmission message or an asynchronous transmission message;
[0010] If the request message is a synchronous delivery message, a synchronous message node is created and put into the first message queue, the first message node is sent and a reply signal is waited for, and the request message is processed according to the received reply signal;
[0011] If the request message is an asynchronous delivery message, an asynchronous message node is created and put into the first message queue, the second message node is sent, and a signal is sent to the next handler of the request message;
[0012] It is judged whether the waiting time of the requested message exceeds a first time threshold;
[0013] If the processing is in order within the first time threshold;
[0014] If the processing exceeds the first time threshold, thread processing is performed.
[0015] Further, the judgment of whether the request message is a synchronous delivery message or an asynchronous delivery message further comprises:
[0016] If the request message is a synchronous delivery message, a first semaphore is referenced when the synchronous message node is created and put into the first message queue, and the first semaphore is released after the request message is processed according to the received reply signal;
[0017] If the request message is an asynchronous delivery message, a second semaphore is referenced when the asynchronous message node is created and put into the first message queue, and the second semaphore is released when the second message node is sent and a signal is sent to the next handler of the request message.
[0018] Further, the creation of the synchronous message node and the putting into the first message queue if the request message is a synchronous delivery message, the sending of the first message node and the waiting for the reply signal, and the processing of the message according to the received reply signal further comprise:
[0019] The sent first message node is monitored for timeout, and if the first message node waits for a time exceeding a second time threshold without receiving a reply, the first message queue message node is discarded, and the synchronous semaphore is released.
[0020] Further, the second message queue comprises at least one message queue, and the requested message node is stored in different message queues comprised in the second message queue according to the message quality of the requested message.
[0021] Further, the first message queue and the second message queue are in a double-linked list structure.
[0022] The embodiment of the application further provides a message queue processing device, comprising:
[0023] The message parsing module is configured to parse the obtained message, divide the message into a request message and a requested message, and create a request message node and a requested message node.
[0024] The message queue construction module is configured to establish a first message queue for storing the request message node and a second message queue for storing the requested message node.
[0025] The first judgment module is configured to judge whether the request message is a synchronous transmission message or an asynchronous transmission message.
[0026] The synchronous transmission message processing module is configured to, when the request message is a synchronous transmission message, create a synchronous message node and put it into the first message queue, send the first message node and wait for a reply signal, and process the request message according to the received reply signal.
[0027] The asynchronous transmission message processing module is configured to, when the request message is an asynchronous transmission message, create an asynchronous message node and put it into the first message queue, send the second message node, and send a signal to a next processing program of the request message.
[0028] The second judgment module is configured to judge whether the waiting time length of the requested message exceeds a first time threshold.
[0029] The first processing module is configured to sequentially process the requested message when the waiting time length of the requested message is within the first time threshold.
[0030] The second processing module is configured to thread-process the requested message when the waiting time length of the requested message exceeds the first time threshold.
[0031] Further, the first judgment module further comprises,
[0032] The synchronous message node reference semaphore module is configured to, when the request message is a synchronous transmission message, create a synchronous message node and put it into the first message queue, reference a first semaphore, and release the first semaphore when the request message is processed according to the received reply signal.
[0033] The asynchronous message node reference semaphore module is configured to, when the request message is an asynchronous transmission message, create an asynchronous message node and put it into the first message queue, reference a second semaphore, and release the second semaphore when the second message node is sent and the signal is sent to the next processing program of the request message.
[0034] Further, the synchronous transmission message processing module further comprises,
[0035] The message node detection module is configured to monitor the first message node in a timeout manner, and if the first message node fails to receive a reply within a second time threshold, the first message queue message node is discarded, and the synchronization semaphore is released.
[0036] The embodiment of the present application also provides an electronic device, comprising a memory and a processor, wherein
[0037] The memory is configured to store program codes.
[0038] The processor is configured to call the program codes to implement the processing method of the message queue.
[0039] The embodiment of the present application also provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to enable an electronic device to perform the processing method of the message queue.
[0040] The processing method of the message queue provided by the present application comprises the steps that a message is parsed to divide the message into a request message and a requested message, and a request message node and a requested message node are created; the request message node is stored in a first message queue, and the requested message node is stored in a second message queue; when the request message is a synchronous transmission message, a synchronous message node is created and put into the first message queue, a first message node is sent and a reply signal is waited, and the request message is processed according to the received reply signal; when the request message is an asynchronous transmission message, an asynchronous message node is created and put into the first message queue, a second message node is sent, and a signal is sent to a next processing program of the request message; the requested message is processed in sequence within a first time threshold; and if the first time threshold is exceeded, the requested message is processed by a thread. The processing method of the message queue provided by the present application realizes dynamic allocation of memory, improves the flexibility of the MQTT message queue, reasonably utilizes the memory, and consumes less resources. The MQTT client processing method program is modularized, and the places that need to be modified and coupled are reduced, the coupling is weakened, and the processing method program is easy to understand and debug. A uniform interface is presented to the outside, and a class with all functions of synchronization, asynchronization and timeout is realized. The processing device of the message queue, the electronic device and the storage medium provided by the present application can also achieve the above effects. BRIEF DESCRIPTION OF DRAWINGS
[0041] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments. Obviously, the drawings in the following description are only some embodiments of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor.
[0042] Figure 1 A schematic diagram of the processing method of the message queue provided by the present application.
[0043] Figure 2 Another schematic diagram of a message queue processing method provided by an embodiment of the present application;
[0044] Figure 3 Another schematic diagram of a message queue processing device provided by an embodiment of the present application;
[0045] Figure 4 Another schematic diagram of a message queue processing device provided by an embodiment of the present application;
[0046] Figure 5 Another schematic diagram of a message queue processing device provided by an embodiment of the present application;
[0047] Figure 6 A schematic diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0048] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs; the terminology used in the description herein is for describing particular embodiments only and is not intended to be limiting of the application; the description and the drawings are to be regarded as illustrative in nature and are not intended to limit the application. The terminology used in the description of the application herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. The description and the drawings are to be regarded as illustrative in nature and are not intended to limit the application, as defined by the appended claims.
[0049] Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment is included in at least one embodiment of the application. The appearances of the phrase "in an embodiment" in various places in the specification are not necessarily all referring to the same embodiment, nor are they necessarily all directed to the same embodiment, or to a single alternative embodiment. It is explicitly contemplated that embodiments described herein can be combined.
[0050] In order to make the purposes, technical solutions and advantages of the present application clearer, further detailed description will be made to the present application in combination with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application, and are not used to limit the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the present application.
[0051] In the following description, the suffixes "module", "part" or "unit" used for an element are merely intended for facilitating the description of the present application, and are not intended to limit the application.
[0052] As Figure 1 Fig. 1 shows a schematic diagram of a method for processing a message queue according to an embodiment of the present application, the method comprising:
[0053] Step S1: parsing the obtained message, dividing the message into a request message and a requested message, and creating a request message node and a requested message node;
[0054] MQTT (Message Queue Telemetry Transport) is a message protocol based on the publish / subscribe paradigm under the ISO standard (ISO / IEC PRF 20922). It works on the TCP / IP protocol family and is a publish / subscribe message protocol designed for remote devices with low hardware performance and in poor network conditions. For this purpose, it needs a message middleware. MQTT is a client-server-based message publish / subscribe transport protocol. The MQTT protocol is lightweight, simple, open and easy to implement, which makes it very suitable for a wide range of applications. In many cases, including limited environments, such as machine-to-machine (M2M) communication, Internet of Things (IoT). It has been widely used in communicating sensors through satellite links, occasionally dial-up medical devices, smart homes, and some small devices.
[0055] Specifically, after obtaining the message, the format of the message frame needs to be distinguished by parsing the MQTT message frame function message. The MQTT message is divided into two parts: topic and message. The topic contains information such as message source, destination, and message type, and the message contains message quality and specific data. According to the message topic, the message is divided into a request message and a requested message, and a request message node and a requested message node are created.
[0056] Step S2: establishing a first message queue for storing messages and a second message queue for storing messages, the first message queue being used to store the request message node, and the second message queue being used to store the requested message node;
[0057] Specifically, the request message node can be stored in the first message queue and the requested message node can be stored in the second message queue according to the message message.
[0058] In one embodiment, the second message queue includes at least one message queue, and the requested message node is stored in different message queues included in the second message queue according to the message quality of the requested message.
[0059] Preferably, the first message queue and the second message queue are double-linked list structures.
[0060] In one embodiment, the first message queue and the second message queue are lists, which are a sequential container. The list container actually has a very similar function to the doubly linked list in data structure. The data elements in the list are connected by the list pointers to form a linear list in logical sense. The list also has the main advantage of the linked list, i.e. the insertion and deletion of elements at any position in the list are fast. The implementation of the list is as follows: each node of the list has three fields: a predecessor pointer field, a data field and a successor pointer field. The predecessor pointer field stores the first address of the predecessor element; the data field is the data of the node; and the successor pointer field stores the first address of the successor element. Since the list element nodes do not require to be in a continuous memory, obviously the fast random access is not supported in the list, and therefore for the iterator, the iterator can only be moved to the successor / predecessor node element by the "++" or "--" operation.
[0061] Step S3: judging whether the request message is a synchronous delivery message or an asynchronous delivery message; if the request message is a synchronous delivery message, creating a synchronous message node and putting it into the first message queue, sending the first message node and waiting for a reply signal, and processing the request message according to the received reply signal; if the request message is an asynchronous delivery message, creating an asynchronous message node and putting it into the first message queue, sending the second message node, and sending a signal to the next processing program of the request message.
[0062] In one embodiment, the judging whether the request message is a synchronous delivery message or an asynchronous delivery message further comprises: if the request message is a synchronous delivery message, referencing the first semaphore when creating the synchronous message node and putting it into the first message queue, and releasing the first semaphore after processing the request message according to the received reply signal; if the request message is an asynchronous delivery message, referencing the second semaphore when creating the asynchronous message node and putting it into the first message queue, and releasing the second semaphore when sending the second message node and sending the signal to the next processing program of the request message.
[0063] The message queue is protected by referencing the first semaphore or the second semaphore. The first semaphore or the second semaphore is placed in the private part of the base queue. When the message queue is involved in the adding and deleting operations, the first semaphore or the second semaphore is referenced. During the referencing of the first semaphore or the second semaphore, other threads (such as the threads requiring to add elements) cannot operate the message queue, and must wait until the first semaphore or the second semaphore is released before operating. For example, deleting a queue element: referencing the semaphore -> deleting the element -> releasing the semaphore,
[0064] Furthermore, to ensure thread safety in multi-threaded lists, a linked list type `std::list` is used, reusing the `list::empty`, `list::push_back`, `list::front`, `list::pop_front`, and `list::remove` functions. Specifically, when requesting a queue, the system simultaneously requests either the first or second semaphore. First, it checks if the requested queue is empty, returns a linked list pointer, pushes the requested message onto the stack, performs message matching, and pops the message from the stack after matching. The first or second semaphore for synchronous operations requires a pointer; it is allocated on the stack, and messages are copied into the list. Asynchronous operations require callback functions. Because message comparison is needed in the message queue, including message removal, the `==` operator needs to be overloaded; otherwise, the `list::remove` function will be unusable.
[0065] Step S4: Determine whether the waiting time for the requested message exceeds the first time threshold; if it is within the first time threshold, process it sequentially; if it exceeds the first time threshold, process it using a thread.
[0066] like Figure 2 The diagram illustrates another message queue processing method provided by an embodiment of the present invention, the method further comprising:
[0067] If the request message is a synchronous transmission message, the process of creating a synchronous message node and placing it in the first message queue, sending the first message node and waiting for a reply signal, and processing the message according to the received reply signal, further includes:
[0068] Step S31: Perform timeout monitoring on the first message node. If the first message node waits for more than the second time threshold without receiving a reply, discard the first message queue message node and release the synchronization semaphore.
[0069] Synchronous messages can experience blocking while waiting for a reply (implemented by releasing semaphores). Therefore, a timeout management thread is set up: the request queue is traversed at intervals (e.g., 1 minute). Each traversal adds the traversal interval (e.g., 1 minute) to the current time of the message in the request queue. If the current time of the message is greater than the set second time threshold, the message is processed and no further reply is waited for. (Both the current time and the set second time threshold are stored in the message node).
[0070] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0071] like Figure 3As shown in the figure, the message queue processing device 100 provided by the embodiment of the application comprises:
[0072] The message parsing module 10 is configured to parse the obtained message, divide the message into a request message and a requested message, and create a request message node and a requested message node. The first judgment module 30 is configured to judge whether the request message is a synchronous transmission message or an asynchronous transmission message. The synchronous transmission message processing module 301 is configured to, when the request message is a synchronous transmission message, create a synchronous message node and put it into the first message queue, send the first message node and wait for a reply signal, and process the request message according to the received reply signal. The second judgment module 40 is configured to judge whether the waiting time length of the requested message exceeds a first time threshold. The first processing module 401 is configured to sequentially process the requested message when the waiting time length of the requested message is within the first time threshold. The second processing module 402 is configured to thread-process the requested message when the waiting time length of the requested message exceeds the first time threshold.
[0073] As shown in the figure, the message queue processing device 100 provided by the embodiment of the application further comprises a synchronous message node reference semaphore module 303. Figure 4 As shown in the figure, the message queue processing device 100 provided by the embodiment of the application further comprises a synchronous message node reference semaphore module 303.
[0074] As shown in the figure, the message queue processing device 100 provided by the embodiment of the application further comprises a message node monitoring module 3011. Figure 5 As shown in the figure, the message queue processing device 100 provided by the embodiment of the application further comprises a message node monitoring module 3011.
[0075] The specific limitation of the message queue processing apparatus can refer to the limitation of the message queue processing method, which will not be repeated here. Each module in the message queue processing apparatus can be implemented by software, hardware, and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in hardware form, or can be stored in the memory in the computer device in software form, so that the processor calls and executes the operation corresponding to each module.
[0076] Reference Figure 6 which shows a schematic diagram of an electronic device 200 provided by an embodiment of the present application. It includes a memory 201 and a processor 202; wherein the memory 201 is configured to store program code; the processor 202 is configured to call the program code to implement the message queue processing method described in any of the above embodiments. The memory 201 and the processor 202 are coupled.
[0077] Specifically, the processor 202 can include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the message queue processing method described above.
[0078] The memory 201 can include a mass storage for data or instructions. For example, but not limited to, the memory 201 can include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive, or a combination of two or more of the above. In appropriate cases, the memory 201 can include removable or non-removable (or fixed) media. In appropriate cases, the memory 201 can be internal or external to the message queue processing apparatus. In a specific embodiment, the memory 201 is a non-volatile solid-state memory. In a specific embodiment, the memory 201 includes read-only memory (ROM). In appropriate cases, the ROM can be mask-programmed ROM, programmable ROM (PROM), erasable PROM (EPROM), electrically erasable PROM (EEPROM), electrically alterable ROM (EAROM), or flash memory, or a combination of two or more of the above. The processor 202 reads and executes computer program instructions stored in the memory 201 to implement the message queue processing method described above.
[0079] In a further embodiment of the electronic device 200, the electronic device 200 can further include a communication interface 203 and a bus 204. Wherein, as Figure 6As shown, the processor 202, the memory 201, the communication interface 203 are connected through the bus 204 and complete the communication between each other.
[0080] The communication interface 203 is mainly used to realize the communication between each module, device, unit and / or equipment required by the database storage data method. The bus 204 includes hardware, software or both, which couples the components of the electronic device 200 to each other. By way of example and not limitation, the bus 204 can include an accelerated graphics port (AGP) or other graphics bus, an enhanced industry standard architecture (EISA) bus, a front side bus (FSB), a hyper transport (HT) interconnect, an industry standard architecture (ISA) bus, an infiniband interconnect, a low pin count (LPC) bus, a memory bus, a microchannel architecture (MCA) bus, a peripheral component interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a serial advanced technology attachment (SATA) bus, a video electronics standards association local (VLB) bus, or other suitable bus or combination of two or more of these. The bus 204 can include one or more buses as appropriate. Although the present application describes and illustrates a particular bus, the present application contemplates any suitable bus or interconnect.
[0081] The computer storage medium containing the computer program for executing the message queue processing method is configured to the electronic device or electronic apparatus as described above, the program in the computer storage medium for executing the message queue processing method is called, and the program is applied to the electronic device or electronic apparatus. The message in the message queue is processed in real time during program execution.
[0082] The embodiment of the present application also provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to enable an electronic device to execute the message queue processing method according to any one of the above.
[0083] Computer readable media can be computer readable signal media or computer readable storage media. Computer readable storage media can be, for example, but not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples (a non-exhaustive list) of computer readable storage media include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In this document, computer readable storage media can be any tangible medium that can contain, or store computer readable program code for use by or in connection with an instruction execution system, apparatus, or device.
[0084] Computer readable signal media can include a computer readable instruction, data structures, program code, or other data by way of a modem, by way of a wired communication means, or by way of wireless communication means, along with a computer readable medium. Such computer readable signal media can take a variety of forms, including, but not limited to, electro-magnetic, optical or any suitable combination thereof. Computer readable signal media can be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate or transport program for use by or in connection with an instruction execution system, apparatus, or device.
[0085] Program code embodied on a computer readable medium can be transmitted using any appropriate medium, including but not limited to wireless, wire line, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0086] Computer program code for carrying out operations of the present application can be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C++ or the like, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code can execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection can be made to an external computer (for example, through the Internet using an Internet Service Provider).
[0087] The terminology used in the description of the application herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in this description of the application and the appended claims, the singular forms "a", "an" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
[0088] Depending on the context, the word "if" can be interpreted to mean "when" or "upon" or "in response to determining" or "in response to detecting," depending on the context. Similarly, the phrase "if it is determined" or "if a detected (statement of a condition or event)" can be interpreted to mean "upon determining" or "in response to determining" or "upon detecting (the stated condition or event)" or "in response to detecting (the stated condition or event)," depending on the context.
[0089] In several embodiments of the present application, it will be understood that the disclosed apparatus, devices, and methods can be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and the division of the units is merely a logical function division. In actual implementation, another division manner can be used, for example, a plurality of units or components can be combined or integrated into another system, or some features can be omitted or not executed. In addition, the coupling or direct coupling or communication connection between the units or components shown or discussed can be indirect coupling or communication connection through some interfaces, devices or units, and can be electrical, mechanical or other forms.
[0090] The above descriptions are merely some preferred embodiments of the present application, and are not intended to limit the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A method of processing a message queue, characterized by, The method comprises the following steps: parsing the obtained message, dividing the message into a request message and a requested message, and creating a request message node and a requested message node; establishing a first message queue for storing messages and a second message queue for storing messages, the first message queue and the second message queue being a double-linked list structure, the first message queue being used for storing the request message node, and the second message queue being used for storing the requested message node; wherein the second message queue comprises at least one message queue, and the requested message node is stored in different message queues included in the second message queue according to the message quality of the requested message; determining whether the request message is a synchronous transmission message or an asynchronous transmission message; if the request message is a synchronous transmission message, creating a synchronous message node and placing it into the first message queue, sending the first message node and waiting for a reply signal, and processing the request message according to the received reply signal; if the request message is an asynchronous transmission message, creating an asynchronous message node and placing it into the first message queue, sending the second message node, and sending a signal to a next handler of the request message; determining whether the waiting time length of the requested message exceeds a first time threshold; if the processing is in order within the first time threshold; if the processing is in thread if the first time threshold is exceeded.
2. The message queue processing method of claim 1, wherein, When determining whether the request message is a synchronous transmission message or an asynchronous transmission message, the method further comprises the following steps: if the request message is a synchronous transmission message, creating a synchronous message node and placing it into the first message queue by referring to a first semaphore, and releasing the first semaphore after the request message is processed according to the received reply signal; if the request message is an asynchronous transmission message, creating an asynchronous message node and placing it into the first message queue by referring to a second semaphore, and releasing the second semaphore when the second message node is sent and the signal is sent to the next handler of the request message.
3. The method of claim 2, wherein, If the request message is a synchronous transmission message, the method further comprises the following steps after creating a synchronous message node and placing it into the first message queue, sending the first message node and waiting for a reply signal, and processing the message according to the received reply signal: performing timeout monitoring on the sent first message node, and discarding the first message queue message node and releasing the synchronous semaphore if the first message node has not received a reply within a second time threshold.
4. A processing device for a message queue for implementing the method of processing a message queue according to any one of claims 1 to 3, characterized in that The method comprises the following steps: a message parsing module, configured to parse the obtained message, divide the message into a request message and a requested message, and create a request message node and a requested message node; a message queue construction module, configured to establish a first message queue for storing messages and a second message queue for storing messages, the first message queue being used for storing the request message node, and the second message queue being used for storing the requested message node; a first determination module, configured to determine whether the request message is a synchronous transmission message or an asynchronous transmission message; a synchronous transmission message processing module, configured to, when the request message is a synchronous transmission message, create a synchronous message node and place it into the first message queue, send the first message node and wait for a reply signal, and process the request message according to the received reply signal; The asynchronous message processing module is configured to, when the request message is an asynchronous delivery message, create an asynchronous message node and put the asynchronous message node into the first message queue, send a second message node, and send a signal to a next handler of the request message; The second judging module is configured to judge whether the waiting time length of the requested message exceeds a first time threshold; The first processing module is configured to sequentially process the requested message when the waiting time length of the requested message is within the first time threshold; The second processing module is configured to thread-process the requested message when the waiting time length of the requested message exceeds the first time threshold.
5. The message queue processing apparatus according to claim 4, wherein The first judging module further comprises, The synchronous message node reference semaphore module is configured to, when the request message is a synchronous delivery message, create a synchronous message node and put the synchronous message node into the first message queue, reference a first semaphore, and release the first semaphore after the request message is processed according to the received reply signal; The asynchronous message node reference semaphore module is configured to, when the request message is an asynchronous delivery message, create an asynchronous message node and put the asynchronous message node into the first message queue, reference a second semaphore, and release the second semaphore when the second message node is sent and the signal is sent to the next handler of the request message.
6. The message queue processing apparatus according to claim 5, wherein The synchronous delivery message processing module further comprises, The message node detection module is configured to perform timeout monitoring on the sent first message node, and discard the first message queue message node and release the synchronous semaphore if the first message node has not received a reply when the waiting time length of the first message node exceeds a second time threshold.
7. An electronic device, comprising: The electronic device comprises a memory and a processor; wherein The memory is configured to store program code; The processor is configured to call the program code to implement the message queue processing method according to any one of claims 1 to 3.
8. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program, when executed by the processor, causes the electronic device to perform the message queue processing method according to any one of claims 1 to 3.
Citation Information
Patent Citations
Message storage method and apparatus
CN109257320A
Message processing method and device
CN113656189A