Data processing method and device, electronic equipment and storage medium
The data processing method addresses inconsistent data formats in microservice architectures by standardizing response data through a preset format and interface adapter chain, enhancing development efficiency and reducing redundancy and errors.
Patent Information
- Application Number
- CN202411775483.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-05
- Publication Date
- 2025-01-03
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In microservice architectures, inconsistent data formats returned by back-end services due to different technology stacks and programming languages used by development teams lead to reduced development efficiency, code redundancy, and maintenance difficulties.
A data processing method that unifies the data format by receiving response data, checking its conformity to a preset format, and using an interface adapter chain to convert it into a standardized format through a target interface adapter.
Improves development efficiency, reduces code redundancy, and ensures data consistency and accuracy by unifying the data format returned by back-end services in microservice architectures.
Smart Images

Figure CN119248288A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of microservice technology, and in particular to a data processing method, device, electronic device and storage medium. Background Art
[0002] In a microservices architecture, backend services are usually designed as multiple independent and independently deployable microservices. The advantage of this architectural style is that it can improve the scalability, maintainability, and flexibility of the system. Each microservice can be independently developed and deployed by different teams based on business needs and technology selection.
[0003] In a microservice architecture, front-end and back-end microservices communicate through API interfaces. These API interfaces usually use the HTTP protocol and follow the RESTful style specification. However, since each microservice may be developed by a different team, using different technology stacks and programming languages, the data format returned by the back-end service is often inconsistent. And front-end developers need to spend a lot of time understanding and processing the data formats from different microservices. This not only reduces development efficiency, but may also lead to code redundancy and difficulty in maintenance. Summary of the invention
[0004] The embodiments of the present disclosure at least provide a data processing method, device, electronic device and storage medium, which can unify the data format returned by the back-end service to improve development efficiency, reduce code redundancy, and ensure the consistency and accuracy of the front-end when integrating data, thereby reducing data inconsistency and the occurrence of errors.
[0005] The present disclosure provides a data processing method, which is applied to a front-end service in a microservice architecture. The method includes: Receive response data returned by the backend service in response to the user's business request; Determining whether the response data conforms to a preset format, wherein the preset format predetermines the field types that the response data should include and the data type corresponding to each field type; If not, the response data is input into a preset interface adapter chain, and the matching relationship between the preset processing format corresponding to each interface adapter and the data format corresponding to the response data is detected in turn, until a target interface adapter matching the data format is determined; The data format is converted into the preset format through the target interface adapter.
[0006] In an optional implementation, in the preset format, the field types include at least a business action execution result field, a request response status field, a request result description field, and a business data field.
[0007] In an optional implementation manner, for the business action execution result field, the corresponding data type is a Boolean type; For the request response status field, the corresponding data type is an integer type; For the request result description field, the corresponding data type is a string type; For the business data field, the corresponding data type at least includes an object type or an array type or a null value.
[0008] In an optional implementation manner, determining whether the response data conforms to a preset format specifically includes: Determine a target field included in the response data and a target data type corresponding to the target field; Determining whether the target field includes all the field types in the preset format; If not, determining the missing field type, and generating field missing exception information describing the missing field type; If so, determining whether each of the target data types matches the corresponding data type in the preset format; If they match, determining that the response data conforms to the preset format; If there is no match, data type mismatch exception information is generated describing the mismatched data type.
[0009] In an optional implementation, the response data is input into a preset interface adapter chain, and the matching relationship between the preset processing format corresponding to each interface adapter and the data format corresponding to the response data is detected in turn until a target interface adapter matching the data format is determined, specifically including: In each of the interface adapters in the interface adapter chain, a matching method corresponding to a preset processing format of the interface adapter is predefined; Wherein, the matching method is used to determine whether the data format corresponding to the response data matches the preset processing format; According to the preset adapter sequence in the interface adapter chain, each interface adapter in the interface adapter chain is traversed in turn, and the matching method corresponding to each interface adapter is executed until a target interface adapter matching the data format is determined.
[0010] In an optional implementation manner, converting the data format into the preset format by the target interface adapter specifically includes: When receiving the field missing exception information, determining the type of the corresponding missing field; Add the missing field type to the corresponding data, and set a corresponding default value or a preset value for indicating field missingness for the missing field type; When the data type mismatch exception information is received, the target data type is converted into the data type corresponding to the preset format.
[0011] The present disclosure also provides a data processing device, which is applied to a front-end service in a microservice architecture. The device includes: A response data receiving module is used to receive the response data returned by the backend service in response to the user's business request; A format checking module, used to determine whether the response data conforms to a preset format, wherein the preset format predetermines the field types that the response data should include and the data type corresponding to each field type; An interface adapter matching module, for inputting the response data into a preset interface adapter chain if there is no match, and sequentially detecting the matching relationship between the preset processing format corresponding to each interface adapter and the data format corresponding to the response data, until a target interface adapter matching the data format is determined; The format conversion module is used to convert the data format into the preset format through the target interface adapter.
[0012] In an optional implementation manner, the format verification module is specifically used to: Determine a target field included in the response data and a target data type corresponding to the target field; Determining whether the target field includes all the field types in the preset format; If not, determining the missing field type, and generating field missing exception information describing the missing field type; If so, determining whether each of the target data types matches the corresponding data type in the preset format; If they match, determining that the response data conforms to the preset format; If there is no match, data type mismatch exception information is generated describing the mismatched data type.
[0013] An embodiment of the present disclosure also provides an electronic device, including: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the above-mentioned data processing method or steps in any possible implementation of the above-mentioned data processing method are performed.
[0014] The embodiment of the present disclosure further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the above-mentioned data processing method or the steps in any possible implementation of the above-mentioned data processing method are executed.
[0015] The embodiments of the present disclosure also provide a computer program product, including a computer program / instruction, which, when executed by a processor, implements the above-mentioned data processing method, or the steps in any possible implementation of the above-mentioned data processing method.
[0016] A data processing method, device, electronic device and storage medium provided by the embodiments of the present disclosure are applied to the front-end service in the microservice architecture, by receiving the response data returned by the back-end service in response to the user's business request; determining whether the response data conforms to a preset format, in which the field types that the response data should include and the data types corresponding to each field type are predefined; if not, the response data is input into a preset interface adapter chain, and the matching relationship between the preset processing format corresponding to each interface adapter and the data format corresponding to the response data is detected in turn, until a target interface adapter matching the data format is determined; the data format is converted to the preset format through the target interface adapter. The data format returned by the back-end service can be unified to improve development efficiency, reduce code redundancy, and ensure the consistency and accuracy of the front-end when integrating data, reducing data inconsistency and the occurrence of errors.
[0017] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following is a brief introduction to the drawings required for use in the embodiments. The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and are used together with the specification to illustrate the technical solutions of the present disclosure. It should be understood that the following drawings only illustrate certain embodiments of the present disclosure and should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can also be obtained based on these drawings without creative work.
[0019] Figure 1 A flow chart of a data processing method provided by an embodiment of the present disclosure is shown; Figure 2 A flowchart showing another data processing method provided by an embodiment of the present disclosure is shown; Figure 3A schematic diagram of a data processing device provided by an embodiment of the present disclosure is shown; Figure 4 A schematic diagram of an electronic device provided by an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0020] In order to make the purpose, technical scheme and advantages of the embodiments of the present disclosure clearer, the technical scheme in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. The components of the embodiments of the present disclosure generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the present disclosure for protection, but merely represents the selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present disclosure.
[0021] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0022] The term "and / or" herein only describes an association relationship, indicating that three relationships may exist. For example, A and / or B may represent the following three situations: A exists alone, A and B exist at the same time, and B exists alone. In addition, the term "at least one" herein represents any combination of at least two of any one or more of a plurality of. For example, including at least one of A, B, and C may represent including any one or more elements selected from the set consisting of A, B, and C.
[0023] According to research, in a microservice architecture, front-end and back-end microservices communicate through API interfaces. These API interfaces usually use the HTTP protocol and follow the RESTful style specification. However, since each microservice may be developed by a different team, using different technology stacks and programming languages, the data format returned by the back-end service is often inconsistent. In addition, front-end developers need to spend a lot of time understanding and processing the data formats from different microservices. This not only reduces development efficiency, but may also lead to code redundancy and difficulty in maintenance.
[0024] Based on the above research, the present disclosure provides a data processing method, device, electronic device and storage medium, which are applied to the front-end service in the microservice architecture, by receiving the response data returned by the back-end service in response to the user's business request; determining whether the response data conforms to a preset format, in which the field types that the response data should include and the data types corresponding to each field type are predefined; if not, the response data is input into a preset interface adapter chain, and the matching relationship between the preset processing format corresponding to each interface adapter and the data format corresponding to the response data is detected in turn, until a target interface adapter matching the data format is determined; the data format is converted to the preset format through the target interface adapter. The data format returned by the back-end service can be unified to improve development efficiency, reduce code redundancy, and ensure the consistency and accuracy of the front-end when integrating data, reducing data inconsistency and the occurrence of errors.
[0025] To facilitate understanding of this embodiment, a data processing method disclosed in the embodiment of the present disclosure is first introduced in detail. The execution subject of the data processing method provided in the embodiment of the present disclosure is generally a computer device with certain computing capabilities, and the computer device includes, for example: a terminal device or a server or other processing device, and the terminal device can be a user equipment (User Equipment, UE), a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (Personal Digital Assistant, PDA), a handheld device, a computing device, a vehicle-mounted device, a wearable device, etc. In some possible implementations, the data processing method can be implemented by a processor calling a computer-readable instruction stored in a memory.
[0026] See also Figure 1 FIG. 1 is a flowchart of a data processing method provided by an embodiment of the present disclosure, wherein the method includes steps S101 to S104, wherein: S101: Receive response data returned by a backend service in response to a user service request.
[0027] In the specific implementation, encapsulate an HTTP request library based on axios and export a component instance named `request`. Front-end developers should uniformly use this `request` instance to make HTTP requests as user business requests. The `request` instance includes common request methods such as GET, POST, PUT, and DELETE. This ensures the standardization and consistency of the request, and facilitates the subsequent unified configuration and management of the request. In the encapsulation component of axios, the response interceptor is used to intercept the response data returned by the back-end interface to obtain the response data returned by the back-end service in response to the user's business request.
[0028] For example, in a microservice architecture for an online shopping application, one of the functions is to allow users to add items to a shopping cart. The user business request can be for a user to try to add an item to a shopping cart. The backend service checks whether the item exists, whether the user is logged in, and other information, and returns response data.
[0029] S102: Determine whether the response data conforms to a preset format, where the preset format predefines field types that the response data should include and data types corresponding to each field type.
[0030] In the specific implementation, in order to ensure that the front-end can consistently process all data returned by the back-end, a unified response data format specification, that is, a preset format, is defined. After using the response interceptor in the axios encapsulation component to intercept the response data returned by the back-end interface, a data validator is used to check whether the response data complies with the unified data format specification. If it complies, the parsed data is directly returned.
[0031] Here, in the preset format, the field types include at least a business action execution result field, a request response status field, a request result description field, and a business data field. For the business action execution result field, the corresponding data type is a Boolean type; for the request response status field, the corresponding data type is an integer type; for the request result description field, the corresponding data type is a string type; for the business data field, the corresponding data type includes at least an object type or an array type or a null value.
[0032] Among them, the business action execution result field is used to identify whether the specific business action executed by the backend service is successful, such as querying user information, adding products to the shopping cart, etc. The results of these operations may be successful or may fail due to some reasons; the request response status field is used to identify the response status of the backend service to the front-end request, including whether the operation is successful, what errors occurred, etc.; the request result description field describes the text information of the request result, which is used for front-end display or debugging; the business data field is the actual returned business data, which may contain different fields depending on the interface.
[0033] Exemplarily, the preset format can be the following JSON structure: {"success": Boolean type, "code": integer type, "message": string type, "data": object / array / empty,}, where "success" represents the business action execution result field, "code" represents the request response status field, "message" represents the request result description field, and "data" represents the business data field.
[0034] It should be noted that the preset format requires that the http status code returned by the backend is a preset value, which can be set according to actual needs, such as 200, to separate business logic from HTTP protocol. In this way, front-end developers no longer need to write different error handling logic according to different HTTP status codes, but only need to pay attention to the business action execution result field and request response status field in the 200 status code response body.
[0035] Here, the HTTP status code is mainly used to describe the processing status of the HTTP request, while the success or failure of the business logic should be defined by the business party. Separating the two can improve the clarity and maintainability of the code.
[0036] For example, for the microservice architecture of online shopping applications, the user business request can be a user trying to add a product to the shopping cart. The backend service checks whether the product exists, whether the user is logged in, and other information, and returns the response data. In any case, the backend always returns the HTTP status code 200 OK, indicating that the HTTP request has been successfully processed. In the response body, the backend returns a structure response data containing the business logic status, such as {"success": boolean, "code": integer, "message": string, "data": object / array / null}. If the product is successfully added to the shopping cart, "success" is true, "code" is a custom success code (such as 200), "message" is a success message, and "data" contains the updated information of the shopping cart. If the product does not exist or the user is not logged in, "success" is false, "code" is a custom error code (such as 4001 for product does not exist, 4002 for user not logged in), "message" is the corresponding error description, and "data" is empty or contains additional error information.
[0037] As a possible implementation, see Figure 2 FIG. 1 is a flowchart of another data processing method provided by an embodiment of the present disclosure, wherein the method includes steps S1021 to S1024, wherein: S1021. Determine a target field included in the response data and a target data type corresponding to the target field.
[0038] S1022: Determine whether the target field includes all the field types in the preset format.
[0039] S1023. If not, determine the missing field type and generate field missing exception information describing the missing field type; if yes, determine whether each of the target data types matches the corresponding data type in the preset format.
[0040] S1024. If there is a match, determine that the response data conforms to the preset format; if there is a mismatch, generate data type mismatch exception information describing the mismatched data type.
[0041] In the specific implementation, in order to verify whether the response data returned by the backend conforms to the preset format specifications, a data validator needs to be implemented, which performs verification after receiving the response data of the user's business request. As an important tool to ensure that the data conforms to the specifications, the data validator can verify whether the data returned by the backend follows the format specifications of the preset format, thereby ensuring that the front end can correctly parse and display the data.
[0042] Here, the data verifier verifies whether the response structure is complete, that is, whether it contains the business action execution result field, the request response status field, the request result description field, and the business data field. It also verifies whether the business action execution result field is of Boolean type, the request response status field is of integer type, the request result description field is of string type, and the business data field is of the expected data type (object, array, or null value).
[0043] It should be noted that the validator can be an independent JavaScript function that receives the axios response object as a parameter and returns the validation result.
[0044] Specifically, when the axios request is completed, a callback function is triggered. The validator module or function receives the response data as input from the callback function. The validator checks whether the response data contains all the necessary fields. If any necessary fields are missing, an exception describing the missing fields is immediately thrown.
[0045] After that, the validator traverses each field in the response data. For each field, the validator verifies whether its data type matches the type specified in the preset format. If the data type of any field is found to not match, an exception describing the type mismatch is thrown.
[0046] Here, if all checks pass, the validator returns a status indicating success, such as true, and the caller can continue to process the response data. If the check fails, the caller needs to catch the exception and print it.
[0047] It should be noted that the code that calls the data validator needs to be able to process the return result of the validator or catch the exception it throws.
[0048] S103. If not, the response data is input into a preset interface adapter chain, and the matching relationship between the preset processing format corresponding to each interface adapter and the data format corresponding to the response data is detected in turn, until a target interface adapter matching the data format is determined.
[0049] In the specific implementation, in order to efficiently process the backend response data format that does not conform to the specification, it is necessary to design a set of interface adapters, which are organized in a chain form and can adapt to different data formats without modifying the original axios component encapsulation. Each interface adapter is executed sequentially in the interface adapter chain, starting from the first interface adapter, and the backend response data is checked one by one until a matching interface adapter is found for data format conversion.
[0050] Here, the interface adapter chain is organized in an array, and the interface adapters are sorted according to usage frequency, processing priority, or other business logic. This design allows us to flexibly add, remove, or reorder interface adapters to meet the data processing needs of different projects. By properly configuring the interface adapter chain, we can ensure that the backend response data is accurately and efficiently converted into the format.
[0051] Specifically, in each interface adapter in the interface adapter chain, a matching method for the interface adapter corresponding to a preset processing format is predefined; wherein the matching method is used to determine whether the data format corresponding to the response data matches the preset processing format; according to the preset adapter order in the interface adapter chain, each interface adapter in the interface adapter chain is traversed in turn, and the matching method corresponding to each interface adapter is executed until a target interface adapter that matches the data format is determined.
[0052] Here, starting from the first interface adapter in the adapter chain, the program will traverse the interface adapter array one by one. For the currently traversed interface adapter, the program will call its pre-defined matching method and pass the backend response data as a parameter. The matching method is responsible for determining whether the response data conforms to the preset processing format of the adapter. The matching method returns a Boolean value to indicate the matching result. If true is returned, it means that a matching interface adapter is found; if false is returned, the next interface adapter will be traversed.
[0053] Preferably, if no matching interface adapter is found after traversing the entire interface adapter chain (ie, the matching methods of all adapters return false), some default processing measures need to be taken, such as throwing an exception.
[0054] It should be noted that the interface adapter chain executes the matching method of each adapter in the defined preset adapter order. This sequential matching mechanism allows the system to try to find an adapter that can handle a specific data format in order. Once a matching method of an interface adapter is found and returns true, the interface adapter chain will stop calling subsequent matching methods because an interface adapter that can handle the data has been found.
[0055] Among them, the preset adapter order can be set according to the frequency of use, processing priority and performance considerations. Adapters can be sorted according to the frequency of their use. For example, if the data format processed by an adapter is very common, it should be placed in front of the adapter chain so that it can be found and executed as soon as possible. This sorting method can optimize performance because common data formats can be processed in a shorter time. Adapters can also be sorted according to processing priority. This depends on the importance of business logic and data. For example, if the data format processed by an adapter is critical to the business, it should have a higher priority and be placed in front of the adapter chain. Adapters with high priority will be tried to match first to ensure that important data is processed first. When sorting adapters, the performance differences of each adapter can also be considered. If an adapter processes data faster, it can be placed in front to reduce the overall response time. On the contrary, if an adapter processes data slower, it can be placed at the back to reduce the impact on overall performance.
[0056] S104: Convert the data format into the preset format through the target interface adapter.
[0057] In a specific implementation, when field missing exception information is received, the corresponding missing field type is determined; the missing field type is added to the corresponding data, and a corresponding default value or a preset value for indicating field missing is set for the missing field type; when data type mismatch exception information is received, the target data type is converted to the corresponding data type in the preset format.
[0058] Here, in the architecture of the interface adapter chain, each interface adapter has clear responsibilities defined: first, the matching method is used to determine whether the response data conforms to its expected format. If it matches, the data conversion method is further called to perform necessary conversions on the data. The matching method returns a Boolean value to indicate the matching result, while the data conversion method is responsible for performing the data conversion operation, returning the converted data object or throwing an exception when the conversion fails.
[0059] Among them, the data conversion method converts the different data formats returned by different backend services into a unified, standardized preset format, which helps the unified processing of the front-end code and reduces the complexity caused by data format differences. In this process, the non-standard data structure and data content returned by the back-end are identified and reassembled into a unified standard data structure, field, type and value on the front-end.
[0060] Specifically, the conversion process includes data type conversion, default value setting, and null value processing. For data type conversion, the data type returned by the backend that does not meet the frontend's expectations is converted to the correct type. This helps the frontend to perform correct data operations and display. For example, the backend returns an ID of string type, but the frontend needs to use it as an index of numeric type. The interface adapter can convert the string to a number. For default value setting and null value processing, when some fields are missing or the field values are empty in the data returned by the backend, default values are set for these fields or specific null value processing is performed. This helps the frontend avoid errors caused by missing data. For example, the description field may be missing in the JSON object returned by the backend. The adapter can set a default value for the field or return a specific value indicating missingness.
[0061] Optionally, the data conversion method can also remove unnecessary fields or data in the data returned by the backend and verify the integrity and accuracy of the data. This helps reduce the amount of data processed by the frontend and improve the robustness of the application. For example, the JSON object returned by the backend may contain sensitive information or fields that are not required by the frontend. The adapter can remove these fields and verify the validity of the remaining fields.
[0062] Below, we will explain the above solution with a specific example: a specific example shows how to process RESTful API response data in different formats: Set the success and failure response specifications: the return format for success: {"data": "object or array"}, the return format for failure: {"error": "error description"}. In order to handle this format, you can set an interface adapter in the interface adapter chain, which will check whether only the data field or the error field exists in the response data. If only the data field exists and the http request status is 200, it is considered a successful response and the following data is returned: {"success": true, "code": 200, "message": null, "data": data, / / data is the data field data returned by the interface}; If only the error field exists and the http request status is not 200, it is considered a failed response and the following data is returned: {"success": false, "code": http status code, "message": error, / / error is the error field data returned by the interface, "data": null} In this way, through the above processing, all request data that does not meet the specifications will be converted into standard data through the matching adapter in the adapter chain, so that the way all front-end interfaces process data is unified.
[0063] A data processing method provided by the embodiment of the present disclosure is applied to the front-end service in the microservice architecture, by receiving the response data returned by the back-end service in response to the user's business request; determining whether the response data conforms to a preset format, in which the field types that the response data should include and the data types corresponding to each field type are predefined; if not, the response data is input into a preset interface adapter chain, and the matching relationship between the preset processing format corresponding to each interface adapter and the data format corresponding to the response data is detected in turn, until a target interface adapter matching the data format is determined; the data format is converted to the preset format through the target interface adapter. The data format returned by the back-end service can be unified to improve development efficiency, reduce code redundancy, and ensure the consistency and accuracy of the front-end when integrating data, reducing data inconsistency and the occurrence of errors.
[0064] Those skilled in the art will appreciate that, in the above method of specific implementation, the order in which the steps are written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of the steps should be determined by their functions and possible internal logic.
[0065] Based on the same inventive concept, a data processing device corresponding to the data processing method is also provided in the embodiment of the present disclosure. Since the principle of solving the problem by the device in the embodiment of the present disclosure is similar to the above-mentioned data processing method in the embodiment of the present disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated.
[0066] See also Figure 3 , Figure 3 Schematic diagram of a data processing device provided by an embodiment of the present disclosure. Figure 3 As shown in , the data processing device 300 provided in the embodiment of the present disclosure is applied to the front-end service in the microservice architecture, including: The response data receiving module 310 is used to receive the response data returned by the backend service in response to the user's business request.
[0067] The format checking module 320 is used to determine whether the response data conforms to a preset format, in which the preset format predetermines the field types that the response data should include and the data type corresponding to each field type.
[0068] The interface adapter matching module 330 is used to input the response data into a preset interface adapter chain if there is no match, and sequentially detect the matching relationship between the preset processing format corresponding to each interface adapter and the data format corresponding to the response data until a target interface adapter matching the data format is determined.
[0069] The format conversion module 340 is used to convert the data format into the preset format through the target interface adapter.
[0070] For descriptions of the processing flow of each module in the device and the interaction flow between each module, reference may be made to the relevant descriptions in the above method embodiment, which will not be described in detail here.
[0071] A data processing device provided by the embodiment of the present disclosure is applied to the front-end service in the microservice architecture, by receiving the response data returned by the back-end service in response to the user's business request; determining whether the response data conforms to a preset format, in which the field types that the response data should include and the data types corresponding to each field type are predefined; if not, the response data is input into a preset interface adapter chain, and the matching relationship between the preset processing format corresponding to each interface adapter and the data format corresponding to the response data is detected in turn, until a target interface adapter matching the data format is determined; the data format is converted to the preset format through the target interface adapter. The data format returned by the back-end service can be unified to improve development efficiency, reduce code redundancy, and ensure the consistency and accuracy of the front-end when integrating data, reducing data inconsistency and the occurrence of errors.
[0072] Corresponds to Figure 1 The data processing method in the present disclosure also provides an electronic device 400, such as Figure 4 FIG. 4 is a schematic diagram of the structure of an electronic device 400 provided in an embodiment of the present disclosure, including: Processor 41, memory 42, and bus 43; memory 42 is used to store execution instructions, including memory 421 and external memory 422; memory 421 here is also called internal memory, which is used to temporarily store operation data in processor 41 and data exchanged with external memory 422 such as hard disk. Processor 41 exchanges data with external memory 422 through memory 421. When the electronic device 400 is running, the processor 41 communicates with the memory 42 through bus 43, so that the processor 41 executes Figure 1 The steps of the data processing method.
[0073] The present disclosure also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the data processing method described in the above method embodiment are executed. The storage medium can be a volatile or non-volatile computer-readable storage medium.
[0074] The present disclosure also provides a computer program product, which includes computer instructions. When the computer instructions are executed by a processor, the steps of the data processing method described in the above method embodiment can be executed. For details, please refer to the above method embodiment, which will not be repeated here.
[0075] The computer program product may be implemented in hardware, software or a combination thereof. In one optional embodiment, the computer program product is implemented as a computer storage medium. In another optional embodiment, the computer program product is implemented as a software product, such as a software development kit (SDK).
[0076] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working process of the device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. In the several embodiments provided in the present disclosure, it should be understood that the disclosed device and method can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the device or unit can be electrical, mechanical or other forms.
[0077] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0078] In addition, each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0079] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present disclosure, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present disclosure. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0080] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present disclosure, which are used to illustrate the technical solutions of the present disclosure, rather than to limit them. The protection scope of the present disclosure is not limited thereto. Although the present disclosure is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed in the present disclosure, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.
Claims
1. A data processing method, characterized in that: Applied to the front-end service in the microservice architecture, the method includes: Receive response data returned by the backend service in response to the user's business request; Determining whether the response data conforms to a preset format, wherein the preset format predetermines the field types that the response data should include and the data type corresponding to each field type; If not, the response data is input into a preset interface adapter chain, and the matching relationship between the preset processing format corresponding to each interface adapter and the data format corresponding to the response data is detected in turn, until a target interface adapter matching the data format is determined; The data format is converted into the preset format through the target interface adapter.
2. The method according to claim 1, characterized in that: In the preset format, the field types include at least a business action execution result field, a request response status field, a request result description field, and a business data field.
3. The method according to claim 2, characterized in that: For the business action execution result field, the corresponding data type is a Boolean type; For the request response status field, the corresponding data type is an integer type; For the request result description field, the corresponding data type is a string type; For the business data field, the corresponding data type at least includes an object type or an array type or a null value.
4. The method according to claim 1, characterized in that: Determining whether the response data conforms to a preset format specifically includes: Determine a target field included in the response data and a target data type corresponding to the target field; Determining whether the target field includes all the field types in the preset format; If not, determining the missing field type, and generating field missing exception information describing the missing field type; If so, determining whether each of the target data types matches the corresponding data type in the preset format; If they match, determining that the response data conforms to the preset format; If there is no match, data type mismatch exception information is generated describing the mismatched data type.
5. The method according to claim 1, characterized in that Inputting the response data into a preset interface adapter chain, sequentially detecting a matching relationship between a preset processing format corresponding to each interface adapter and a data format corresponding to the response data, until a target interface adapter matching the data format is determined, specifically comprising: In each of the interface adapters in the interface adapter chain, a matching method corresponding to a preset processing format of the interface adapter is predefined; Wherein, the matching method is used to determine whether the data format corresponding to the response data matches the preset processing format; According to the preset adapter sequence in the interface adapter chain, each interface adapter in the interface adapter chain is traversed in turn, and the matching method corresponding to each interface adapter is executed until a target interface adapter matching the data format is determined.
6. The method according to claim 4, characterized in that Converting the data format into the preset format through the target interface adapter specifically includes: When receiving the field missing exception information, determining the type of the corresponding missing field; Add the missing field type to the response data, and set a corresponding default value or a preset value for indicating field missingness for the missing field type; When the data type mismatch exception information is received, the target data type is converted into the data type corresponding to the preset format.
7. A data processing device, characterized in that: Applied to front-end services in a microservice architecture, the device comprises: A response data receiving module is used to receive the response data returned by the backend service in response to the user's business request; A format checking module, used to determine whether the response data conforms to a preset format, wherein the preset format predetermines the field types that the response data should include and the data type corresponding to each field type; An interface adapter matching module, for inputting the response data into a preset interface adapter chain if there is no match, and sequentially detecting the matching relationship between the preset processing format corresponding to each interface adapter and the data format corresponding to the response data, until a target interface adapter matching the data format is determined; The format conversion module is used to convert the data format into the preset format through the target interface adapter.
8. The device according to claim 7, characterized in that The format verification module is specifically used for: Determine a target field included in the response data and a target data type corresponding to the target field; Determining whether the target field includes all the field types in the preset format; If not, determining the missing field type, and generating field missing exception information describing the missing field type; If so, determining whether each of the target data types matches the corresponding data type in the preset format; If they match, determining that the response data conforms to the preset format; If there is no match, data type mismatch exception information is generated describing the mismatched data type.
9. An electronic device, characterized in that: include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps of the data processing method as described in any one of claims 1 to 6 are performed.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the data processing method according to any one of claims 1 to 6 are executed.
Citation Information
Patent Citations
Error tolerance processing method and apparatus for data
CN105653383A
Abnormality processing method and device, electronic equipment and readable storage medium
CN113626234A
Packet return data verification method and device, electronic equipment and storage medium
CN116805948A
Multi-modal data processing method and system, electronic equipment and storage medium
CN118363730A
General interactive service system based on hospital big data
CN118689671A
Cited By
Parameter data transmission method and device, electronic equipment and storage medium
CN120994726A