Message processing method, device, electronic device and computer-readable storage medium
By obtaining and storing service instance code collection information on the terminal and adding this information to the message, the problem of message processing failure in different terminal environments is solved, and the efficiency and success rate of message processing are improved.
Patent Information
- Application Number
- CN202411132786.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-19
- Publication Date
- 2025-04-15
- Estimated Expiration
- 2044-08-19
AI Technical Summary
When debugging services in different terminal environments, messages cannot be processed in the correct environment, resulting in failure in processing.
By obtaining the instance code collection information of all services on the terminal and adding the instance code collection information when the message is sent, the target message has the target message body and the target set information, so when the terminal receives the target message, it determines whether the required environment and the terminal environment are consistent and determines whether to perform processing.
It effectively reduces the processing failure caused by message processing in an error environment, improves the processing efficiency and success rate of message, and is suitable for a variety of application scenarios.
Smart Images

Figure CN118733302B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of network communication technology, and in particular to a message processing method, device, electronic device and computer-readable storage medium. Background Art
[0002] In the traditional synchronous communication mode, systems call each other directly, which leads to tight coupling between systems. Once one of the systems fails or needs maintenance, it will affect the normal operation of other systems. Therefore, in software development, in order to meet the needs of asynchronous communication and decoupling between systems, message queues are usually introduced as middleware to achieve asynchronous communication between systems. The sender sends messages to the message queue, and the receiver obtains messages from the message queue for processing. The communication between systems becomes a message-based asynchronous mode. By reducing the coupling between systems, the scalability and reliability of the system can be improved.
[0003] However, during the development process, we will face the problem of debugging services in different terminal environments. Usually, local debugging will be performed first to deal with the problem, and only after the problem is dealt with will it be released to the development environment to verify the problem fix. When the message queue is processed, it usually sends messages to the corresponding multiple terminals in a polling manner. Due to the different terminal environments, the message cannot be processed in the correct environment, resulting in message processing failure, affecting the local environment debugging, etc. Summary of the invention
[0004] In view of this, the purpose of the embodiments of the present application is to provide a message processing method, device, electronic device and computer-readable storage medium to improve the problem of processing failure caused by the inability to process messages in the correct environment in the prior art.
[0005] In order to solve the above problems, in a first aspect, an embodiment of the present application provides a message processing method, the method comprising:
[0006] Determine the instance code set information of all services on the terminal;
[0007] Receive a target message sent by a message queue; wherein the target message includes a target message body and target set information;
[0008] According to the instance code set information, it is determined whether to consume the target message.
[0009] In the above implementation process, by acquiring the instance code set information reflecting the actual environment of the terminal, and adding the corresponding instance code set information to the message when sending the message to the message queue, the target message has the corresponding target message body and target set information, so that when the terminal receives the target message, it can judge whether the required environment of the target message is consistent with the terminal's own environment according to the target set information in the target message and its own corresponding instance code set information, so as to determine whether to process the target message. The environment required by the message and its own environment can be analyzed and compared, effectively reducing the processing failure caused by the message being processed in an erroneous environment, thereby improving the message processing efficiency and success rate, and is suitable for a variety of application scenarios.
[0010] Optionally, the determining the instance code set information of all services on the terminal includes:
[0011] Obtaining registration information of each of the services on the terminal;
[0012] Based on the registration information and the network address information of the terminal, generating a unique instance code corresponding to each of the services;
[0013] Integrate all the instance codes to obtain the instance code set information;
[0014] The instance code set information is stored in the local thread.
[0015] In the above implementation process, the registration information of each service on the terminal can be obtained according to various service governance components, and the unique instance code corresponding to each service can be generated in combination with the registration information and the network address information of the terminal. The instance code can reflect the service and the operating environment. In addition, considering the situation that there are multiple services on the terminal, the instance codes of all services on the terminal can be integrated to obtain the corresponding instance code collection information, and the instance code collection information can be stored in the local thread for subsequent use. The registration status of the service and the address of the terminal can be combined to generate a unique instance code that reflects the service and the operating environment, so as to improve the effectiveness of the instance code collection information, thereby improving the accuracy of judging whether the message environment is in compliance based on the instance code collection information.
[0016] Optionally, judging whether to consume the target message according to the instance code set information includes:
[0017] Parsing the target message to obtain the target message body and the target set information;
[0018] Read the instance code set information from the local thread;
[0019] Comparing the target set information with the instance code set information;
[0020] If it is determined that the target set information is consistent with the instance code set information, the target message body is consumed.
[0021] In the above implementation process, after the terminal receives the target message sent by the message queue, it can parse the target message to obtain the target message body and target collection information, read its own instance code collection information from the local thread, and compare it with the target collection information. If the two collection information are determined to be consistent, it means that the service environment and operating environment required for consuming the target message are consistent with the actual environment of the terminal, and the terminal can consume the target message body so that the target message body can be processed normally in the correct environment. The ability to compare the required environment with the actual environment to determine whether the message can be consumed effectively reduces the situation where the message is abnormally processed in the wrong environment.
[0022] Optionally, comparing the target set information with the instance code set information includes:
[0023] Comparing the number of target codes in the target set information and the number of instance codes in the instance code set information;
[0024] If it is determined that the number of the target code and the instance code is consistent, then the target code and the instance code are compared; if each of the target codes has the same instance code, then it is determined that the target set information is consistent with the instance code set information;
[0025] If the number of the target codes and the instance codes are inconsistent, or any of the target codes does not have the same instance code, it is determined that the target set information is inconsistent with the instance code set information.
[0026] In the above implementation process, since the target set information may include one or more target codes, and the instance code set information may include one or more instance codes, when comparing the target set information and the instance code set information, the number of target codes and instance codes may be compared first to determine whether the number of services on the terminal is consistent; after the number is consistent, the data of the target code and the instance code are compared to compare the substantial content. When each target code has the same instance code, the number and substantial content of the target code are exactly the same as the instance code, that is, the target set information is completely consistent with the instance code set information. When any comparison result of the number or substantial content is different, the environment required to represent the target message does not match the substantial environment of the terminal, and it is determined that the target set information is inconsistent with the instance code set information. A dual judgment method can be designed according to the number and substantial content of the instance code to ensure the validity and accuracy of the judgment, so as to determine whether to consume the message according to the judgment result.
[0027] Optionally, the determining whether to consume the target message according to the instance code set information further includes:
[0028] If it is determined that the target set information is inconsistent with the instance code set information, the target message is returned to the message queue so that the message queue can re-pollating and sending the target message.
[0029] In the above implementation process, if the target set information is inconsistent with the instance code set information, the environment required to represent the target message is inconsistent with the actual environment of the terminal, and the terminal cannot process the target message normally. The target message can be returned to the message queue for the message queue to re-polling and sending the target message until the target message can be consumed normally. The ability to return the message to the message queue for reprocessing in the case of inconsistent environments effectively improves the efficiency of message polling and sending, thereby improving the efficiency of other terminals in judging and consuming messages.
[0030] Optionally, the method further comprises:
[0031] If the target message is not consumed within a preset time period, the target message is marked as an abnormal message;
[0032] The abnormal message is sent to the abnormal sub-queue of the message queue, so that the message queue can provide an abnormal prompt based on the abnormal message stored in the abnormal sub-queue.
[0033] In the above implementation process, when the same terminal generates and consumes messages, the service environment on the terminal may change. Therefore, there may be an abnormal situation where the target message cannot be consumed normally. In order to solve this abnormal situation, a corresponding preset time period can be set as the consumption time threshold of the message. If the target message is not consumed within the preset time period, it indicates that there may be an abnormal situation. The current terminal can mark the target message as an abnormal message and send the abnormal message to the abnormal subqueue under the message queue, so that the message queue can make an abnormal prompt based on the abnormal message stored in the abnormal subqueue, thereby prompting the staff to handle the abnormal message accordingly. When the message has not been consumed normally for a long time, the message can be marked and set in the corresponding subqueue for abnormal prompt, which effectively reduces the adverse situation caused by the continued polling of abnormal messages and improves the efficiency of handling abnormal situations.
[0034] Optionally, the method further comprises:
[0035] Adding the instance code set information to the initial message body to obtain a composite message;
[0036] The composite message is sent to the message queue.
[0037] In the above implementation process, when generating a message, the terminal can read the instance code set information in the local thread and add the instance code set information to the generated initial message body to obtain a corresponding composite message, and then send the composite message to the message queue, so that the messages received and sent in the message queue are composite messages with a message body and instance code set information. When generating a message, the instance code set information can be added to the corresponding message body, thereby ensuring that the received target message has the corresponding target message body and target set information.
[0038] In a second aspect, an embodiment of the present application further provides a message processing device, the device comprising: a determination module, a receiving module and a processing module;
[0039] The determination module is used to determine instance code set information of all services on the terminal;
[0040] The receiving module is used to receive a target message sent by a message queue; wherein the target message includes a target message body and target set information;
[0041] The processing module is used to determine whether to consume the target message according to the instance code set information.
[0042] In the above implementation process, the instance code set information reflecting the actual environment of the terminal is acquired through the determination module, the target message with the corresponding target message body and target set information sent by the message queue is received through the receiving module, and the processing module judges whether the required environment of the target message is consistent with the terminal's own environment based on the target set information in the target message and its own corresponding instance code set information, so as to determine whether to process the target message.
[0043] In a third aspect, an embodiment of the present application further provides an electronic device, comprising a memory and a processor, wherein the memory stores program instructions, and when the processor reads and runs the program instructions, it executes the steps in any implementation of the above-mentioned message processing method.
[0044] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer program instructions, and when the computer program instructions are read and executed by a processor, the steps in any implementation of the above-mentioned message processing method are executed.
[0045] In summary, the embodiments of the present application provide a message processing method, device, electronic device and computer-readable storage medium, which can obtain instance code set information that reflects the actual environment of the terminal, and add the corresponding instance code set information to the message when the message is sent to the message queue. Therefore, when the terminal receives the target message, it can determine whether the required environment of the target message is consistent with the terminal's own environment based on the target set information in the message and its own corresponding instance code set information, so as to determine whether to process the target message, which effectively improves the message processing efficiency and success rate, and is suitable for a variety of application scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0047] Figure 1 A block diagram of an electronic device provided in an embodiment of the present application;
[0048] Figure 2 A flowchart of a first message processing method provided in an embodiment of the present application;
[0049] Figure 3 A detailed flow chart of step S200 provided in an embodiment of the present application;
[0050] Figure 4 A detailed flowchart of step S400 provided in an embodiment of the present application;
[0051] Figure 5 A detailed flowchart of step S430 provided in an embodiment of the present application;
[0052] Figure 6 A flowchart of a second message processing method provided in an embodiment of the present application;
[0053] Figure 7 A flowchart of a third message processing method provided in an embodiment of the present application;
[0054] Figure 8 A schematic diagram of the structure of a message processing device provided in an embodiment of the present application.
[0055] Icons: 100 - electronic device; 111 - memory; 112 - storage controller; 113 - processor; 114 - peripheral interface; 115 - input and output unit; 116 - display unit; 700 - message processing device; 710 - determination module; 720 - receiving module; 730 - processing module. DETAILED DESCRIPTION
[0056] The technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments of the embodiments of the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the embodiments of the present application.
[0057] During the software development process, we will face the problem of debugging services in different terminal environments. Usually, local debugging will be performed first to handle the problem, and only after the problem is handled will it be released to the development environment to verify the problem fix. When the message queue is processed, the message is usually sent to the corresponding multiple terminals in a polling manner. Due to the different terminal environments, the message cannot be processed in the correct environment. For example, the current local environment is A, the development environment is B, A and B both listen to the message queue C, if C sends a business processing message, the message will be sent to A or B in a polling manner. At this time, the business logic processing method in the A environment is the latest, and the B environment is not the latest. The latest business processing logic processing method, that is, A, needs to be used to process the message. If the message is sent to B first during polling, the message that should have been processed correctly in the A environment will be processed in the B environment. Since B does not have the latest business logic, the processing will fail, thus affecting the local environment debugging.
[0058] Therefore, in order to solve the above problems, an embodiment of the present application provides a message processing method, which is applied to the electronic device corresponding to the terminal. The electronic device can be a server, a personal computer (PC), a tablet computer, a smart phone, a personal digital assistant (PDA), and other electronic devices with logical computing functions. It can determine whether to consume the message based on the actual environment of the service on the terminal and the actual environment required by the message, so as to ensure that the message can be processed in the correct environment, effectively reducing the adverse situation of message processing failure.
[0059] Optionally, see Figure 1 , Figure 1 The block diagram of an electronic device provided in an embodiment of the present application. The electronic device 100 may include a memory 111, a storage controller 112, a processor 113, a peripheral interface 114, an input and output unit 115, and a display unit 116. A person skilled in the art may understand that Figure 1 The structure shown is only for illustration and does not limit the structure of the electronic device 100. For example, the electronic device 100 may further include Figure 1 More or fewer components as shown, or with Figure 1 Different configurations shown.
[0060] The memory 111, storage controller 112, processor 113, peripheral interface 114, input / output unit 115 and display unit 116 are electrically connected to each other directly or indirectly to achieve data transmission or interaction. For example, these components can be electrically connected to each other via one or more communication buses or signal lines. The processor 113 is used to execute the executable module stored in the memory.
[0061] The memory 111 may be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable read-only memory (EEPROM), etc. The memory 111 is used to store programs, and the processor 113 executes the program after receiving the execution instruction. The method executed by the electronic device 100 defined by the process disclosed in any embodiment of the present application can be applied to the processor 113, or implemented by the processor 113.
[0062] The processor 113 may be an integrated circuit chip with signal processing capability. The processor 113 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application may be implemented or executed. The general-purpose processor may be a microprocessor or any conventional processor.
[0063] The peripheral interface 114 couples various input / output devices to the processor 113 and the memory 111. In some embodiments, the peripheral interface 114, the processor 113 and the memory controller 112 can be implemented in a single chip. In other embodiments, they can be implemented by separate chips.
[0064] The input / output unit 115 is used to provide input data to the user. The input / output unit 115 may be, but is not limited to, a mouse and a keyboard.
[0065] The above-mentioned display unit 116 provides an interactive interface (such as a user operation interface) between the electronic device 100 and the user or is used to display image data for the user's reference. In this embodiment, the display unit can be a liquid crystal display or a touch display. If it is a touch display, it can be a capacitive touch screen or a resistive touch screen that supports single-point and multi-point touch operations. Supporting single-point and multi-point touch operations means that the touch display can sense touch operations generated simultaneously from one or more positions on the touch display, and the sensed touch operations are handed over to the processor for calculation and processing. In an embodiment of the present application, the display unit 116 can display a variety of information such as the substantive content of the determined instance code set information, the consumption status of the message, etc.
[0066] The electronic device in this embodiment can be used to execute each step in each message processing method provided in the embodiment of the present application. The implementation process of the message processing method is described in detail below through several embodiments.
[0067] See also Figure 2 , Figure 2 A flowchart of a first message processing method provided in an embodiment of the present application, the method may include steps S200-S400.
[0068] Step S200: determining instance code set information of all services on the terminal.
[0069] Among them, the instance code collection information may include the instance code of each service on the terminal. Each instance code is unique. The instance code is the coded information that can reflect the service operating environment on the terminal, such as a string of information. The corresponding instance code collection information can be determined according to the corresponding service governance component.
[0070] Step S300: receiving a target message sent by a message queue.
[0071] Among them, the message queue is a topic subscribed or monitored by the terminal. When the terminal sends a message to the message queue, it can add corresponding instance code set information in the message. In this case, the target message sent in the message queue can include a target message body and target set information. The target set message is the instance code set information corresponding to the terminal sending the target message.
[0072] Step S400: judging whether to consume the target message according to the instance code set information.
[0073] Among them, it is possible to judge whether the required environment of the target message is consistent with the environment of the terminal itself according to the target set information in the target message and the instance code set information corresponding to itself, so as to determine whether to process the target message.
[0074] exist Figure 2In the illustrated embodiment, the environment required by the message and its own environment can be analyzed and compared, effectively reducing processing failures caused by message processing in an erroneous environment, thereby improving message processing efficiency and success rate, and is suitable for a variety of application scenarios.
[0075] Optionally, see Figure 3 , Figure 3 A detailed flowchart of step S200 is provided for an embodiment of the present application. Step S200 may include steps S210-S240.
[0076] Step S210, obtaining registration information of each service on the terminal.
[0077] Among them, the registration information of each service registration can be obtained from the corresponding service governance component. The registration information may include various information such as the name, ID, and number of the service.
[0078] Optionally, the service governance component can be Eureka, which mainly includes service registration and service discovery and is mainly used to build a service registration center. Service providers can register their own services in Eureka so that consumers can find them, and service consumers can obtain the registration list from Eureka to consume services.
[0079] Step S220: Generate a unique instance code corresponding to each service based on the registration information and the network address information of the terminal.
[0080] Among them, since the same service can be set up on multiple terminals, in order to distinguish each service, the network address information of the terminal, such as the IP address of the terminal, etc., can also be obtained, and the registration information and the network address information of the terminal can be combined to generate a corresponding unique instance code for each service, so that the same service has a unique instance code when deployed and registered on different terminals, and the service and operating environment on the terminal can be reflected according to the uniqueness of the instance code.
[0081] Step S230: Integrate all instance codes to obtain instance code set information.
[0082] Considering the situation that there are multiple services on the terminal, the instance codes of all services on the terminal can be integrated to obtain corresponding instance code set information.
[0083] Step S240: store the instance code set information in the local thread.
[0084] In order to facilitate subsequent use, the instance code set information can be stored. In addition, considering the efficiency of reading data in subsequent use, the instance code set information can be stored in the local thread without setting up a third-party memory for separate storage, and the storage and reading speed is faster.
[0085] For example, the local thread can be THREADLOCAL, which is a class that solves the data inconsistency problem caused by multi-threaded operations sharing resources by thread isolation. THREADLOCAL creates a separate variable copy for each thread in a multi-threaded environment. The variable copies between threads do not affect each other. Each thread has its own variable copy, so there is no problem of sharing between multiple threads, thereby ensuring thread safety. THREADLOCAL is suitable for scenarios where each thread needs its own independent copy of data and can be used in multiple methods, that is, variables are isolated between threads and shared between methods or classes.
[0086] Optionally, the code for obtaining the instance code set information and storing it in the local thread THREADLOCAL may include:
[0087] / / Get the service registration instance collection
[0088] List <string>services = discoveryClient.getServices();
[0089] / / Store the collection in ThreadLocal
[0090] ThreadLocalUtils.setInstances(services);
[0091] exist Figure 3 In the illustrated embodiment, a unique instance code that reflects the service and operating environment can be generated in combination with the service registration status and the terminal address, so as to improve the validity of the instance code set information, thereby improving the accuracy of judging whether the message environment complies based on the instance code set information.
[0092] Optionally, see Figure 4 , Figure 4 A detailed flowchart of step S400 is provided for an embodiment of the present application. Step S400 may include steps S410-S440.
[0093] Step S410, parse the target message to obtain the target message body and target set information.
[0094] After receiving the target message sent by the message queue, the terminal may parse the target message to obtain the target message body and target set information.
[0095] Step S420, reading instance code set information from the local thread.
[0096] Step S430, comparing the target set information with the instance code set information.
[0097] The terminal may read its own instance code set information from the local thread to compare with the target set information to determine whether the target set information exists in the instance code set information of the local thread.
[0098] Step S440: If it is determined that the target set information is consistent with the instance code set information, the target message body is consumed.
[0099] Among them, if the target set information exists in the instance code set information of the local thread, that is, the two set information are consistent, then the service environment and operating environment required for consuming the target message are consistent with the actual environment of the terminal, and the terminal can consume the target message body so that the target message body can be processed normally in the correct environment.
[0100] exist Figure 4 In the illustrated embodiment, the required environment and the actual environment can be compared to determine whether the message can be consumed, thereby effectively reducing the situation where the message is abnormally processed in an erroneous environment.
[0101] Optionally, see Figure 5 , Figure 5 A detailed flowchart of step S430 is provided for an embodiment of the present application. Step S430 may include steps S431-S433.
[0102] Step S431, comparing the number of target codes in the target set information and the number of instance codes in the instance code set information.
[0103] Among them, since the target set information may include one or more target codes, the target code is the instance code of the corresponding terminal that sends the target message to the message queue; the instance code set information may include one or more instance codes. Therefore, when comparing the target set information and the instance code set information, the number of target codes and instance codes can be compared first to determine whether the number of services on the terminal is consistent.
[0104] Step S432: If it is determined that the number of target codes and instance codes is consistent, data comparison is performed on the target codes and instance codes; if each target code has the same instance code, it is determined that the target set information is consistent with the instance code set information.
[0105] After the number is consistent, the data of the target code and the instance code are compared to compare the substantial content, for example, the character string of each target code is compared one by one with the instance code, etc. When each target code has the same instance code, the number and substantial content of the target code are exactly the same as the instance code, that is, the target set information is completely consistent with the instance code set information.
[0106] Step S433: If the number of target codes and instance codes is inconsistent, or any target code does not have the same instance code, it is determined that the target set information is inconsistent with the instance code set information.
[0107] If any comparison result of the quantity or the substantial content is different, the environment required to represent the target message does not match the substantial environment of the terminal, and it is determined that the target set information is inconsistent with the instance code set information.
[0108] Optionally, when the target code and the instance code are inconsistent in quantity or substantial content, there may be multiple environmental inconsistencies such as different environments or changes in the terminal environment.
[0109] It should be noted that if it is determined that the target set information is inconsistent with the instance code set information, the target message is returned to the message queue so that the message queue can re-pollating and sending the target message. If the target set information is inconsistent with the instance code set information, the environment required to represent the target message does not match the actual environment of the terminal, and the terminal cannot process the target message normally. The target message can be returned to the message queue so that the message queue can re-pollating and sending the target message until the target message can be consumed normally. The ability to return the message to the message queue for reprocessing in the event of an inconsistent environment effectively improves the efficiency of message polling and sending, thereby improving the efficiency of other terminals in judging and consuming messages.
[0110] Optionally, the code logic for obtaining the target message and processing it may include:
[0111] try {
[0112] / / Get queue message information
[0113] String s = new String(bytes, StandardCharsets.UTF_8);
[0114] JSONObject jsonObject = JSONObject.parseObject(s);
[0115] / / Get the instance collection carried
[0116] String instanceQueue = jsonObject.getString(CommonKeyConfig.IP);
[0117] List <string>instancesQueue = JSON.parseArray(instanceQueue,String.class);
[0118] / / Get the instance code set information corresponding to the service
[0119] List <string>instances = ThreadLocalUtils.getInstances();
[0120] / / To judge, the target set information must all exist in the currently cached instance code set information, otherwise it will not be consumed
[0121] instancesQueue.forEach(instance->{
[0122] if (!instances.contains(instance)){
[0123] throw new CustomException("There is a consumption instance that does not conform to the current environment");
[0124] }
[0125] });
[0126] } catch (Exception e) {
[0127] / / Put it back into the queue
[0128] fanoutRabbitMQUtils.backMessageFanout(message, channel);
[0129] }
[0130] exist Figure 5 In the illustrated embodiment, a dual judgment method can be designed according to the number of instance codes and the substantial content to ensure the validity and accuracy of the judgment, thereby determining whether to consume the message according to the judgment result.
[0131] Optionally, see Figure 6 , Figure 6 This is a flow chart of a second message processing method provided in an embodiment of the present application. The method may further include steps S510-S520.
[0132] Step S510: If the target message is not consumed within a preset time period, the target message is marked as an abnormal message.
[0133] Among them, when the same terminal generates and consumes messages, the service environment on the terminal may change, so there may be an abnormal situation that the target message cannot be consumed normally. In order to solve this abnormal situation, a corresponding preset time period can be set as the consumption time threshold of the message, and whether the target message is consumed within the preset time period is monitored. If the target message is not consumed within the preset time period, it indicates that there may be an abnormal situation that cannot be consumed normally, and the current terminal can mark the target message as an abnormal message.
[0134] Step S520: Send an exception message to the exception sub-queue of the message queue, so that the message queue can provide an exception prompt based on the exception message stored in the exception sub-queue.
[0135] The exception message may be sent to the exception subqueue under the message queue, so that the message queue can provide an exception prompt based on the exception message stored in the exception subqueue, thereby prompting the staff to perform corresponding exception processing on the exception message.
[0136] exist Figure 6 In the illustrated embodiment, when a message has not been consumed normally for a long time, the message can be marked and set in a corresponding subqueue for abnormal prompting, thereby effectively reducing the adverse conditions caused by continued polling of abnormal messages and improving the efficiency of handling abnormal conditions.
[0137] Optionally, see Figure 7 , Figure 7 This is a flow chart of a third message processing method provided in an embodiment of the present application. The method may further include steps S610-S620.
[0138] Step S610: add instance code set information to the initial message body to obtain a composite message.
[0139] When generating a message, the terminal may read the instance code set information in the local thread, and add the instance code set information to the generated initial message body to obtain a corresponding composite message.
[0140] Step S620: Send the synthesized message to the message queue.
[0141] The synthesized message may be sent to a message queue, so that the messages received and sent in the message queue are all synthesized messages having a message body and instance code set information.
[0142] It should be noted that the target message received by the current terminal is a composite message generated and sent by a certain terminal.
[0143] Optionally, when sending a message, the instance code set information of the current environment may be obtained through the local thread THREADLOCAL to carry the instance code set information into the generated initial message body, and the generated composite message may be sent. The implementation code logic may include:
[0144] / Send a message and carry the IP in the initial message body
[0145] MessageProperties messageProperties = new MessageProperties();
[0146] messageProperties.setDeliveryMode(MessageDeliveryMode.PERSISTENT);
[0147] / / Convert the object to JSON
[0148] JSONObject json = (JSONObject) JSONObject.toJSON(object);
[0149] json.put(CommonKeyConfig.UID, CustomIdUtils.getSerialNo());
[0150] / / Get the instance code collection information stored by the service
[0151] List <string>instances = ThreadLocalUtils.getInstances();
[0152] json.put(CommonKeyConfig.IP,instances);
[0153] byte[] bytes = json.toJSONString().getBytes(StandardCharsets.UTF_8);
[0154] Message message = new Message(bytes, messageProperties);
[0155] / / Send message
[0156] rabbitTemplate.convertAndSend(exChange, routingKey, message);
[0157] exist Figure 7 In the illustrated embodiment, the instance code set information can be added to the corresponding message body when the message is generated, thereby ensuring that the received target message has the corresponding target message body and target set information.
[0158] See also Figure 8 , Figure 8 A structural diagram of a message processing device provided in an embodiment of the present application, the message processing device 700 may include: a determination module 710, a receiving module 720 and a processing module 730;
[0159] The determination module 710 is used to determine the instance code set information of all services on the terminal;
[0160] The receiving module 720 is used to receive a target message sent by a message queue; wherein the target message includes a target message body and target set information;
[0161] The processing module 730 is used to determine whether to consume the target message according to the instance code set information.
[0162] In an optional implementation, the determination module 710 is specifically used to: obtain registration information of each service on the terminal; generate a unique instance code corresponding to each service based on the registration information and the network address information of the terminal; integrate all instance codes to obtain instance code collection information; and store the instance code collection information in a local thread.
[0163] In an optional implementation, the processing module 730 is specifically used to: parse the target message to obtain the target message body and target collection information; read the instance code collection information from the local thread; compare the target collection information with the instance code collection information; if it is determined that the target collection information is consistent with the instance code collection information, then consume the target message body.
[0164] In an optional implementation, the processing module 730 is specifically used to: compare the number of target codes in the target set information and the number of instance codes in the instance code set information; if it is determined that the number of target codes and instance codes is consistent, then perform data comparison on the target codes and instance codes; if each target code has the same instance code, then the target set information is determined to be consistent with the instance code set information; if the number of target codes and instance codes is inconsistent, or any target code does not have the same instance code, then the target set information is determined to be inconsistent with the instance code set information.
[0165] In an optional implementation, the processing module 730 is further configured to: if it is determined that the target set information is inconsistent with the instance code set information, return the target message to the message queue so that the message queue can re-pollating and sending the target message.
[0166] In an optional embodiment, the message processing device 700 may also include an exception module, which is used to mark the target message as an abnormal message if the target message is not consumed within a preset time period; and send the abnormal message to the abnormal sub-queue of the message queue so that the message queue can provide an abnormal prompt based on the abnormal message stored in the abnormal sub-queue.
[0167] In an optional implementation, the message processing device 700 may further include a sending module, configured to add instance code set information to the initial message body to obtain a composite message; and send the composite message to the message queue.
[0168] Since the principle of solving the problem by the message processing device 700 in the embodiment of the present application is similar to that of the embodiment of the aforementioned message processing method, the implementation of the message processing device 700 in this embodiment can refer to the description in the embodiment of the aforementioned message processing method, and the repeated parts will not be repeated.
[0169] An embodiment of the present application further provides a computer-readable storage medium, in which computer program instructions are stored. When the computer program instructions are read and executed by a processor, the steps of any one of the message processing methods provided in the embodiment are executed.
[0170] In several embodiments provided in the present application, it should be understood that the disclosed device can also be implemented in other ways. The device embodiments described above are merely schematic, for example, the block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices according to the multiple embodiments of the present application. In this regard, each box in the block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram, and the combination of the block diagrams, can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0171] In addition, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0172] If the function is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, and other media that can store program codes.
[0173] The above description is only an embodiment of the present application and is not intended to limit the scope of protection of the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the scope of protection of the present application. It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in the subsequent drawings.
[0174] The above description is only a specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application.
[0175] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "include..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.< / string> < / string> < / string> < / string>
Claims
1. A message processing method, applied in a terminal, characterized in that: The method comprises: Determine the instance code set information of all services on the terminal; Receive a target message sent by a message queue; wherein the target message includes a target message body and target set information; Determining whether to consume the target message according to the instance code set information; The determining of instance code set information of all services on the terminal includes: obtaining registration information of each of the services on the terminal; generating a unique instance code corresponding to each of the services based on the registration information and the network address information of the terminal; integrating all the instance codes to obtain the instance code set information; and storing the instance code set information in a local thread; The determining whether to consume the target message based on the instance code set information includes: parsing the target message to obtain the target message body and the target set information; reading the instance code set information from a local thread; comparing the target set information with the instance code set information; and if it is determined that the target set information is consistent with the instance code set information, consuming the target message body.
2. The method according to claim 1, characterized in that The comparing the target set information with the instance code set information includes: Comparing the number of target codes in the target set information and the number of instance codes in the instance code set information; If it is determined that the number of the target code and the instance code is consistent, then the target code and the instance code are compared; if each of the target codes has the same instance code, then it is determined that the target set information is consistent with the instance code set information; If the number of the target codes and the instance codes are inconsistent, or any of the target codes does not have the same instance code, it is determined that the target set information is inconsistent with the instance code set information.
3. The method according to claim 1, characterized in that The determining whether to consume the target message according to the instance code set information further includes: If it is determined that the target set information is inconsistent with the instance code set information, the target message is returned to the message queue so that the message queue can re-pollating and sending the target message.
4. The method according to any one of claims 1 to 3, characterized in that The method further comprises: If the target message is not consumed within a preset time period, the target message is marked as an abnormal message; The abnormal message is sent to the abnormal sub-queue of the message queue, so that the message queue can provide an abnormal prompt based on the abnormal message stored in the abnormal sub-queue.
5. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: Adding the instance code set information to the initial message body to obtain a composite message; The composite message is sent to the message queue.
6. A message processing device, applied in a terminal, characterized in that: The device comprises: a determination module, a receiving module and a processing module; The determination module is used to determine instance code set information of all services on the terminal; The receiving module is used to receive a target message sent by a message queue; wherein the target message includes a target message body and target set information; The processing module is used to determine whether to consume the target message according to the instance code set information; The determination module is specifically used to: obtain registration information of each of the services on the terminal; generate a unique instance code corresponding to each of the services based on the registration information and the network address information of the terminal; integrate all the instance codes to obtain the instance code set information; and store the instance code set information in a local thread; The processing module is specifically used to: parse the target message to obtain the target message body and the target collection information; read the instance code collection information from the local thread; compare the target collection information with the instance code collection information; if it is determined that the target collection information is consistent with the instance code collection information, consume the target message body.
7. An electronic device, characterized in that: The electronic device comprises a memory and a processor, wherein the memory stores program instructions, and when the processor runs the program instructions, the steps in the method according to any one of claims 1 to 5 are executed.
8. A computer-readable storage medium, characterized in that: The readable storage medium stores computer program instructions, and when the computer program instructions are executed by a processor, the steps in the method according to any one of claims 1 to 5 are executed.
Citation Information
Patent Citations
Information receiving and transmission method, information receiving and transmission system and information receiving and transmission device
CN104639291A
Communication Network System Of Bus Network Structure And Message Routing Method Using The System
US20080137638A1