CN-121996310-A - Method, system, equipment and medium for realizing data micro-service based on plug-in
Abstract
The embodiment of the application provides a method, a system, equipment and a medium for realizing data micro-service based on a plug-in, wherein the method comprises the steps that a route management module loads HTTP resolvers and encapsulators arranged on different objects, and creates a route management object comprising plug-in route registration and management functions; the plug-in management module loads a C++ dynamic library from a corresponding catalogue, searches a plug-in export function and calls the plug-in export function to obtain an instantiated plug-in object, registers a plug-in route in the route management module, responds to a monitored request, sends the request to the route management module, determines a target plug-in route corresponding to the request according to the request and the plug-in route mapping relation, accesses a target plug-in through the target plug-in route and operates a data service to obtain target data, encapsulates the target data into a response corresponding to the request, and sends the response to a corresponding client. The method aims to reduce the coupling degree between service components and improve the maintainability and expandability of programs.
Inventors
- Dai su
- HOU HONGJUN
- SHANG MINQIANG
- RAN XIANHUA
- DU JIGUO
- JIN JIAN
Assignees
- 中国石油天然气集团有限公司
- 中国石油集团东方地球物理勘探有限责任公司
- 中油油气勘探软件国家工程研究中心有限公司
Dates
- Publication Date
- 20260508
- Application Date
- 20241104
Claims (11)
- 1. The method for realizing the data micro-service based on the plug-in is characterized by being applied to a server, and comprises the following steps: The route management module loads HTTP resolvers and encapsulators arranged in different objects, and creates a route management object comprising a plug-in route registration function and a management function, wherein the route management object is used for registering and managing each plug-in route; The plug-in management module downloads all C++ dynamic libraries from plugins catalogues, searches plug-in export functions in all C++ dynamic libraries and calls the plug-in export functions to obtain instantiated plug-in objects, and the plugins catalogues are subdirectories of catalogues where application programs of the initialization management module are located; Registering each plug-in route in the route management module through the plug-in management module; responding to the monitored client request, and sending the client request to a route management module; According to the client request and the plug-in route mapping relation, a route management module determines a target plug-in route corresponding to the client request, wherein the plug-in route mapping relation is a mapping relation between different data service URLs and corresponding plug-in routes; And accessing the target plugin through the target plugin route, running the data service of the target plugin, acquiring corresponding target data, packaging the target data into a response corresponding to the client request, and sending the response to the client initiating the client request.
- 2. The method for implementing plug-in based data micro services according to claim 1, further comprising: Creating a C++ dynamic library item; taking a plug-in interface class provided by a plug-in management module as a base class, and writing a plug-in class with a data service function in the C++ dynamic library item; Implementing a route registration function in the plugin class, wherein the route registration function is used for registering plugin routes in a route management module; Writing a plug-in export function in the C++ dynamic library item, generating an instantiated plug-in object according to the plug-in class when the plug-in export function is called, and returning the plug-in object to a plug-in management module; copying the C++ dynamic library item to the plugins catalog of the application program, and rerun the application program.
- 3. The method for implementing plug-in based data micro services according to claim 2, wherein the method further comprises: Initializing command line parameters of an application program, wherein the command line parameters are used for designating addresses and ports for monitoring WEB service and designating loading paths of extension plug-ins; Initializing interrupt signal binding of a Linux system; initializing a static file service.
- 4. The method for implementing a plug-in based data micro service according to claim 1, wherein registering each plug-in route in the route management module by the plug-in management module comprises: Calling a routing registration function of the plugin through the plugin management module; And transmitting the target mapping relation to a route management module through the called route registration function of the plugin, and realizing registration of the plugin route, wherein the target mapping relation is the mapping relation between the data service URL of the plugin and the corresponding plugin route.
- 5. The method for realizing the plug-in based data micro service according to claim 4, wherein before the routing registration function of the plug-in is called by the plug-in management module, the method further comprises: Calling a routing registration pre-function of a plug-in through a plug-in management module, wherein the routing registration pre-function comprises plug-in operations required to be performed before the routing registration function is executed; after invoking the routing registration function of the plugin by the plugin management module, the method further includes: calling a route registration post-function of the plugin through a plugin management module, wherein the route registration post-function comprises plugin operations required to be performed after the route registration function is executed; After the routing registration post function call of the plugin management module to all plugins is completed, the method further comprises the following steps: and calling a route initialization completion function of each plug-in through a plug-in management module, wherein the route initialization completion function comprises plug-in operations required to be carried out after route registration post-function execution of all the plug-ins.
- 6. The method for implementing a plug-in based data micro service according to claim 1, wherein the determining, by the route management module, the target plug-in route corresponding to the client request according to the mapping relationship between the client request and the plug-in route comprises: the route management module analyzes the client request to obtain a target URL; determining whether the target URL is registered in a route management module; In the case that the target URL is not registered in the route management module, sending a response that the service does not exist to the client; And under the condition that the target URL is registered in the route management module, determining a target plug-in route corresponding to the client request in a plug-in route mapping relation.
- 7. The plug-in based data micro service implementation method according to claim 1, wherein running a data service of a target plug-in and obtaining corresponding target data, packaging the target data into a response corresponding to a client request, and sending the response to a client that initiates the client request, includes: Calling a data service function of a target plug-in a sub-thread to acquire target data, and transmitting the target data to a route management module in a callback mode; The route management module encapsulates the target data into a response corresponding to the client request, and sends the response to the client initiating the client request.
- 8. The method for implementing plug-in based data micro services according to claim 1, further comprising: when the application program exits, the plug-in management module calls the destruction function of each plug-in.
- 9. A plug-in based data micro-service implementation system, the system comprising: The routing management module is used for loading HTTP resolvers and encapsulators arranged in different objects and creating a routing management object comprising a plug-in routing registration function and a management function, wherein the routing management object is used for registering and managing each plug-in routing; The plug-in management module is used for downloading all C++ dynamic libraries from plugins catalogues, searching plug-in export functions in all C++ dynamic libraries and calling to obtain an instantiated plug-in object, wherein the plugins catalogues are subdirectories of the catalogues of the application programs of the initialization management module; The application program module is used for responding to the monitored client request and sending the client request to the route management module; The route management module is further used for determining a target plug-in route corresponding to the client request according to the client request and the plug-in route mapping relation, wherein the plug-in route mapping relation is a mapping relation between different data service URLs and corresponding plug-in routes, accessing the target plug-in through the target plug-in route, operating the data service of the target plug-in and obtaining corresponding target data, packaging the target data into a response corresponding to the client request, and sending the response to the client initiating the client request.
- 10. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the computer program implementing a plug-in based data micro-service implementation method according to claims 1 to 8 when executed by the processor.
- 11. A computer readable storage medium having a computer program stored thereon, wherein the computer program when executed by a processor implements a plug-in based data micro service implementation method according to any of claims 1 to 8.
Description
Method, system, equipment and medium for realizing data micro-service based on plug-in Technical Field The application relates to the field of data service, in particular to a method, a system, equipment and a medium for realizing data micro-service based on a plug-in. Background The data service encapsulates the processes of accessing the data storage system and extracting and integrating the data into a reusable service interface, provides a standardized data access mode for a user, and realizes multiplexing and sharing of the data. However, the old data service program usually adopts a single architecture, so that the coupling degree of each service component is too high, and the difficulty of maintaining and expanding the service is increased. Disclosure of Invention In view of this, the embodiments of the present application provide a method, a system, a device, and a medium for implementing a data micro-service based on a plug-in, which aim to reduce the coupling degree between data service components and improve maintainability and expandability of data services. The first aspect of the embodiment of the application provides a method for realizing a data micro-service based on a plug-in, which is applied to a server, and comprises the following steps: The route management module loads HTTP resolvers and encapsulators arranged in different objects, and creates a route management object comprising a plug-in route registration function and a management function, wherein the route management object is used for registering and managing each plug-in route; The plug-in management module downloads all C++ dynamic libraries from plugins catalogues, searches plug-in export functions in all C++ dynamic libraries and calls the plug-in export functions to obtain instantiated plug-in objects, and the plugins catalogues are subdirectories of catalogues where application programs of the initialization management module are located; Registering each plug-in route in the route management module through the plug-in management module; responding to the monitored client request, and sending the client request to a route management module; According to the client request and the plug-in route mapping relation, a route management module determines a target plug-in route corresponding to the client request, wherein the plug-in route mapping relation is a mapping relation between different data service URLs and corresponding plug-in routes; And accessing the target plugin through the target plugin route, running the data service of the target plugin, acquiring corresponding target data, packaging the target data into a response corresponding to the client request, and sending the response to the client initiating the client request. Optionally, the method further comprises: Creating a C++ dynamic library item; taking a plug-in interface class provided by a plug-in management module as a base class, and writing a plug-in class with a data service function in the C++ dynamic library item; Implementing a route registration function in the plugin class, wherein the route registration function is used for registering plugin routes in a route management module; Writing a plug-in export function in the C++ dynamic library item, generating an instantiated plug-in object according to the plug-in class when the plug-in export function is called, and returning the plug-in object to a plug-in management module; copying the C++ dynamic library item to the plugins catalog of the application program, and rerun the application program. Optionally, the method further comprises: Initializing command line parameters of an application program, wherein the command line parameters are used for designating addresses and ports for monitoring WEB service and designating loading paths of extension plug-ins; Initializing interrupt signal binding of a Linux system; initializing a static file service. Optionally, registering, by the plug-in management module, each plug-in route in the route management module includes: Calling a routing registration function of the plugin through the plugin management module; And transmitting the target mapping relation to a route management module through the called route registration function of the plugin, and realizing registration of the plugin route, wherein the target mapping relation is the mapping relation between the data service URL of the plugin and the corresponding plugin route. Optionally, before the routing registration function of the plugin is invoked by the plugin management module, the method further includes: Calling a routing registration pre-function of a plug-in through a plug-in management module, wherein the routing registration pre-function comprises plug-in operations required to be performed before the routing registration function is executed; after invoking the routing registration function of the plugin by the plugin management module, the method further includes: calling a route registrat