A data source routing method and device
By receiving access requests in the database application system and obtaining tenant and business direction information, using matrix data source routing service to realize automatic routing switching between multi-tenant and multi-service data sources, it solves the multi-tenant and multi-service data source routing in the existing technology The switching problem enhances the reusability of the solution and decouples it from the database application system.
Patent Information
- Application Number
- CN201910695657.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-07-30
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2039-07-30
AI Technical Summary
The prior art cannot solve the problem of automatic routing switching between multi-tenant and multi-service data sources at the same time, and is closely coupled with the database application system, so the solution is poor reusable.
By receiving access requests from the database application system, obtaining the tenant and business direction information of the current context, using the matrix data source routing service to switch to the corresponding specific data source, realizing automatic routing switching between multi-tenant and multi-service data sources, and through configuration information Query and listening, dynamic initialization of matrix data source and dynamic routing services of matrix data source are decomposed into independent domain services, supporting multiple application access methods, and realizing code decoupling from database application systems.
Automatic routing switching between multi-tenant and multi-service data sources is realized, which enhances the reusability of the solution and decouples the code from the database application system, improving the flexibility and adaptability of the system.
Smart Images

Figure CN112306984B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a data source routing method and device. Background Art
[0002] In database application systems, data sources, as standard interfaces for database connection management, bear extremely important responsibilities. Complex database application systems involve both the separation and routing of multi-business data sources and the isolation and routing of data sources for multi-tenants. Therefore, there is a problem of automatically switching the system data source to the data source of the corresponding business of the corresponding tenant according to the context tenant and the business direction of the current access.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0004] It cannot solve the problem of automatic routing switching of multi-tenants and multi-business data sources at the same time, and is tightly coupled with the database application system, so the solution has poor reusability. Summary of the invention
[0005] In view of this, an embodiment of the present invention provides a data source routing method and device, which can simultaneously solve the problem of automatic routing switching of multi-tenant and multi-business data sources, and decouple from the code of the database application system to enhance the reusability of the solution.
[0006] To achieve the above objective, according to one aspect of an embodiment of the present invention, a data source routing method is provided.
[0007] A data source routing method comprises: receiving an access request from a database application system to a matrix data source, wherein the matrix data source comprises an overall dynamic data source, a business dynamic data source, and a specific data source, wherein one overall data source corresponds to multiple business dynamic data sources, and each business dynamic data source corresponds to multiple specific data sources; when the database application system accesses the overall dynamic data source, obtaining tenant information of the current context of the database application system and information of the business direction currently accessed through a matrix data source routing service, and switching the access request to a specific data source corresponding to the tenant of the current context and the business direction currently accessed under the overall dynamic data source; when the database application system accesses a target business dynamic data source among the multiple business dynamic data sources, obtaining tenant information of the current context of the database application system through a business dynamic data source routing service, and switching the access request to a specific data source corresponding to the tenant of the current context under the target business dynamic data source.
[0008] Optionally, before the step of receiving the access request of the database application system to the matrix data source, it includes: initializing the matrix data source according to the data source configuration information, including: initializing the overall dynamic data source, multiple business dynamic data sources corresponding to the overall dynamic data source, and multiple specific data sources corresponding to each business dynamic data source, the overall dynamic data source, the business dynamic data source, and the specific data source are named according to the naming convention of the matrix data source; respectively creating an overall dynamic data source instance, each business dynamic data source instance, and each specific data source instance, and initializing a database connection pool instance for each specific data source, and the names of the overall dynamic data source, each business dynamic data source, and each specific data source correspond to their respective instances.
[0009] Optionally, the initialized matrix data source is dynamically updated as the data source configuration information changes, and the content of the dynamic update includes: updating the corresponding business dynamic data source instance according to the change of the data source configuration information, updating the corresponding specific data source instance and its database connection pool information.
[0010] Optionally, it also includes: obtaining the data source configuration information and monitoring changes in the data source configuration information through configuration information query and monitoring services, wherein the data source configuration information is obtained and monitored in one of the following three ways: Method 1: obtaining the data source configuration information from a configuration file under a file path name specified by the database application system, and periodically scanning the configuration file to monitor changes in the data source configuration information; Method 2: obtaining the data source configuration information from a remote configuration center according to a configuration information query interface configured by the database application system, and monitoring changes in the data source configuration information pushed by the remote configuration center to a message queue or a distributed service; Method 3: using a first interface method and a second interface method customized by the database application system to respectively obtain and monitor the data source configuration information, the first interface method being an interface method for querying data source configuration information, and the second interface method being an interface method for monitoring changes in data source configuration information.
[0011] Optionally, the step of switching the access request to the specific data source corresponding to the tenant of the current context and the business direction of the current access under the overall dynamic data source includes: calculating the first target specific data source name corresponding to the tenant of the current context and the business direction of the current access under the overall dynamic data source according to the naming specification of the matrix data source based on the tenant information of the current context and the business direction of the current access obtained; switching the access request to the specific data source corresponding to the first target specific data source name according to the correspondence between the specific data source name and the specific data source instance; the step of switching the access request to the specific data source corresponding to the tenant of the current context under the target business dynamic data source includes: calculating the second target specific data source name corresponding to the tenant of the current context under the target business dynamic data source according to the naming specification of the matrix data source based on the tenant information of the current context obtained; and switching the access request to the specific data source corresponding to the second target specific data source name according to the correspondence between the specific data source name and the specific data source instance.
[0012] Optionally, each business dynamic data source corresponds to a business direction, and each specific data source corresponds to a tenant and a business direction; the naming convention of the matrix data source is: the first character string, the second character string, and the third character string respectively represent the overall dynamic data source, the business dynamic data source, and the specific data source, the name of the overall dynamic data source is the first character string, the name of each of the business dynamic data source is a combination of the corresponding business direction keyword and the second character string, and the name of each of the specific data source is a combination of the corresponding tenant identifier, the business direction keyword, and the third character string.
[0013] Optionally, the target business dynamic data source is a business dynamic data source located by the database application system through the business direction specified in its local configuration file; the currently accessed business direction is obtained according to the business direction declared by the database application system or the business direction value passed by the database application system, wherein the database application system declares the business direction through an annotation identifier or passes the business direction value through a first thread-level static method.
[0014] Optionally, the tenant information of the current context is acquired by reading a context tenant identification value set by the database application system in a system property, or reading a context tenant identification value passed by the database application system by calling a second thread-level static method.
[0015] According to another aspect of an embodiment of the present invention, a data source routing device is provided.
[0016] A data source routing device comprises: an access request receiving module, used for receiving an access request of a database application system to a matrix data source, wherein the matrix data source comprises an overall dynamic data source, a business dynamic data source, and a specific data source, wherein one overall data source corresponds to multiple business dynamic data sources, and each business dynamic data source corresponds to multiple specific data sources; a data source routing module, used for, when the database application system accesses the overall dynamic data source, obtaining tenant information of the current context of the database application system and information of the business direction of the current access through a matrix data source routing service, and switching the access request to a specific data source corresponding to the tenant of the current context and the business direction of the current access under the overall dynamic data source; and, when the database application system accesses a target business dynamic data source among the multiple business dynamic data sources, obtaining tenant information of the current context of the database application system through a business dynamic data source routing service, and switching the access request to a specific data source corresponding to the tenant of the current context under the target business dynamic data source.
[0017] Optionally, it also includes a data source initialization module, which is used to: initialize the matrix data source according to the data source configuration information, including: initializing the overall dynamic data source, multiple business dynamic data sources corresponding to the overall dynamic data source, and multiple specific data sources corresponding to each business dynamic data source, the overall dynamic data source, the business dynamic data source, and the specific data sources are named according to the naming convention of the matrix data source; respectively create an overall dynamic data source instance, each business dynamic data source instance, and each specific data source instance, and initialize a database connection pool instance for each specific data source, and the names of the overall dynamic data source, each business dynamic data source, and each specific data source correspond to their respective instances.
[0018] Optionally, it also includes a data source update module, which is used to dynamically update the initialized matrix data source as the data source configuration information changes. The content of the dynamic update includes: updating the corresponding business dynamic data source instance according to the change of the data source configuration information, updating the corresponding specific data source instance and its database connection pool information.
[0019] Optionally, it also includes a configuration information query and monitoring module: used to obtain the data source configuration information and monitor changes in the data source configuration information through configuration information query and monitoring services, wherein the data source configuration information is obtained and monitored in one of the following three ways: Method 1: obtaining the data source configuration information from a configuration file under a file path name specified by the database application system, and periodically scanning the configuration file to monitor changes in the data source configuration information; Method 2: obtaining the data source configuration information from a remote configuration center according to a configuration information query interface configured by the database application system, and monitoring changes in the data source configuration information pushed to a message queue or distributed service by the remote configuration center; Method 3: using a first interface method and a second interface method customized by the database application system to respectively obtain and monitor the data source configuration information, the first interface method being an interface method for querying data source configuration information, and the second interface method being an interface method for monitoring changes in data source configuration information.
[0020] Optionally, the data source routing module includes a specific data source routing submodule, which is used to: calculate the first target specific data source name corresponding to the tenant of the current context and the business direction of the current access under the overall dynamic data source according to the tenant information of the current context obtained and the business direction information of the current access in accordance with the naming convention of the matrix data source; switch the access request to the specific data source corresponding to the first target specific data source name according to the correspondence between the specific data source name and the specific data source instance; or, calculate the second target specific data source name corresponding to the tenant of the current context under the target business dynamic data source according to the naming convention of the matrix data source according to the correspondence between the specific data source name and the specific data source instance; switch the access request to the specific data source corresponding to the second target specific data source name according to the correspondence between the specific data source name and the specific data source instance.
[0021] Optionally, each business dynamic data source corresponds to a business direction, and each specific data source corresponds to a tenant and a business direction; the naming convention of the matrix data source is: the first character string, the second character string, and the third character string respectively represent the overall dynamic data source, the business dynamic data source, and the specific data source, the name of the overall dynamic data source is the first character string, the name of each of the business dynamic data source is a combination of the corresponding business direction keyword and the second character string, and the name of each of the specific data source is a combination of the corresponding tenant identifier, the business direction keyword, and the third character string.
[0022] Optionally, the target business dynamic data source is a business dynamic data source located by the database application system through the business direction specified in its local configuration file; the currently accessed business direction is obtained according to the business direction declared by the database application system or the business direction value passed by the database application system, wherein the database application system declares the business direction through an annotation identifier or passes the business direction value through a first thread-level static method.
[0023] Optionally, the tenant information of the current context is acquired by reading a context tenant identification value set by the database application system in a system property, or reading a context tenant identification value passed by the database application system by calling a second thread-level static method.
[0024] According to yet another aspect of the embodiments of the present invention, an electronic device is provided.
[0025] An electronic device includes: one or more processors; a memory for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the data source routing method provided by the present invention.
[0026] According to yet another aspect of an embodiment of the present invention, a computer readable medium is provided.
[0027] A computer readable medium stores a computer program, and when the program is executed by a processor, the data source routing method provided by the present invention is implemented.
[0028] An embodiment of the above invention has the following advantages or beneficial effects: receiving a database application system's access request to a matrix data source, the matrix data source includes an overall dynamic data source, a business dynamic data source, and a specific data source; when the database application system accesses the overall dynamic data source, the tenant information of the current context of the database application system and the business direction information currently accessed are obtained through the matrix data source routing service, and the access request is switched to a specific data source corresponding to the tenant of the current context and the business direction currently accessed under the overall dynamic data source; when the database application system accesses a target business dynamic data source among multiple business dynamic data sources, the tenant information of the current context of the database application system is obtained through the business dynamic data source routing service, and the access request is switched to a specific data source corresponding to the tenant of the current context under the target business dynamic data source. The problem of automatic routing switching of multi-tenants and multi-business data sources can be solved at the same time. Furthermore, through the embodiment of the present invention, it can be decomposed into three field services: configuration information query and monitoring, matrix data source dynamic initialization, and matrix data source dynamic routing (specifically implemented through matrix data source routing service and business dynamic data source routing service). Each field service supports multiple application access methods to interact with the database application system, and the data source routing device of the embodiment of the present invention can be implemented as an independent matrix data source routing device application component, thereby achieving code decoupling from the database application system and enhancing the reusability of the solution.
[0029] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0031] Figure 1 is a schematic diagram of main steps of a data source routing method according to an embodiment of the present invention;
[0032] Figure 2 is a schematic diagram of a system architecture for data source routing according to an embodiment of the present invention;
[0033] Figure 3 is a schematic diagram of main modules of a data source routing device according to an embodiment of the present invention;
[0034] Figure 4 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0035] Figure 5 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0036] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0037] Those skilled in the art will appreciate that the embodiments of the present invention may be implemented as a system, device, apparatus, method or computer program product. Therefore, the present disclosure may be implemented in the following forms, namely: complete hardware, complete software (including firmware, resident software, microcode, etc.), or a combination of hardware and software.
[0038] Figure 1 4 is a schematic diagram of main steps of a data source routing method according to an embodiment of the present invention.
[0039] like Figure 1 As shown, the data source routing method of the embodiment of the present invention mainly includes steps S101 to S103.
[0040] Step S101: Receive a database application system's access request to a matrix data source, where the matrix data source includes an overall dynamic data source, a business dynamic data source, and a specific data source, wherein one overall data source corresponds to multiple business dynamic data sources, and each business dynamic data source corresponds to multiple specific data sources.
[0041] Each business dynamic data source corresponds to a business direction, and each specific data source corresponds to a tenant and a business direction. A business direction refers to a business field, a sub-field, or a business sub-database in a database application system. Both the overall dynamic data source and the business dynamic data source are data sources that do not have a specific channel to connect to the database, while the specific data source is a data source that has a specific channel to connect to the database.
[0042] When the database application system accesses the overall dynamic data source, step S102 is executed. When the database application system accesses a target business dynamic data source among multiple business dynamic data sources, step S103 is executed. The target business dynamic data source is a business dynamic data source located by the database application system through the business direction specified in its local configuration file.
[0043] Step S102: Obtain the tenant information of the current context and the business direction information of the current access through the matrix data source routing service of the database application system, and switch the access request to the specific data source corresponding to the tenant of the current context and the business direction of the current access under the overall dynamic data source.
[0044] Specifically, based on the tenant information of the current context (referred to as context) and the currently accessed business direction information obtained, the first target specific data source name corresponding to the tenant of the current context and the currently accessed business direction under the overall dynamic data source can be calculated in accordance with the naming convention of the matrix data source; based on the correspondence between the specific data source name and the specific data source instance, the access request is switched to the specific data source corresponding to the first target specific data source name.
[0045] The currently accessed business direction may be obtained according to the business direction declared by the database application system or the business direction value passed by the database application system, wherein the database application system declares the business direction through an annotation identifier or passes the business direction value through a first thread-level static method.
[0046] Furthermore, the tenant information of the current context is obtained by reading the context tenant identification value set by the database application system in the system properties, or reading the context tenant identification value passed by the database application system by calling the second thread-level static method.
[0047] The naming convention of the matrix data source is introduced in detail below. The first character string, the second character string, and the third character string represent the overall dynamic data source, the business dynamic data source, and the specific data source, respectively. For example, the first character string is matrixDatasource, the second character string is DynamicDatasource, and the third character string is Datasource. When naming the overall dynamic data source, the business dynamic data source, and the specific data source, the first character string, the second character string, and the third character string are used to distinguish the three types of data sources, namely, the overall dynamic data source, the business dynamic data source, and the specific data source. Specifically, the name of the overall dynamic data source is the first character string, for example, matrixDatasource; the name of each business dynamic data source is a combination of the corresponding business direction keyword and the second character string, for example, the naming rule of the business dynamic data source is: the business direction keyword is followed by DynamicDatasource; the name of each specific data source is a combination of the corresponding tenant identifier, the business direction keyword, and the third character string, for example, the naming rule of the specific data source is: {tenant identifier}#{business direction keyword}#Datasource.
[0048] Step S103: Obtain tenant information of the current context of the database application system through the business dynamic data source routing service, and switch the access request to a specific data source corresponding to the tenant of the current context under the target business dynamic data source.
[0049] Specifically, the second target specific data source name corresponding to the tenant of the current context under the target business dynamic data source can be calculated according to the tenant information of the current context obtained and the naming convention of the matrix data source; based on the correspondence between the specific data source name and the specific data source instance, the access request is switched to the specific data source corresponding to the second target specific data source name.
[0050] The method of obtaining the tenant information of the current context has been introduced above and will not be repeated here.
[0051] Before step S101, it includes: initializing the matrix data source according to the data source configuration information, including: initializing the overall dynamic data source, multiple business dynamic data sources corresponding to the overall dynamic data source, and multiple specific data sources corresponding to each business dynamic data source, the overall dynamic data source, the business dynamic data source, and the specific data source are named according to the naming specifications of the matrix data source; creating an overall dynamic data source instance, each business dynamic data source instance, and each specific data source instance, and initializing a database connection pool instance for each specific data source, the names of the overall dynamic data source, each business dynamic data source, and each specific data source have a corresponding relationship with their respective instances, that is, the name of the instance is the name of the data source, for example, the name of the overall dynamic data source instance is the name of the overall dynamic data source, and the corresponding relationship between the names of the business dynamic data source and the specific data source and the instance is similar.
[0052] The initialized matrix data source is dynamically updated as the data source configuration information changes. The dynamic update includes: updating the corresponding business dynamic data source instance according to the change of the data source configuration information, and updating the corresponding specific data source instance and its database connection pool information.
[0053] You can use the configuration information query and monitoring service to obtain data source configuration information and monitor changes in data source configuration information. The data source configuration information can be obtained and monitored in one of the following ways:
[0054] Method 1: obtaining the data source configuration information from a configuration file under a file path name specified by a database application system, and periodically scanning the configuration file to monitor changes in the data source configuration information;
[0055] Method 2: Obtain data source configuration information from the remote configuration center according to the configuration information query interface configured by the database application system, and monitor the data source configuration information changes pushed by the remote configuration center to the message queue or distributed service, such as ZooKeeper;
[0056] Method three: Use the first interface method and the second interface method customized by the database application system to obtain and monitor the data source configuration information respectively. The first interface method is an interface method for querying data source configuration information, and the second interface method is an interface method for monitoring changes in data source configuration information.
[0057] The embodiment of the present invention designs the data source configuration information format as the commonly used JSON (JavaScript Object Notation, JS object notation) format in the industry. Its cross-platform and easy-to-expand features can well adapt to various application scenarios such as configuration files, external configuration centers, and database application system customization. The specific content format is designed as follows:
[0058]
[0059] Figure 2 4 is a schematic diagram of a system architecture for data source routing according to an embodiment of the present invention.
[0060] like Figure 2 As shown, the overall architecture of the embodiment of the present invention includes three services: configuration information query and monitoring, matrix data source dynamic initialization, and matrix data source dynamic routing.
[0061] Configuration information query and monitoring services support local multi-service multi-tenant data source configuration information (referred to as data source configuration information), and also support remote unified configuration center (i.e. Figure 2 It can query and monitor multi-business and multi-tenant data source configuration information through an external unified configuration and management center in the database, and support customized data sources of database application systems (for example, applications can obtain data source configuration information from Git (an open source distributed version control system) repositories).
[0062] The embodiment of the present invention provides three configuration information query and monitoring methods as follows: for the database application system to choose: 1. Configuration file method; 2. Remote configuration center method; 3. Application customization method. The local configuration attribute queryConfigType of the database application system is designed to specify one of the three methods: local (i.e. configuration file method) / remote (i.e. remote configuration center method) / customize (i.e. application customization method).
[0063] For the configuration file method, a local configuration attribute of the database application system is used to specify the file path name, and local files, network system files and distributed system files are supported. The local configuration attribute is: dbConfigFilePath: / usr / config / db.json, and the content of the configuration file fully complies with the JSON format of the data source configuration information designed above. The configuration information query and monitoring service of the embodiment of the present invention periodically scans the configuration file content changes to implement the monitoring of the data source configuration information.
[0064] For the remote configuration center mode, the configuration information query interface design uses the Restful WebService protocol, and the return value is the JSON format designed above. The URL (Uniform Resource Locator) of the remote configuration center configuration information query interface can be configured by the database application system through the local configuration attribute remoteConfigURL, for example, remoteConfigURL: http: / / host:port / queryConfig? appCode=specified application. Data source configuration information change monitoring supports two methods: one is data source configuration information change notification and monitoring based on MQ (message queue); the other is data source configuration information change notification and monitoring based on ZooKeeper (a distributed, open source distributed application coordination service) coordination service. Specifically, it can be specified by the local configuration attribute remoteConfigListeningMode: MQ / ZooKeeper of the database application system. The remote configuration center is responsible for pushing data source configuration information changes to MQ / ZooKeeper, and the configuration information query and monitoring service is responsible for monitoring the data source configuration information changes of the specified database application system in MQ / ZooKeeper, and performing the corresponding matrix data source initialization and dynamic update processing.
[0065] Two interface program methods are designed for application customization: interface method 1 (i.e. the first interface method mentioned above) is for querying configuration information, and the return value is in the JSON format designed above; interface method 2 (i.e. the second interface method mentioned above) is for monitoring configuration changes. The database application system needs to implement the two interface methods of this interface to specify how to obtain configuration information of multi-business and multi-tenant data sources and how to monitor changes.
[0066] When the database application system starts, it calls the initialization method initializeMatrixDatasource() of the embodiment of the present invention to query the initial configuration information and start the monitoring service. At the same time, the local configuration attribute systemApplicationCode is used to indicate the unique identifier of the database application system in the unified configuration and management center.
[0067] Regardless of which configuration information query and monitoring method the database application system uses, when the configuration information query and monitoring service queries the initial multi-business multi-tenant data source configuration information and monitors and receives changes in data source configuration information, it directly calls the matrix data source dynamic initialization service to push the data source configuration information and uniformly initialize the database application system's multi-business multi-tenant matrix data source.
[0068] The matrix data source dynamic initialization service includes the data source initialization service (initializeDatasource()) and the data source update service (updateDatasource()). The data source initialization service is used to initialize the matrix data source according to the data source configuration information, including initializing an overall dynamic data source, multiple business dynamic data sources and several specific data sources, and initializing a database connection pool for each specific data source. The data source update service is used to dynamically update the entire matrix data source according to the monitored data source configuration change information. The following is a detailed introduction to the matrix data source dynamic initialization service.
[0069] The embodiment of the present invention designs a matrix data source logical structure to implement the above two services of initializeDatasource() and updateDatasource(). The matrix data source refers to a dynamic data source described from the two dimensions of business and tenant. Its logical structure includes: an overall dynamic data source, multiple business-level dynamic data sources (such as Figure 2 business A dynamic data source ~ business M dynamic data source) and several specific data sources (such as Figure 2 Business A tenant 1 data source, business A tenant 2 data source, and so on). The overall dynamic data source is named matrixDatasource; multiple business dynamic data sources correspond to multiple business data source configuration information, that is, a business dynamic data source is initialized for each business data source configuration information, and the naming rule is business direction keyword followed by DynamicDatasource; several specific data sources refer to initializing a specific data source for each business data source configuration of each tenant. If there are M business directions and N tenants, M*N specific data sources need to be initialized. The naming rule of specific data sources is: {tenant identifier}#{business direction keyword}#Datasource. Each specific data source is initialized according to the database type, data source type, connection parameters, and connection pool configuration parameter information configured for it.
[0070] The data source initialization service receives JSON structure data that conforms to the data source configuration information format. According to the matrix data source logical structure and naming conventions designed above, it creates an overall dynamic data source instance, multiple business-level dynamic data source instances, and several specific data source instances, and initializes a database connection pool instance for each specific data source (for example Figure 2 At the same time, the overall dynamic data source is set as the system default data source, and the corresponding relationship between the names of these data sources and their initialized data source instances is passed to the matrix data source dynamic routing service.
[0071] The data source update service receives JSON structure data that conforms to the data source configuration information format, which represents the changed data source configuration information (including the complete configuration information of the newly added, modified and deleted data sources, excluding the configuration information of the unchanged data sources). According to the matrix data source logical structure and naming specifications designed above, it adds, modifies and deletes the corresponding business dynamic data source instances, adds, modifies and deletes the corresponding specific data source instances and their database connection pool information, and passes the corresponding relationship between the names of these updated data sources and their initialized data source instances to the matrix data source dynamic routing service. It should be noted that the process of updating (adding, modifying and deleting) the above instances by the data source update service is the process of destroying the original old instances and creating new instances (i.e. reinitialization).
[0072] The matrix data source dynamic routing service automatically switches the system data source to the corresponding business data source of the corresponding tenant according to the context tenant and the business direction currently being accessed. The matrix data source dynamic routing service specifically includes the matrix data source routing service and the business dynamic data source routing service. The matrix data source routing service can automatically switch the access request to the specific data source of the corresponding tenant and the corresponding business according to the context tenant information and the business direction information currently being accessed. The business dynamic data source routing service can automatically switch the access request to the specific data source of the corresponding tenant under the business dynamic data source located by the database application system according to the context tenant information.
[0073] The matrix data source dynamic routing service also provides two sub-services, which are used to obtain the context tenant and the currently accessed business direction. The context tenant information and the currently accessed business direction information can be obtained from the runtime process environment of the database application system. According to the logical structure of the matrix data source and its naming specifications, the specific data source name corresponding to the context tenant and the currently accessed business direction is calculated, and then the specific data source instance to be used is determined according to the corresponding relationship between the data source name and its instance passed by the matrix data source dynamic initialization service, and the corresponding database connection pool is returned, so that the automatic routing service to the data source of the corresponding business direction of the corresponding tenant can be realized. The following is a detailed introduction to obtaining the context tenant and obtaining the currently accessed business direction.
[0074] The embodiment of the present invention designs two ways to obtain context tenant information (context tenant identification value): one is to pass through the system property _ContextTenantId. Before the database application system uses the data source, the context tenant identification value is set to the system property, and the matrix data source dynamic routing service is responsible for dynamically reading the value from the system property; the second is to pass through the thread-level static method setContextTenantId() provided by the embodiment of the present invention. Specifically, the database application system is responsible for calling this method to pass the context tenant identification value, and the matrix data source dynamic routing service is responsible for reading the value and cleaning it up immediately after using it in the current thread. The database application system can choose one of the above two ways to pass the context tenant information as needed. As a preferred implementation, the second way can be used first, that is, the context tenant identification value passed through the thread-level static method setContextTenantId() (i.e., the second thread-level static method above). If it is not obtained through the second way, the context tenant identification value is obtained through the first way, that is, reading the system property _ContextTenantId.
[0075] The embodiment of the present invention designs three ways to obtain the business direction of the current access, and the database application system can freely choose one or more of the ways according to its own business scenario. Among the three ways, the first way: the database application system specifies a group of service classes or all services in a certain package to use a certain business dynamic data source in a unified manner in the local configuration file, and the specified business dynamic data source complies with the matrix data source naming specification. For example, all services in the fixed assets (business direction is fixedAssets) package of the financial system are uniformly configured to use the fixedAssetsDynamicDatasource business dynamic data source. The second way: the embodiment of the present invention provides an annotation tag @Datasource, and the database application system declares the business direction (A (only for example)) corresponding to the service through the annotation tag @Datasource ("business direction A") on its persistent service class. When the matrix data source dynamic routing service is running, it attempts to read the annotation tag on the persistent service class currently accessed by the database application system to determine the business direction currently accessed. Method three: The embodiment of the present invention provides a thread-level static method setCurrentBusinessKey() (i.e., the first thread-level static method mentioned above) for the database application system to pass the currently accessed business direction. The database application system is responsible for calling this method to pass the currently accessed business direction value, and the matrix data source dynamic routing service is responsible for reading the value and cleaning it up immediately after using it in the current thread.
[0076] Among the three ways to obtain the business direction of the current visit, the first and second ways are often used in database application systems with relatively fixed business direction numbers and names; while the third way is often used in database application systems with variable business directions. The database application system calculates the current business direction according to its business logic and then passes it to the matrix data source dynamic routing service for dynamic routing of the data source, for example, the business sub-database routing is performed according to the result value of the modulo operation of the business primary key as the business direction. The embodiment of the present invention preferentially adopts the third way to obtain the business direction of the current visit. If it is not obtained, it is obtained according to the second way. If it is still not obtained, it is obtained by the first way.
[0077] From the functional division, the matrix data source dynamic routing service includes the matrix data source routing service and the business dynamic data source routing service. Among them, the matrix data source routing service sets the overall dynamic data source as the system default data source. When the database application system accesses the matrix data source, the matrix data source routing service calculates the corresponding specific data source name according to the obtained context tenant information and the currently accessed business direction information and the matrix data source naming specification. Then, according to the correspondence between the data source name and its instance passed by the matrix data source dynamic initialization service, the specific data source instance to be used is determined, and the corresponding database connection pool is returned to realize automatic routing of specific data sources. The business dynamic data source routing service is used in the scenario where the database application system has configured a specified business dynamic data source for a certain package. After the database application system has configured a specified business dynamic data source for a certain package (the business direction currently accessed is the business direction corresponding to the specified business dynamic data source), when the database application system accesses the business dynamic data source during operation, the business dynamic data source routing service calculates the specific data source name corresponding to the tenant under the business dynamic data source based on the context tenant information obtained and the matrix data source naming specification, and then determines the specific data source instance that should be used currently based on the correspondence between the data source name and its instance, and returns the corresponding database connection pool to realize automatic routing of specific data sources in this business.
[0078] Among them, when using the matrix data source routing service or the business dynamic data source routing service for data source routing, the context tenant information can be obtained by any of the two methods of obtaining context tenant information mentioned above (the second method is preferred). When using the matrix data source routing service for data source routing, the business direction of the current access is obtained by using method two or method three of the three methods of obtaining the business direction of the current access (method three is preferred). When the business dynamic data source routing service is used for data source routing, according to method one of obtaining the business direction of the current access, the database application system specifies a business dynamic data source in the local configuration file, that is, locates the business dynamic data source, so that the business direction corresponding to the business dynamic data source is the business direction of the current access. In other words, the business dynamic data source routing service does not need to obtain the business direction of the current access separately.
[0079] The embodiment of the present invention supports configuration, initialization and automatic routing of data sources from two dimensions: tenant and business, forming a matrix data source routing service, and supports declaring its business direction on the database application system persistent service class in the form of annotation identifiers, forming a declarative data source routing service. In addition, the service of the embodiment of the present invention can be decomposed into three field services: configuration information query and monitoring, matrix data source dynamic initialization and matrix data source dynamic routing. Each field service supports multiple application access methods to interact with the database application system, and provides an independent matrix data source routing device application component, thereby realizing code decoupling from the database application system.
[0080] Figure 3 4 is a schematic diagram of main modules of a data source routing device according to an embodiment of the present invention.
[0081] like Figure 3 As shown, a data source routing device 300 according to an embodiment of the present invention mainly includes: a data source initialization module 301 , an access request receiving module 302 , and a data source routing module 303 .
[0082] The data source initialization module 301 is used to initialize the matrix data source according to the data source configuration information, including initializing the overall dynamic data source, multiple business dynamic data sources corresponding to the overall dynamic data source, and multiple specific data sources corresponding to each business dynamic data source. The overall dynamic data source, the business dynamic data source, and the specific data sources are named according to the naming specifications of the matrix data source; respectively create an overall dynamic data source instance, each business dynamic data source instance, and each specific data source instance, and initialize a database connection pool instance for each specific data source. The names of the overall dynamic data source, each business dynamic data source, and each specific data source correspond to their respective instances.
[0083] The access request receiving module 302 is used to receive the access request of the database application system to the matrix data source, and the matrix data source includes an overall dynamic data source, a business dynamic data source, and a specific data source, wherein one overall data source corresponds to multiple business dynamic data sources, and each business dynamic data source corresponds to multiple specific data sources. Each business dynamic data source corresponds to a business direction, and each specific data source corresponds to a tenant and a business direction.
[0084] The data source routing module 303 is used to obtain the tenant information of the current context of the database application system and the business direction information currently accessed through the matrix data source routing service when the database application system accesses the overall dynamic data source, and switch the access request to the specific data source corresponding to the tenant of the current context and the business direction currently accessed under the overall dynamic data source; when the database application system accesses a target business dynamic data source among multiple business dynamic data sources, the tenant information of the current context of the database application system is obtained through the business dynamic data source routing service, and the access request is switched to the specific data source corresponding to the tenant of the current context under the target business dynamic data source.
[0085] The data source routing device 300 may also include a data source update module for dynamically updating the initialized matrix data source as the data source configuration information changes. The dynamic update content includes: updating the corresponding business dynamic data source instance according to the change of the data source configuration information, and updating the corresponding specific data source instance and its database connection pool information.
[0086] The data source routing device 300 may also include a configuration information query and monitoring module: used to obtain data source configuration information and monitor changes in data source configuration information through configuration information query and monitoring services, wherein the data source configuration information is obtained and monitored in one of the following three ways: Method 1: obtaining data source configuration information from a configuration file under a file path name specified by the database application system, and periodically scanning the configuration file to monitor changes in data source configuration information; Method 2: obtaining data source configuration information from a remote configuration center according to a configuration information query interface configured by the database application system, and monitoring changes in data source configuration information pushed to a message queue or distributed service by the remote configuration center; Method 3: using a first interface method and a second interface method customized by the database application system to obtain and monitor data source configuration information respectively, the first interface method being an interface method for querying data source configuration information, and the second interface method being an interface method for monitoring changes in data source configuration information.
[0087] The data source routing module 303 may specifically include a specific data source routing submodule, which is used to: calculate the first target specific data source name corresponding to the tenant of the current context and the business direction of the current access under the overall dynamic data source according to the tenant information of the current context obtained and the business direction information of the current access in accordance with the naming convention of the matrix data source; switch the access request to the specific data source corresponding to the first target specific data source name according to the correspondence between the specific data source name and the specific data source instance; or, calculate the second target specific data source name corresponding to the tenant of the current context under the target business dynamic data source according to the naming convention of the matrix data source according to the tenant information of the current context obtained; and switch the access request to the specific data source corresponding to the second target specific data source name according to the correspondence between the specific data source name and the specific data source instance.
[0088] The naming convention of the matrix data source can be: the first string, the second string, and the third string respectively represent the overall dynamic data source, the business dynamic data source, and the specific data source. The name of the overall dynamic data source is the first string, the name of each business dynamic data source is a combination of the corresponding business direction keyword and the second string, and the name of each specific data source is a combination of the corresponding tenant identifier, business direction keyword, and the third string.
[0089] The target business dynamic data source can be a business dynamic data source located by the database application system through the business direction specified in its local configuration file; the currently accessed business direction is obtained according to the business direction declared by the database application system or the business direction value passed by the database application system, wherein the database application system declares the business direction through an annotation identifier or passes the business direction value through a first thread-level static method.
[0090] The tenant information of the current context is obtained by reading the context tenant identification value set in the system property of the database application system, or reading the context tenant identification value passed by the database application system by calling the second thread-level static method.
[0091] The data source routing device of the embodiment of the present invention can be implemented as an independent application component with perfect specifications and standardized interfaces. The component is independent of the database application system and runs in the same operating system process as the database application system. For example, it is implemented as a Jar (Java ARchive, Java archive) package in Java language, or a DLL (dynamic link library file) in C# language. The multi-service multi-tenant data source configuration information supports local file configuration, and also supports interaction with an external unified configuration and management center, and supports customized configuration query and monitoring of the database application system. In addition, how the current context tenant of the database application system is passed to the multi-service multi-tenant matrix data source routing device, and how the database application system specifies the corresponding data source when developing specific business modules and configuring the system, all require the data source routing device to uniformly perform standard agreements and formulate standardized service interfaces. Under the guidance of relevant standard agreements, the data source routing device starts with the above-mentioned configuration information query and monitoring, matrix data source dynamic initialization, and matrix data source dynamic routing. The three services are implemented separately. The embodiment of the present invention can solve the problem of dynamic configuration and automatic routing switching of multi-tenant and multi-service data sources in complex database application systems.
[0092] In addition, the specific implementation content of the data source routing device in the embodiment of the present invention has been described in detail in the data source routing method described above, so the repeated content will not be described again here.
[0093] Figure 4 An exemplary system architecture 400 is shown to which the data source routing method or data source routing device according to the embodiment of the present invention can be applied.
[0094] like Figure 4 As shown, system architecture 400 may include terminal devices 401, 402, 403, network 404 and server 405. Network 404 is used to provide a medium for communication links between terminal devices 401, 402, 403 and server 405. Network 404 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0095] Users can use terminal devices 401, 402, 403 to interact with server 405 through network 404 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 401, 402, 403, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only as examples).
[0096] The terminal devices 401 , 402 , and 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.
[0097] The server 405 may be a server that provides various services, such as a backend management server (only an example) that provides support for shopping websites browsed by users using the terminal devices 401, 402, and 403. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information, product information - only an example) to the terminal device.
[0098] It should be noted that the data source routing method provided in the embodiment of the present invention is generally executed by the server 405 , and accordingly, the data source routing device is generally disposed in the server 405 .
[0099] It should be understood that Figure 4 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0100] Reference below Figure 5 , which shows a schematic diagram of the structure of a computer system 500 of a terminal device or server suitable for implementing an embodiment of the present application. Figure 5 The terminal device or server shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0101] like Figure 5 As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage part 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the system 500 are also stored. The CPU 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0102] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, etc.; an output section 507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN card, a modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 510 as needed, so that a computer program read therefrom is installed into the storage section 508 as needed.
[0103] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the main step schematic diagram can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the main step schematic diagram. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 509, and / or installed from the removable medium 511. When the computer program is executed by the central processing unit (CPU) 501, the above-mentioned functions defined in the system of the present application are executed.
[0104] It should be noted that the computer-readable medium shown in the present invention can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present application, a computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal can take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0105] The main step schematic diagram and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each box in the main step schematic diagram or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or the main step schematic diagram, and the combination of the boxes in the block diagram or the main step schematic diagram can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0106] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be arranged in a processor, for example, it may be described as: a processor includes an access request receiving module and a data source routing module. The names of these modules do not constitute a limitation on the modules themselves in certain cases, for example, the access request receiving module may also be described as "a module for receiving an access request from a database application system to a matrix data source".
[0107] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently and not assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: receiving a database application system's access request to a matrix data source, the matrix data source includes an overall dynamic data source, a business dynamic data source, and a specific data source, wherein one overall data source corresponds to multiple business dynamic data sources, and each business dynamic data source corresponds to multiple specific data sources; when the database application system accesses the overall dynamic data source, the tenant information of the current context of the database application system and the business direction information currently accessed are obtained through the matrix data source routing service, and the access request is switched to the specific data source corresponding to the tenant of the current context and the business direction currently accessed under the overall dynamic data source; when the database application system accesses a target business dynamic data source among the multiple business dynamic data sources, the tenant information of the current context of the database application system is obtained through the business dynamic data source routing service, and the access request is switched to the specific data source corresponding to the tenant of the current context under the target business dynamic data source.
[0108] According to the technical solution of the embodiment of the present invention, a database application system receives an access request to a matrix data source, and the matrix data source includes an overall dynamic data source, a business dynamic data source, and a specific data source; when the database application system accesses the overall dynamic data source, the tenant information of the current context of the database application system and the business direction information of the current access are obtained through the matrix data source routing service, and the access request is switched to the specific data source corresponding to the tenant of the current context and the business direction of the current access under the overall dynamic data source; when the database application system accesses a target business dynamic data source among multiple business dynamic data sources, the tenant information of the current context of the database application system is obtained through the business dynamic data source routing service, and the access request is switched to the specific data source corresponding to the tenant of the current context under the target business dynamic data source. The problem of automatic routing switching of multi-tenants and multi-business data sources can be solved at the same time. And through the embodiment of the present invention, it can be decomposed into three field services: configuration information query and monitoring, matrix data source dynamic initialization, and matrix data source dynamic routing (specifically implemented by matrix data source routing service and business dynamic data source routing service). Each field service supports multiple application access modes to interact with the database application system, and the data source routing device of the embodiment of the present invention can be implemented as an independent matrix data source routing device application component, thereby realizing code decoupling from the database application system and enhancing the reusability of the solution.
[0109] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A data source routing method, characterized in that: include: Receiving an access request from a database application system to a matrix data source, wherein the matrix data source includes an overall dynamic data source, a business dynamic data source, and a specific data source, wherein one overall data source corresponds to multiple business dynamic data sources, and each business dynamic data source corresponds to multiple specific data sources; When the database application system accesses the overall dynamic data source, the tenant information of the current context and the business direction information of the current access of the database application system are obtained through the matrix data source routing service, and the access request is switched to the specific data source corresponding to the tenant of the current context and the business direction of the current access under the overall dynamic data source; When the database application system accesses a target business dynamic data source among the multiple business dynamic data sources, the tenant information of the current context of the database application system is obtained through the business dynamic data source routing service, and the access request is switched to a specific data source corresponding to the tenant of the current context under the target business dynamic data source.
2. The method according to claim 1, characterized in that Before the step of receiving the access request of the database application system to the matrix data source, the method includes: Initializing the matrix data source according to the data source configuration information, including: initializing the overall dynamic data source, multiple business dynamic data sources corresponding to the overall dynamic data source, and multiple specific data sources corresponding to each business dynamic data source, wherein the overall dynamic data source, the business dynamic data source, and the specific data source are named according to the naming specification of the matrix data source; Create an overall dynamic data source instance, each business dynamic data source instance, and each specific data source instance respectively, and initialize a database connection pool instance for each specific data source. The names of the overall dynamic data source, each business dynamic data source, and each specific data source correspond to their respective instances.
3. The method according to claim 2, characterized in that The initialized matrix data source is dynamically updated as the data source configuration information changes. The dynamic update includes: updating the corresponding business dynamic data source instance according to the change of the data source configuration information, and updating the corresponding specific data source instance and its database connection pool information.
4. The method according to claim 3, characterized in that Also includes: The data source configuration information is obtained and the changes of the data source configuration information are monitored through the configuration information query and monitoring service, wherein the data source configuration information is obtained and monitored in one of the following three ways: Method 1: obtaining the data source configuration information from a configuration file under a file path name specified by the database application system, and periodically scanning the configuration file to monitor changes in the data source configuration information; Method 2: obtaining the data source configuration information from the remote configuration center according to the configuration information query interface configured by the database application system, and monitoring the data source configuration information changes pushed by the remote configuration center to the message queue or distributed service; Method three: Use the first interface method and the second interface method customized by the database application system to respectively obtain and monitor the data source configuration information, the first interface method is an interface method for querying data source configuration information, and the second interface method is an interface method for monitoring changes in data source configuration information.
5. The method according to claim 1, characterized in that The step of switching the access request to a specific data source under the overall dynamic data source corresponding to the tenant of the current context and the business direction of the current access comprises: According to the tenant information of the current context and the business direction information currently accessed, and in accordance with the naming convention of the matrix data source, a first target specific data source name corresponding to the tenant of the current context and the business direction currently accessed under the overall dynamic data source is calculated; According to the correspondence between the specific data source name and the specific data source instance, the access request is switched to the specific data source corresponding to the first target specific data source name; The step of switching the access request to a specific data source corresponding to the tenant of the current context under the target business dynamic data source comprises: According to the tenant information of the current context obtained, the second target specific data source name corresponding to the tenant of the current context under the target business dynamic data source is calculated according to the naming convention of the matrix data source; According to the correspondence between the specific data source name and the specific data source instance, the access request is switched to the specific data source corresponding to the second target specific data source name.
6. The method according to claim 2 or 5, characterized in that: Each business dynamic data source corresponds to a business direction, and each specific data source corresponds to a tenant and a business direction; The naming convention of the matrix data source is: The overall dynamic data source, the business dynamic data source, and the specific data source are represented by a first character string, a second character string, and a third character string, respectively. The name of the overall dynamic data source is the first character string, the name of each of the business dynamic data sources is a combination of the corresponding business direction keyword and the second character string, and the name of each of the specific data sources is a combination of the corresponding tenant identifier, the business direction keyword, and the third character string.
7. The method according to claim 1, characterized in that The target business dynamic data source is a business dynamic data source located by the database application system through the business direction specified in its local configuration file; The currently accessed business direction is obtained according to the business direction declared by the database application system or the business direction value passed by the database application system, wherein the database application system declares the business direction through an annotation identifier or passes the business direction value through a first thread-level static method.
8. The method according to claim 1, characterized in that The tenant information of the current context is obtained by reading the context tenant identification value set by the database application system in the system property, or reading the context tenant identification value passed by the database application system by calling the second thread-level static method.
9. A data source routing device, characterized in that: include: An access request receiving module is used to receive an access request from a database application system to a matrix data source, wherein the matrix data source includes an overall dynamic data source, a business dynamic data source, and a specific data source, wherein one overall data source corresponds to multiple business dynamic data sources, and each business dynamic data source corresponds to multiple specific data sources; A data source routing module is used to obtain the tenant information of the current context and the business direction information of the current access of the database application system through the matrix data source routing service when the database application system accesses the overall dynamic data source, and switch the access request to the specific data source corresponding to the tenant of the current context and the business direction of the current access under the overall dynamic data source; When the database application system accesses a target business dynamic data source among the multiple business dynamic data sources, the tenant information of the current context of the database application system is obtained through the business dynamic data source routing service, and the access request is switched to a specific data source corresponding to the tenant of the current context under the target business dynamic data source.
10. The device according to claim 9, characterized in that It also includes a data source initialization module for: Initializing the matrix data source according to the data source configuration information, including: initializing the overall dynamic data source, multiple business dynamic data sources corresponding to the overall dynamic data source, and multiple specific data sources corresponding to each business dynamic data source, wherein the overall dynamic data source, the business dynamic data source, and the specific data source are named according to the naming specification of the matrix data source; Create an overall dynamic data source instance, each business dynamic data source instance, and each specific data source instance respectively, and initialize a database connection pool instance for each specific data source. The names of the overall dynamic data source, each business dynamic data source, and each specific data source correspond to their respective instances.
11. The device according to claim 10, characterized in that It also includes a data source update module, which is used to dynamically update the initialized matrix data source as the data source configuration information changes. The content of the dynamic update includes: updating the corresponding business dynamic data source instance according to the change of the data source configuration information, updating the corresponding specific data source instance and its database connection pool information.
12. The device according to claim 11, characterized in that It also includes a configuration information query and monitoring module: used to obtain the data source configuration information and monitor changes in the data source configuration information through a configuration information query and monitoring service, wherein the data source configuration information is obtained and monitored in one of the following three ways: Method 1: obtaining the data source configuration information from a configuration file under a file path name specified by the database application system, and periodically scanning the configuration file to monitor changes in the data source configuration information; Method 2: obtaining the data source configuration information from a remote configuration center according to a configuration information query interface configured by the database application system, and monitoring changes in the data source configuration information pushed by the remote configuration center to a message queue or distributed service; Method three: Use the first interface method and the second interface method customized by the database application system to respectively obtain and monitor the data source configuration information, the first interface method is an interface method for querying data source configuration information, and the second interface method is an interface method for monitoring changes in data source configuration information.
13. The device according to claim 9, characterized in that The data source routing module includes a specific data source routing submodule, which is used to: According to the tenant information of the current context and the business direction information currently accessed, and in accordance with the naming convention of the matrix data source, a first target specific data source name corresponding to the tenant of the current context and the business direction currently accessed under the overall dynamic data source is calculated; According to the correspondence between the specific data source name and the specific data source instance, the access request is switched to the specific data source corresponding to the first target specific data source name; or, According to the tenant information of the current context obtained, the second target specific data source name corresponding to the tenant of the current context under the target business dynamic data source is calculated according to the naming convention of the matrix data source; According to the correspondence between the specific data source name and the specific data source instance, the access request is switched to the specific data source corresponding to the second target specific data source name.
14. The device according to claim 10 or 13, characterized in that Each business dynamic data source corresponds to a business direction, and each specific data source corresponds to a tenant and a business direction; The naming convention of the matrix data source is: The overall dynamic data source, the business dynamic data source, and the specific data source are represented by a first character string, a second character string, and a third character string, respectively. The name of the overall dynamic data source is the first character string, the name of each of the business dynamic data sources is a combination of the corresponding business direction keyword and the second character string, and the name of each of the specific data sources is a combination of the corresponding tenant identifier, the business direction keyword, and the third character string.
15. The device according to claim 9, characterized in that The target business dynamic data source is a business dynamic data source located by the database application system through the business direction specified in its local configuration file; The currently accessed business direction is obtained according to the business direction declared by the database application system or the business direction value passed by the database application system, wherein the database application system declares the business direction through an annotation identifier or passes the business direction value through a first thread-level static method.
16. The device according to claim 9, characterized in that The tenant information of the current context is obtained by reading the context tenant identification value set by the database application system in the system property, or reading the context tenant identification value passed by the database application system by calling the second thread-level static method.
17. An electronic device, characterized in that: include: one or more processors; a memory for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors are enabled to implement the method according to any one of claims 1 to 8.
18. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Multi-tenant-oriented data acquisition method, device and system
CN102456028A
Invocation method for providing and obtaining dynamic routing and static routing based on cloud computing deployment
CN102594661A