Data interface service method, device, equipment and medium based on FlaskRestful framework
Through the data interface service method based on the FlaskRestful framework, the problems of non-standard interfaces and high costs in data services are solved, the standardized construction of interfaces and the standardization of data flow are realized, the development costs are reduced, and the efficiency and quality are improved.
Patent Information
- Application Number
- CN202210168412.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-23
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2042-02-23
AI Technical Summary
In the existing data service process, data interface services are not standardized and costly, resulting in high costs for repeated interface construction, development, modification and maintenance.
Using the data interface service method based on the FlaskRestful framework, by responding to client requests, determine the target interface type and data flow type, obtain the pre-configured interface development logic mapping table, use Python language to build the target interface, and use Nginx reverse proxy for load Balance to achieve data flow and interface standardization.
It realizes the standardized construction of interfaces, reduces development costs, improves development efficiency and quality, ensures the reliability of services and the processing of different types of data transfer, and saves development costs.
Smart Images

Figure CN114706910B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of big data technology, and in particular to a data interface service method, device, equipment and medium based on a FlaskRestful framework. Background Art
[0002] With the booming development of the big data era, how to explore the potential value of data has become an important part of enterprises' challenge of digital transformation or the improvement of their core competitiveness. More and more companies are beginning to pay attention to the storage and accumulation of data, build their own data warehouses, and on this basis, build core data assets such as portrait systems, recommendation systems, and pricing systems. Data assets are like the water resources needed by enterprises in daily life. They are ubiquitous and indispensable, but if there are no corresponding water processing plants and transportation pipelines, each business department can only go to the reservoir to fetch water, which greatly affects the enthusiasm of the business departments and easily causes confusion in data assets.
[0003] Therefore, encapsulating data assets into data services and using interface services to respond to various customized application scenarios at the upper level can greatly tap and release the value of data assets.
[0004] However, in the existing data service process, a large number of data interfaces are independently built to connect with application products based on the needs of a certain scenario, resulting in duplicate construction of interfaces and relatively high costs for development, modification, maintenance, and monitoring. Summary of the invention
[0005] The embodiments of the present invention provide a data interface service method, device, equipment and medium based on the FlaskRestful framework, aiming to solve the problems of non-standard and high cost of data interface services.
[0006] In a first aspect, an embodiment of the present invention provides a data interface service method based on a FlaskRestful framework, which includes:
[0007] In response to a data request initiated by a client to the FlaskRestful framework, a target interface type and a target data flow type are determined according to the data request;
[0008] Obtain a pre-configured interface development logic mapping table corresponding to the interface type, and use the target interface type to query in the interface development logic mapping table to obtain the target interface development logic corresponding to the target interface type;
[0009] Using Python language, construct the target interface based on the target interface development logic;
[0010] Obtain the Gunicorn server cluster and Nginx reverse proxy deployed in the FlaskRestful framework, and use the Nginx reverse proxy to perform load balancing on the Gunicorn server cluster to obtain the target server;
[0011] Calling the target interface to connect to the target server, and performing data flow in the target server based on the target data flow type to obtain target data;
[0012] The target data is fed back to the client.
[0013] According to a preferred embodiment of the present invention, constructing a target interface based on the target interface development logic includes:
[0014] When there is a new data source, an algo file, an API file and public variables are added based on the algorithm logic of the new data source, and the algo file, the API file, the database file and the public variables are encapsulated as a first interface to be tested, and the first interface to be tested is deployed in the FlaskRestful framework. After the deployment is completed, the first interface to be tested is tested, and when the first interface to be tested passes the test, the first interface to be tested is determined as the target interface; or
[0015] When there is no new data source, add an algo file and an API file, and encapsulate the algo file and the API file to obtain a second interface to be tested, deploy the second interface to be tested in the FlaskRestful framework, and after the deployment is completed, test the second interface to be tested, query the interface log generated during the test, and when the interface log shows that the second interface to be tested passes the test, publish the second interface to be tested to the production environment, or when the interface log shows that the second interface to be tested fails the test, repair the second interface to be tested.
[0016] According to a preferred embodiment of the present invention, constructing a target interface based on the target interface development logic further comprises:
[0017] For the sub-interface of the search server ES type in the target interface, a new engine and ES sub-interface are created on the specified search platform;
[0018] Create a new Flink task on the real-time computing platform based on the engine and the ES sub-interface;
[0019] Test the Flink task;
[0020] When the Flink task passes the test, the ES sub-interface is published to the specified platform; or
[0021] When the Flink task fails the test, the ES sub-interface is repaired.
[0022] According to a preferred embodiment of the present invention, the use of the Nginx reverse proxy to perform load balancing on the Gunicorn server cluster to obtain the target server includes:
[0023] Using the Nginx reverse proxy to poll each server in the Gunicorn server cluster, and determining the currently polled server as the target server; and / or
[0024] The request address of the client is obtained, and the target server is obtained from the Gunicorn server cluster according to the request address.
[0025] According to a preferred embodiment of the present invention, the data is transferred in the target server based on the target data transfer type to obtain the target data, including:
[0026] Obtaining data to be processed from the target server;
[0027] When the target data flow type is an offline type, the data to be processed is processed in a data warehouse to obtain label information of the data to be processed, the label information of the data to be processed is pushed to a relational database, and the label information of the data to be processed is pushed from the relational database to a cache, the label information of the data to be processed is read from the cache, and a data structure conversion tool is used to convert the label information of the data to be processed into tabular data to obtain the target data; or
[0028] When the target data flow type is a real-time type, the data to be processed is stored in a preset middleware, and the data to be processed is read from the preset middleware into a message queue, the data to be processed is read from the message queue, and the data to be processed is pushed to the cache, the data to be processed is read from the cache, and the data structure conversion tool is used to convert the data to be processed into the table data to obtain the target data; or
[0029] When the target data flow type is an offline and real-time coexistence type, the data to be processed is processed in the data warehouse to obtain label information of the data to be processed, the label information of the data to be processed is processed using a stream processing framework, and the processed label information of the data to be processed is pushed to a search server, based on the search server, the processed label information of the data to be processed is sent to a preset interface, and the data returned by the preset interface is received as the target data.
[0030] According to a preferred embodiment of the present invention, when data is transferred in the target server based on the target data transfer type, the method further includes:
[0031] Obtaining an HTTP request to the target server;
[0032] Determine whether to respond to the HTTP request based on the response middleware in the target server;
[0033] When it is determined to respond to the HTTP request, the router configuration component of the target server parses the HTTP request to obtain a parsing result;
[0034] Send the parsing result to the view response middleware for processing to obtain a view processing result;
[0035] Use the global exception handling plug-in to monitor the view processing result;
[0036] When the view processing result is abnormal, the view processing result is sent to the exception processing middleware for processing to obtain the exception processing result, and the exception processing result is returned through the response middleware; or
[0037] When there is no exception in the view processing result, the view processing result is returned through the response middleware.
[0038] According to a preferred embodiment of the present invention, when data is transferred in the target server based on the target data transfer type, the method further includes:
[0039] Obtain each process during data flow, and obtain the process management tool deployed in the FlaskRestful framework;
[0040] Using the process management tool to monitor each process;
[0041] When a process is detected to have exited abnormally, the detected process is identified as the target process;
[0042] Restarting the target process;
[0043] When the target process fails to be restarted, a pre-configured times threshold is obtained, and when the number of restarts of the target process reaches the times threshold, the target process is terminated.
[0044] In a second aspect, an embodiment of the present invention provides a data interface service device based on a FlaskRestful framework, comprising:
[0045] A determination unit, configured to respond to a data request initiated by a client to a FlaskRestful framework, and determine a target interface type and a target data flow type according to the data request;
[0046] A query unit, used to obtain a pre-configured interface development logic mapping table corresponding to the interface type, and query the interface development logic mapping table using the target interface type to obtain a target interface development logic corresponding to the target interface type;
[0047] A construction unit, used to construct a target interface based on the target interface development logic using Python language;
[0048] An execution unit is used to obtain a Gunicorn server cluster and an Nginx reverse proxy deployed in the FlaskRestful framework, and use the Nginx reverse proxy to perform load balancing on the Gunicorn server cluster to obtain a target server;
[0049] A transfer unit, configured to call the target interface to connect to the target server, and perform data transfer in the target server based on the target data transfer type to obtain target data;
[0050] A feedback unit is used to feed back the target data to the client.
[0051] In the third aspect, an embodiment of the present invention further provides a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the data interface service method based on the FlaskRestful framework described in the first aspect is implemented.
[0052] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor executes the data interface service method based on the FlaskRestful framework described in the first aspect above.
[0053] The embodiment of the present invention provides a data interface service method, device, equipment and medium based on the FlaskRestful framework, which can respond to a data request initiated by a client to the FlaskRestful framework, determine the target interface type and the target data flow type according to the data request, and the FlaskRestful framework can provide lightweight access, obtain a pre-configured interface development logic mapping table corresponding to the interface type, and use the target interface type to query in the interface development logic mapping table to obtain the target interface development logic corresponding to the target interface type, use Python language to build a target interface based on the target interface development logic, Python language has good support for data mining algorithms, and at the same time realizes the standardized construction of the interface, and obtains the FlaskRestful l The Gunicorn server cluster and Nginx reverse proxy are deployed in the framework, and the Nginx reverse proxy is used to perform load balancing on the Gunicorn server cluster to obtain the target server to avoid putting pressure on the server, call the target interface to connect to the target server, and perform data flow in the target server based on the target data flow type to obtain the target data, standardize the data flow to achieve data flow under different types, and process and handle the data in a targeted manner, and feed back the target data to the client, so as to combine various types of services based on the FlaskRestful framework to ensure the reliability of the services and the standardization of various types of interfaces, which also saves development costs and ensures development quality and efficiency to provide better data support. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying any creative work.
[0055] Figure 1 A flow chart of a data interface service method based on the FlaskRestful framework provided in an embodiment of the present invention;
[0056] Figure 2 A schematic block diagram of a data interface service device based on the FlaskRestful framework provided in an embodiment of the present invention;
[0057] Figure 3 A schematic block diagram of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0058] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0059] It should be understood that when used in this specification and the appended claims, the terms "include" and "comprises" indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.
[0060] It should also be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.
[0061] It should be further understood that the term "and / or" used in the present description and the appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0062] See also Figure 1 , which is a flow chart of a data interface service method based on the FlaskRestful framework provided in an embodiment of the present invention.
[0063] S10, in response to a data request initiated by the client to the FlaskRestful framework, determining a target interface type and a target data flow type according to the data request.
[0064] In at least one embodiment of the present invention, the FlaskRestful framework is a Python webservice framework that can provide lightweight Http (Hyper Text Transfer Protocol) access.
[0065] In at least one embodiment of the present invention, the client may include any type of user terminal.
[0066] For example, when a user wants to obtain user data through the FlaskRestful framework to perform user preference analysis, the data request can be initiated to the FlaskRestful framework through the user's client.
[0067] In at least one embodiment of the present invention, by parsing the data request, relevant information carried by the data request, such as: the target interface type, the target data flow type, etc., can be acquired.
[0068] The target interface type may include, but is not limited to, any one of the following: an algorithm-based interface development type, a rule-based interface development type, and a process-based interface development type.
[0069] The target data flow type may include, but is not limited to, any one of the following: an offline type, a real-time type, and an offline and real-time coexistence type.
[0070] S11, obtaining a pre-configured interface development logic mapping table corresponding to the interface type, and using the target interface type to query in the interface development logic mapping table to obtain a target interface development logic corresponding to the target interface type.
[0071] In at least one embodiment of the present invention, the interface development logic mapping table is used to store the correspondence between the interface development logic and the interface type.
[0072] In at least one embodiment of the present invention, the querying in the interface development logic mapping table using the target interface type to obtain the target interface development logic corresponding to the target interface type comprises:
[0073] Matching the target interface type with the interface type stored in the interface development logic mapping table;
[0074] Obtaining the interface type that matches the target interface type and using it as the target type;
[0075] The interface development logic corresponding to the target type and stored in the interface development logic mapping table is determined as the target interface development logic.
[0076] S12, using Python language to build a target interface based on the target interface development logic.
[0077] In at least one embodiment of the present invention, the Python language has good support for data mining algorithms. Therefore, algorithm empowerment can be better performed based on the Python language, and since it is less error-prone, it is relatively friendly to data developers.
[0078] In at least one embodiment of the present invention, constructing a target interface based on the target interface development logic includes:
[0079] When there is a new data source, an algo file, an API (Application Programming Interface) file, a database (datebase, db) file and public variables are added based on the algorithm logic of the new data source, and the algo file, the API file, the database file and the public variables are encapsulated as a first interface to be tested, and the first interface to be tested is deployed in the FlaskRestful framework. After the deployment is completed, the first interface to be tested is tested, and when the first interface to be tested passes the test, the first interface to be tested is determined as the target interface; or
[0080] When there is no new data source, add an algo file and an API file, and encapsulate the algo file and the API file to obtain a second interface to be tested, deploy the second interface to be tested in the FlaskRestful framework, and after the deployment is completed, test the second interface to be tested, query the interface log generated during the test, and when the interface log shows that the second interface to be tested passes the test, publish the second interface to be tested to the production environment, or when the interface log shows that the second interface to be tested fails the test, repair the second interface to be tested.
[0081] It should be noted that after the second interface to be tested is repaired, the repaired second interface to be tested is redeployed to the FlaskRestful framework, and retested after deployment, through continuous repair, deployment, and testing until the second interface to be tested passes the test.
[0082] Through the above implementation, different interface construction processes can be executed according to whether there is a new data source.
[0083] In at least one embodiment of the present invention, constructing a target interface based on the target interface development logic further comprises:
[0084] For the sub-interface of the search server ES (Elastic Search) type in the target interface, a new engine and ES sub-interface are created on the specified search platform;
[0085] Create a new Flink task on the real-time computing platform based on the engine and the ES sub-interface;
[0086] Test the Flink task;
[0087] When the Flink task passes the test, the ES sub-interface is published to the specified platform; or
[0088] When the Flink task fails the test, the ES sub-interface is repaired.
[0089] The designated search platform may be any search platform that supports ES.
[0090] The designated platform may include a BDP platform.
[0091] It should be noted that after the ES sub-interface is repaired, a new Flink task is created based on the repaired ES sub-interface, and the repair, creation and testing are continued until the ES sub-interface passes the test.
[0092] After the interface is built, interface development for different scenarios only requires modifying a few parameters based on specific business content.
[0093] For example, the flow of data has been standardized. If a new interface needs to use new data, it only needs to modify the configuration information without redeveloping the entire data access process.
[0094] Through the above implementation, interfaces with the same service type can be uniformly encapsulated to avoid repeated construction of interfaces, improve service efficiency, and enhance code reuse.
[0095] S13, obtaining the Gunicorn server cluster and Nginx reverse proxy deployed in the FlaskRestful framework, and using the Nginx reverse proxy to perform load balancing on the Gunicorn server cluster to obtain the target server.
[0096] In at least one embodiment of the present invention, the Gunicorn server is a widely used high-performance Python WSGI UNIX HTTP Server.
[0097] In at least one embodiment of the present invention, the Nginx reverse proxy is a high-performance HTTP and reverse proxy web server for request load balancing.
[0098] In at least one embodiment of the present invention, the use of the Nginx reverse proxy to perform load balancing on the Gunicorn server cluster to obtain the target server includes:
[0099] Using the Nginx reverse proxy to poll each server in the Gunicorn server cluster, and determining the currently polled server as the target server; and / or
[0100] The request address of the client is obtained, and the target server is obtained from the Gunicorn server cluster according to the request address.
[0101] Through the above implementation, different modes of load balancing can be implemented based on Nginx middleware in the FlaskRestful framework to avoid putting pressure on the server.
[0102] S14, calling the target interface to connect to the target server, and performing data flow in the target server based on the target data flow type to obtain target data.
[0103] In at least one embodiment of the present invention, the performing data flow in the target server based on the target data flow type to obtain the target data includes:
[0104] Obtaining data to be processed from the target server;
[0105] When the target data flow type is an offline type, the data to be processed is processed in a data warehouse to obtain label information of the data to be processed, the label information of the data to be processed is pushed to a relational database, and the label information of the data to be processed is pushed from the relational database to a cache, the label information of the data to be processed is read from the cache, and a data structure conversion tool is used to convert the label information of the data to be processed into tabular data to obtain the target data; or
[0106] When the target data flow type is a real-time type, the data to be processed is stored in a preset middleware, and the data to be processed is read from the preset middleware into a message queue, the data to be processed is read from the message queue, and the data to be processed is pushed to the cache, the data to be processed is read from the cache, and the data structure conversion tool is used to convert the data to be processed into the table data to obtain the target data; or
[0107] When the target data flow type is an offline and real-time coexistence type, the data to be processed is processed in the data warehouse to obtain label information of the data to be processed, the label information of the data to be processed is processed using a stream processing framework, and the processed label information of the data to be processed is pushed to a search server, based on the search server, the processed label information of the data to be processed is sent to a preset interface, and the data returned by the preset interface is received as the target data.
[0108] In this embodiment, the data warehouse may be hive, which is a data warehouse infrastructure on Hadoop.
[0109] In this embodiment, the relational database may be a MySQL database.
[0110] In this embodiment, the cache may be a redis cache. By storing data in the cache, computing efficiency can be improved.
[0111] In this embodiment, the data structure conversion tool may be a dataframe.
[0112] In this embodiment, the preset middleware may be Binlog or canal.
[0113] In this embodiment, the message queue may be kafka.
[0114] In this embodiment, the stream processing framework may be flink.
[0115] In this embodiment, the search server may be an ES (ElasticSearch) search engine.
[0116] In this embodiment, the preset interface may be a data request interface of a third-party platform.
[0117] After different types of data flow, the final data can be calculated and used in the application system.
[0118] Through the above implementation methods, the flow of data is standardized to achieve data flow of different types and to process and handle the data in a targeted manner.
[0119] In at least one embodiment of the present invention, when data is transferred in the target server based on the target data transfer type, the method further includes:
[0120] Obtaining an HTTP request to the target server;
[0121] Determine whether to respond to the HTTP request based on the response middleware in the target server;
[0122] When it is determined to respond to the HTTP request, the router configuration component of the target server parses the HTTP request to obtain a parsing result;
[0123] Send the parsing result to the view response middleware for processing to obtain a view processing result;
[0124] Use the global exception handling plug-in to monitor the view processing result;
[0125] When the view processing result is abnormal, the view processing result is sent to the exception processing middleware for processing to obtain the exception processing result, and the exception processing result is returned through the response middleware; or
[0126] When there is no exception in the view processing result, the view processing result is returned through the response middleware.
[0127] Through the above implementation, the calling of the interface can be implemented in the target server.
[0128] In at least one embodiment of the present invention, when data is transferred in the target server based on the target data transfer type, the method further includes:
[0129] Obtain each process during data flow, and obtain the process management tool deployed in the FlaskRestful framework;
[0130] Using the process management tool to monitor each process;
[0131] When a process is detected to exit abnormally, the detected process is identified as the target process;
[0132] Restarting the target process;
[0133] When the target process fails to be restarted, a pre-configured times threshold is obtained, and when the number of restarts of the target process reaches the times threshold, the target process is terminated.
[0134] In this embodiment, the process management tool is used to manage and restart the background process after an abnormality occurs.
[0135] For example, the process management tool may be a Supervisor tool, which is a process management tool written in Python.
[0136] Through the above implementation, the process can be restarted after an abnormality occurs, so as to ensure the availability of the data interface and improve the stability of the entire framework.
[0137] S15, feeding back the target data to the client.
[0138] Through the above implementation, various types of services can be combined based on the FlaskRestful framework to ensure the reliability of services and the standardization of various types of interfaces, which also saves development costs and ensures development quality and efficiency to provide better data support.
[0139] It should be noted that in order to further ensure the security of the data and prevent the data from being maliciously tampered with, the target data can be stored on the blockchain node.
[0140] It can be seen from the above technical scheme that the present invention can respond to the data request initiated by the client to the FlaskRestful framework, determine the target interface type and the target data flow type according to the data request, and the FlaskRestful framework can provide lightweight access, obtain the pre-configured interface development logic mapping table corresponding to the interface type, and use the target interface type to query in the interface development logic mapping table to obtain the target interface development logic corresponding to the target interface type, and use the Python language to build the target interface based on the target interface development logic. The Python language has good support for data mining algorithms and realizes the standardized construction of interfaces. The Gunicorn server deployed in the FlaskRestful framework is obtained. The target server cluster and Nginx reverse proxy are used, and the Nginx reverse proxy is used to perform load balancing on the Gunicorn server cluster to obtain the target server to avoid putting pressure on the server, and the target interface is called to connect to the target server, and data is transferred in the target server based on the target data flow type to obtain the target data, and the data flow is standardized to achieve data flow under different types, and the data is processed and processed in a targeted manner, and the target data is fed back to the client, so that various types of services can be combined based on the FlaskRestful framework to ensure the reliability of the service and the standardization of various types of interfaces, which also saves development costs and ensures development quality and efficiency to provide better data support.
[0141] The embodiment of the present invention also provides a data interface service device based on the FlaskRestful framework, which is used to execute any embodiment of the aforementioned data interface service method based on the FlaskRestful framework. Figure 2 , Figure 2 It is a schematic block diagram of a data interface service device based on the FlaskRestful framework provided in an embodiment of the present invention.
[0142] like Figure 2 As shown, the data interface service device 100 based on the FlaskRestful framework includes: a determination unit 101, a query unit 102, a construction unit 103, an execution unit 104, a circulation unit 105, and a feedback unit 106.
[0143] The determination unit 101 responds to a data request initiated by a client to the FlaskRestful framework, and determines a target interface type and a target data flow type according to the data request.
[0144] In at least one embodiment of the present invention, the FlaskRestful framework is a Python webservice framework that can provide lightweight Http (Hyper Text Transfer Protocol) access.
[0145] In at least one embodiment of the present invention, the client may include any type of user terminal.
[0146] For example, when a user wants to obtain user data through the FlaskRestful framework to perform user preference analysis, the data request can be initiated to the FlaskRestful framework through the user's client.
[0147] In at least one embodiment of the present invention, by parsing the data request, relevant information carried by the data request, such as: the target interface type, the target data flow type, etc., can be acquired.
[0148] The target interface type may include, but is not limited to, any one of the following: an algorithm-based interface development type, a rule-based interface development type, and a process-based interface development type.
[0149] The target data flow type may include, but is not limited to, any one of the following: an offline type, a real-time type, and an offline and real-time coexistence type.
[0150] The query unit 102 obtains a pre-configured interface development logic mapping table corresponding to the interface type, and uses the target interface type to query the interface development logic mapping table to obtain a target interface development logic corresponding to the target interface type.
[0151] In at least one embodiment of the present invention, the interface development logic mapping table is used to store the correspondence between the interface development logic and the interface type.
[0152] In at least one embodiment of the present invention, the query unit 102 uses the target interface type to query the interface development logic mapping table, and obtains the target interface development logic corresponding to the target interface type, including:
[0153] Matching the target interface type with the interface type stored in the interface development logic mapping table;
[0154] Obtaining the interface type that matches the target interface type and using it as the target type;
[0155] The interface development logic corresponding to the target type and stored in the interface development logic mapping table is determined as the target interface development logic.
[0156] The construction unit 103 uses Python language to construct the target interface based on the target interface development logic.
[0157] In at least one embodiment of the present invention, the Python language has good support for data mining algorithms. Therefore, the Python language can better enable algorithms, and is relatively friendly to data developers because it is less error-prone.
[0158] In at least one embodiment of the present invention, the constructing unit 103 constructs the target interface based on the target interface development logic, including:
[0159] When there is a new data source, an algo file, an API (Application Programming Interface) file, a database (datebase, db) file and public variables are added based on the algorithm logic of the new data source, and the algo file, the API file, the database file and the public variables are encapsulated as a first interface to be tested, and the first interface to be tested is deployed in the FlaskRestful framework. After the deployment is completed, the first interface to be tested is tested, and when the first interface to be tested passes the test, the first interface to be tested is determined as the target interface; or
[0160] When there is no new data source, add an algo file and an API file, and encapsulate the algo file and the API file to obtain a second interface to be tested, deploy the second interface to be tested in the FlaskRestful framework, and after the deployment is completed, test the second interface to be tested, query the interface log generated during the test, and when the interface log shows that the second interface to be tested passes the test, publish the second interface to be tested to the production environment, or when the interface log shows that the second interface to be tested fails the test, repair the second interface to be tested.
[0161] It should be noted that after the second interface to be tested is repaired, the repaired second interface to be tested is redeployed to the FlaskRestful framework, and retested after deployment, through continuous repair, deployment, and testing until the second interface to be tested passes the test.
[0162] Through the above implementation, different interface construction processes can be executed according to whether there is a new data source.
[0163] In at least one embodiment of the present invention, the constructing unit 103 constructs the target interface based on the target interface development logic, further comprising:
[0164] For the sub-interface of the search server ES (Elastic Search) type in the target interface, a new engine and ES sub-interface are created on the specified search platform;
[0165] Create a new Flink task on the real-time computing platform based on the engine and the ES sub-interface;
[0166] Test the Flink task;
[0167] When the Flink task passes the test, the ES sub-interface is published to the specified platform; or
[0168] When the Flink task fails the test, the ES sub-interface is repaired.
[0169] The designated search platform may be any search platform that supports ES.
[0170] The designated platform may include a BDP platform.
[0171] It should be noted that after the ES sub-interface is repaired, a new Flink task is created based on the repaired ES sub-interface, and the repair, creation and testing are continued until the ES sub-interface passes the test.
[0172] After the interface is built, interface development for different scenarios only requires modifying a few parameters based on specific business content.
[0173] For example, the flow of data has been standardized. If a new interface needs to use new data, it only needs to modify the configuration information without redeveloping the entire data access process.
[0174] Through the above implementation, interfaces with the same service type can be uniformly encapsulated to avoid repeated construction of interfaces, improve service efficiency, and enhance code reuse.
[0175] The execution unit 104 obtains the Gunicorn server cluster and the Nginx reverse proxy deployed in the FlaskRestful framework, and uses the Nginx reverse proxy to perform load balancing on the Gunicorn server cluster to obtain a target server.
[0176] In at least one embodiment of the present invention, the Gunicorn server is a widely used high-performance Python WSGI UNIX HTTP Server.
[0177] In at least one embodiment of the present invention, the Nginx reverse proxy is a high-performance HTTP and reverse proxy web server for request load balancing.
[0178] In at least one embodiment of the present invention, the execution unit 104 uses the Nginx reverse proxy to perform load balancing on the Gunicorn server cluster, and the target server obtained includes:
[0179] Using the Nginx reverse proxy to poll each server in the Gunicorn server cluster, and determining the currently polled server as the target server; and / or
[0180] The request address of the client is obtained, and the target server is obtained from the Gunicorn server cluster according to the request address.
[0181] Through the above implementation, different modes of load balancing can be implemented based on Nginx middleware in the FlaskRestful framework to avoid putting pressure on the server.
[0182] The transfer unit 105 calls the target interface to connect to the target server, and performs data transfer in the target server based on the target data transfer type to obtain target data.
[0183] In at least one embodiment of the present invention, the transfer unit 105 performs data transfer in the target server based on the target data transfer type, and obtains the target data including:
[0184] Obtaining data to be processed from the target server;
[0185] When the target data flow type is an offline type, the data to be processed is processed in a data warehouse to obtain label information of the data to be processed, the label information of the data to be processed is pushed to a relational database, and the label information of the data to be processed is pushed from the relational database to a cache, the label information of the data to be processed is read from the cache, and a data structure conversion tool is used to convert the label information of the data to be processed into tabular data to obtain the target data; or
[0186] When the target data flow type is a real-time type, the data to be processed is stored in a preset middleware, and the data to be processed is read from the preset middleware into a message queue, the data to be processed is read from the message queue, and the data to be processed is pushed to the cache, the data to be processed is read from the cache, and the data structure conversion tool is used to convert the data to be processed into the table data to obtain the target data; or
[0187] When the target data flow type is an offline and real-time coexistence type, the data to be processed is processed in the data warehouse to obtain label information of the data to be processed, the label information of the data to be processed is processed using a stream processing framework, and the processed label information of the data to be processed is pushed to a search server, based on the search server, the processed label information of the data to be processed is sent to a preset interface, and the data returned by the preset interface is received as the target data.
[0188] In this embodiment, the data warehouse may be hive, which is a data warehouse infrastructure on Hadoop.
[0189] In this embodiment, the relational database may be a MySQL database.
[0190] In this embodiment, the cache may be a redis cache. By storing data in the cache, computing efficiency can be improved.
[0191] In this embodiment, the data structure conversion tool may be a dataframe.
[0192] In this embodiment, the preset middleware may be Binlog or canal.
[0193] In this embodiment, the message queue may be kafka.
[0194] In this embodiment, the stream processing framework may be flink.
[0195] In this embodiment, the search server may be an ES (ElasticSearch) search engine.
[0196] In this embodiment, the preset interface may be a data request interface of a third-party platform.
[0197] After different types of data flow, the final data can be calculated and used in the application system.
[0198] Through the above implementation methods, the flow of data is standardized to achieve data flow of different types and to process and handle the data in a targeted manner.
[0199] In at least one embodiment of the present invention, when data is transferred in the target server based on the target data transfer type, an HTTP request to the target server is obtained;
[0200] Determine whether to respond to the HTTP request based on the response middleware in the target server;
[0201] When it is determined to respond to the HTTP request, the router configuration component of the target server parses the HTTP request to obtain a parsing result;
[0202] Send the parsing result to the view response middleware for processing to obtain a view processing result;
[0203] Use the global exception handling plug-in to monitor the view processing result;
[0204] When the view processing result is abnormal, the view processing result is sent to the exception processing middleware for processing to obtain the exception processing result, and the exception processing result is returned through the response middleware; or
[0205] When there is no exception in the view processing result, the view processing result is returned through the response middleware.
[0206] Through the above implementation, the calling of the interface can be implemented in the target server.
[0207] In at least one embodiment of the present invention, when data is transferred in the target server based on the target data transfer type, each process during data transfer is obtained, and a process management tool deployed in the FlaskRestful framework is obtained;
[0208] Using the process management tool to monitor each process;
[0209] When a process is detected to have exited abnormally, the detected process is identified as the target process;
[0210] Restarting the target process;
[0211] When the target process fails to be restarted, a pre-configured times threshold is obtained, and when the number of restarts of the target process reaches the times threshold, the target process is terminated.
[0212] In this embodiment, the process management tool is used to manage and restart the background process after an abnormality occurs.
[0213] For example, the process management tool may be a Supervisor tool, which is a process management tool written in Python.
[0214] Through the above implementation, the process can be restarted after an abnormality occurs, so as to ensure the availability of the data interface and improve the stability of the entire framework.
[0215] The feedback unit 106 feeds back the target data to the client.
[0216] Through the above implementation, various types of services can be combined based on the FlaskRestful framework to ensure the reliability of services and the standardization of various types of interfaces, which also saves development costs and ensures development quality and efficiency to provide better data support.
[0217] It should be noted that in order to further ensure the security of the data and prevent the data from being maliciously tampered with, the target data can be stored on the blockchain node.
[0218] It can be seen from the above technical scheme that the present invention can respond to the data request initiated by the client to the FlaskRestful framework, determine the target interface type and the target data flow type according to the data request, and the FlaskRestful framework can provide lightweight access, obtain the pre-configured interface development logic mapping table corresponding to the interface type, and use the target interface type to query in the interface development logic mapping table to obtain the target interface development logic corresponding to the target interface type, and use the Python language to build the target interface based on the target interface development logic. The Python language has good support for data mining algorithms and realizes the standardized construction of interfaces. The Gunicorn server deployed in the FlaskRestful framework is obtained. The target server cluster and Nginx reverse proxy are used, and the Nginx reverse proxy is used to perform load balancing on the Gunicorn server cluster to obtain the target server to avoid putting pressure on the server, and the target interface is called to connect to the target server, and data is transferred in the target server based on the target data flow type to obtain the target data, and the data flow is standardized to achieve data flow under different types, and the data is processed and processed in a targeted manner, and the target data is fed back to the client, so that various types of services can be combined based on the FlaskRestful framework to ensure the reliability of the service and the standardization of various types of interfaces, which also saves development costs and ensures development quality and efficiency to provide better data support.
[0219] The data interface service device based on the FlaskRestful framework can be implemented in the form of a computer program. Figure 3 Runs on the computer device shown.
[0220] See also Figure 3 , Figure 3 5 is a schematic block diagram of a computer device provided in an embodiment of the present invention. The computer device 500 is a server, which can be an independent server or a server cluster composed of multiple servers. The server can be an independent server or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.
[0221] Among them, Artificial Intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0222] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0223] See also Figure 3 The computer device 500 includes a processor 502 , a memory and a network interface 505 connected via a system bus 501 , wherein the memory may include a storage medium 503 and an internal memory 504 .
[0224] The storage medium 503 can store an operating system 5031 and a computer program 5032. When the computer program 5032 is executed, the processor 502 can execute a data interface service method based on the FlaskRestful framework.
[0225] The processor 502 is used to provide computing and control capabilities to support the operation of the entire computer device 500 .
[0226] The internal memory 504 provides an environment for the operation of the computer program 5032 in the storage medium 503. When the computer program 5032 is executed by the processor 502, the processor 502 can execute a data interface service method based on the FlaskRestful framework.
[0227] The network interface 505 is used for network communication, such as providing data information transmission, etc. Those skilled in the art will understand that Figure 3 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present invention, and does not constitute a limitation on the computer device 500 to which the solution of the present invention is applied. The specific computer device 500 may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0228] The processor 502 is used to run the computer program 5032 stored in the memory to implement the data interface service method based on the FlaskRestful framework disclosed in the embodiment of the present invention.
[0229] Those skilled in the art will understand that Figure 3 The embodiments of the computer device shown in the figure do not constitute a limitation on the specific composition of the computer device. In other embodiments, the computer device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. For example, in some embodiments, the computer device may only include a memory and a processor. In such embodiments, the structure and function of the memory and the processor are the same as those of the embodiment of the present invention. Figure 3 The embodiments shown are consistent and will not be described again here.
[0230] It should be understood that in the embodiment of the present invention, the processor 502 may be a central processing unit (CPU), and the processor 502 may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0231] In another embodiment of the present invention, a computer-readable storage medium is provided. The computer-readable storage medium may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. The computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, the data interface service method based on the FlaskRestful framework disclosed in the embodiment of the present invention is implemented.
[0232] The blockchain referred to in this invention is a new application mode of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0233] It should be noted that the data involved in this case were all obtained legally.
[0234] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working process of the above-described equipment, devices and units can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. Those of ordinary skill in the art can appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented with electronic hardware, computer software or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to the function. Whether these functions are executed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present invention.
[0235] In the several embodiments provided by the present invention, it should be understood that the disclosed equipment, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. Units with the same function may also be combined into one unit. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interfaces, devices or units, or may be an electrical, mechanical or other form of connection.
[0236] 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 embodiments of the present invention.
[0237] The present invention can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronic devices, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present invention can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present invention can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0238] In addition, each functional unit in each embodiment of the present invention 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. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0239] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including 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 invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), disk or optical disk and other media that can store program codes.
[0240] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.
Claims
1. A data interface service method based on the FlaskRestful framework, characterized in that: include: In response to a data request initiated by a client to the FlaskRestful framework, a target interface type and a target data flow type are determined according to the data request; Obtain a pre-configured interface development logic mapping table corresponding to the interface type, and use the target interface type to query in the interface development logic mapping table to obtain the target interface development logic corresponding to the target interface type; Using Python language, construct the target interface based on the target interface development logic; Obtain the Gunicorn server cluster and Nginx reverse proxy deployed in the FlaskRestful framework, and use the Nginx reverse proxy to perform load balancing on the Gunicorn server cluster to obtain the target server; Calling the target interface to connect to the target server, and performing data flow in the target server based on the target data flow type to obtain target data; Feedback the target data to the client; Wherein, when there is a new data source, an algo file, an API file and a public variable are newly added based on the algorithm logic of the new data source, and the algo file, the API file, the database file and the public variables are encapsulated as a first interface to be tested, and the first interface to be tested is deployed in the FlaskRestful framework, and after the deployment is completed, the first interface to be tested is tested, and when the first interface to be tested passes the test, the first interface to be tested is determined as the target interface; or When no new data source is added, an algo file and an API file are added, and the algo file and the API file are encapsulated to obtain a second interface to be tested, and the second interface to be tested is deployed in the FlaskRestful framework. After the deployment is completed, the second interface to be tested is tested, and the interface log generated during the test is queried. When the interface log shows that the second interface to be tested passes the test, the second interface to be tested is released to the production environment, or when the interface log shows that the second interface to be tested fails the test, the second interface to be tested is repaired; Wherein, obtaining the data to be processed from the target server; When the target data flow type is an offline type, the data to be processed is processed in a data warehouse to obtain label information of the data to be processed, the label information of the data to be processed is pushed to a relational database, and the label information of the data to be processed is pushed from the relational database to a cache, the label information of the data to be processed is read from the cache, and a data structure conversion tool is used to convert the label information of the data to be processed into tabular data to obtain the target data; or When the target data flow type is a real-time type, the data to be processed is stored in a preset middleware, and the data to be processed is read from the preset middleware into a message queue, the data to be processed is read from the message queue, and the data to be processed is pushed to the cache, the data to be processed is read from the cache, and the data structure conversion tool is used to convert the data to be processed into the table data to obtain the target data; or When the target data flow type is an offline and real-time coexistence type, the data to be processed is processed in the data warehouse to obtain label information of the data to be processed, the label information of the data to be processed is processed using a stream processing framework, and the processed label information of the data to be processed is pushed to a search server, based on the search server, the processed label information of the data to be processed is sent to a preset interface, and the data returned by the preset interface is received as the target data.
2. According to the data interface service method based on the FlaskRestful framework of claim 1, it is characterized in that: The constructing the target interface based on the target interface development logic further comprises: For the sub-interface of the search server ES type in the target interface, a new engine and ES sub-interface are created on the specified search platform; Create a new Flink task on the real-time computing platform based on the engine and the ES sub-interface; Test the Flink task; When the Flink task passes the test, the ES sub-interface is published to the specified platform; or When the Flink task fails the test, the ES sub-interface is repaired.
3. The data interface service method based on the FlaskRestful framework according to claim 1, characterized in that: The use of the Nginx reverse proxy to perform load balancing on the Gunicorn server cluster to obtain the target server includes: Using the Nginx reverse proxy to poll each server in the Gunicorn server cluster, and determining the currently polled server as the target server; and / or The request address of the client is obtained, and the target server is obtained from the Gunicorn server cluster according to the request address.
4. The data interface service method based on the FlaskRestful framework according to claim 1, characterized in that: When data is transferred in the target server based on the target data transfer type, the method further includes: Obtaining an HTTP request to the target server; Determine whether to respond to the HTTP request based on the response middleware in the target server; When it is determined to respond to the HTTP request, the router configuration component of the target server parses the HTTP request to obtain a parsing result; Send the parsing result to the view response middleware for processing to obtain a view processing result; Use the global exception handling plug-in to monitor the view processing result; When the view processing result is abnormal, the view processing result is sent to the exception processing middleware for processing to obtain the exception processing result, and the exception processing result is returned through the response middleware; or When there is no exception in the view processing result, the view processing result is returned through the response middleware.
5. The data interface service method based on the FlaskRestful framework according to claim 1, characterized in that: When data is transferred in the target server based on the target data transfer type, the method further includes: Obtain each process during data flow, and obtain the process management tool deployed in the FlaskRestful framework; Using the process management tool to monitor each process; When a process is detected to have exited abnormally, the detected process is identified as the target process; Restarting the target process; When the target process fails to be restarted, a pre-configured times threshold is obtained, and when the number of restarts of the target process reaches the times threshold, the target process is terminated.
6. A data interface service device based on the FlaskRestful framework, characterized in that: include: A determination unit, configured to respond to a data request initiated by a client to a FlaskRestful framework, and determine a target interface type and a target data flow type according to the data request; A query unit, used to obtain a pre-configured interface development logic mapping table corresponding to the interface type, and query the interface development logic mapping table using the target interface type to obtain a target interface development logic corresponding to the target interface type; A construction unit, used to construct a target interface based on the target interface development logic using Python language; An execution unit is used to obtain a Gunicorn server cluster and an Nginx reverse proxy deployed in the FlaskRestful framework, and use the Nginx reverse proxy to perform load balancing on the Gunicorn server cluster to obtain a target server; A transfer unit, configured to call the target interface to connect to the target server, and perform data transfer in the target server based on the target data transfer type to obtain target data; A feedback unit, used for feeding back the target data to the client; Among them, when there is a new data source, an algo file, an API file and a public variable are added based on the algorithm logic of the new data source, and the algo file, the API file, the database file and the public variables are encapsulated as a first interface to be tested, and the first interface to be tested is deployed in the FlaskRestful framework. After the deployment is completed, the first interface to be tested is tested, and when the first interface to be tested passes the test, the first interface to be tested is determined as the target interface; or when there is no new data source, an algo file and an API file are added, and the algo file and the API file are encapsulated to obtain a second interface to be tested, and the second interface to be tested is deployed in the FlaskRestful framework. After the deployment is completed, the second interface to be tested is tested, and the interface log generated during the test process is queried. When the interface log shows that the second interface to be tested passes the test, the second interface to be tested is released to the production environment, or when the interface log shows that the second interface to be tested fails the test, the second interface to be tested is repaired; wherein, the data to be processed is obtained from the target server; when the target data flow type is an offline type, the data to be processed is processed in a data warehouse to obtain label information of the data to be processed, the label information of the data to be processed is pushed to a relational database, and the label information of the data to be processed is pushed from the relational database to a cache, the label information of the data to be processed is read from the cache, and the label information of the data to be processed is converted into table data using a data structure conversion tool to obtain the target data; or when the target data flow type is a real-time type, the data to be processed is stored in a preset middleware, and the data to be processed is read from the preset middleware into a message queue, and the message queue is read from the message queue. The data to be processed is read from the queue and pushed to the cache, the data to be processed is read from the cache, and the data to be processed is converted into the tabular data using the data structure conversion tool to obtain the target data; or when the target data flow type is an offline and real-time coexistence type, the data to be processed is processed in the data warehouse to obtain label information of the data to be processed, the label information of the data to be processed is processed using a stream processing framework, and the processed label information of the data to be processed is pushed to the search server, the processed label information of the data to be processed is sent to a preset interface based on the search server, and the data returned by the preset interface is received as the target data.
7. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the data interface service method based on the FlaskRestful framework is implemented as described in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, which, when executed by a processor, enables the processor to execute the data interface service method based on the FlaskRestful framework as described in any one of claims 1 to 5.
