CN112306984A - Data source routing method and device - Google Patents

Data source routing method and device Download PDF

Info

Publication number
CN112306984A
CN112306984A CN201910695657.7A CN201910695657A CN112306984A CN 112306984 A CN112306984 A CN 112306984A CN 201910695657 A CN201910695657 A CN 201910695657A CN 112306984 A CN112306984 A CN 112306984A
Authority
CN
China
Prior art keywords
data source
service
dynamic data
application system
tenant
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201910695657.7A
Other languages
Chinese (zh)
Inventor
刘荣华
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201910695657.7A priority Critical patent/CN112306984A/en
Publication of CN112306984A publication Critical patent/CN112306984A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/18File system types
    • G06F16/182Distributed file systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/25Integrating or interfacing systems involving database management systems
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/60Scheduling or organising the servicing of application requests, e.g. requests for application data transmissions using the analysis and optimisation of the required network resources
    • H04L67/63Routing a service request depending on the request content or context

Abstract

The invention discloses a data source routing method and device, and relates to the technical field of computers. The method comprises the steps that an access request of a database application system to a matrix data source is received, a total data source in the matrix data source corresponds to a plurality of service dynamic data sources, and each service dynamic data source corresponds to a plurality of specific data sources; under the condition that a database application system accesses a total dynamic data source, acquiring tenant information of the current context and currently accessed service direction information, and switching an access request to a specific data source corresponding to the current service direction of the current context tenant under the total dynamic data source; and under the condition that the database application system accesses the target service dynamic data source, acquiring the current context tenant information, and switching the access request to a specific data source corresponding to the current context tenant under the target service dynamic data source. The problem of routing switching of multi-tenant multi-service data sources can be solved simultaneously, decoupling with a database application system code is achieved, and reusability is high.

Description

Data source routing method and device
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a data source routing method and apparatus.
Background
In a database application system, a data source is used as a standard interface for database connection management and bears extremely important responsibility. The complex database application system not only relates to the problem of separation and routing of multi-service data sources, but also relates to the problem of isolation and routing of the data sources of multiple tenants, so that the problem that the data sources of the system need to be automatically switched to the data sources of the corresponding services of the corresponding tenants according to the context tenants and the current access service direction occurs.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art:
the problem of routing switching of multi-tenant data sources and multi-service data sources cannot be solved simultaneously, the data sources are tightly coupled with a database application system, and the reusability of a solution is poor.
Disclosure of Invention
In view of this, embodiments of the present invention provide a data source routing method and apparatus, which can simultaneously solve the problem of routing switch of multi-tenant and multi-service data sources, and are decoupled from codes of a database application system, thereby enhancing reusability of a solution.
To achieve the above object, according to an aspect of an embodiment of the present invention, a data source routing method is provided.
A data source routing method, comprising: receiving an access request of a database application system to a matrix data source, wherein the matrix data source comprises a total dynamic data source, a service dynamic data source and a specific data source, one total data source corresponds to a plurality of service dynamic data sources, and each service dynamic data source corresponds to a plurality of specific data sources; under the condition that the database application system accesses the overall dynamic data source, acquiring tenant information of the current context and currently accessed service direction information of the database application system 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 currently accessed service direction under the overall dynamic data source; and under the condition that the database application system accesses one target business dynamic data source in the plurality of business dynamic data sources, acquiring 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.
Optionally, the step of receiving an access request of the database application system to the matrix data source is preceded by: initializing the matrix data source according to data source configuration information, wherein the matrix data source comprises: initializing the total dynamic data source, a plurality of service dynamic data sources corresponding to the total dynamic data source and a plurality of specific data sources corresponding to each service dynamic data source, wherein the total dynamic data source, the service dynamic data sources and the specific data sources are named according to the naming specifications of the matrix data sources respectively; respectively creating a total dynamic data source instance, each service dynamic data source instance and each specific data source instance, initializing a database connection pool instance for each specific data source, wherein the names of the total dynamic data source, each service dynamic data source and each specific data source respectively have a corresponding relation with the respective instance.
Optionally, the initialized matrix data source is dynamically updated along with the change of the data source configuration information, and the content of the dynamic update includes: and updating the corresponding business dynamic data source example according to the change of the data source configuration information, and updating the corresponding specific data source example and the database connection pool information thereof.
Optionally, the method further comprises: acquiring the data source configuration information and monitoring the change of the data source configuration information through a configuration information query and monitoring service, wherein the acquisition and monitoring mode of the data source configuration information is one of the following three modes: the first method is as follows: acquiring the data source configuration information from a configuration file under a file path name specified by the database application system, and regularly scanning the configuration file to monitor the change of the data source configuration information; the second method comprises the following steps: acquiring 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 the data source configuration information change pushed to a message queue or distributed service by the remote configuration center; the third method comprises the following steps: and respectively acquiring and monitoring the data source configuration information by utilizing a first interface method and a second interface method which are self-defined by the database application system, wherein the first interface method is an interface method for inquiring the data source configuration information, and the second interface method is an interface method for monitoring the change of the data source configuration information.
Optionally, the step of switching the access request to a specific data source corresponding to the tenant of the current context and the currently accessed business direction under the overall dynamic data source includes: according to the acquired tenant information of the current context and the current accessed service direction information, and according to the naming specification of the matrix data source, calculating a first target specific data source name corresponding to the tenant of the current context and the current accessed service direction under the overall dynamic data source; switching the access request to a specific data source corresponding to the first target specific data source name according to the corresponding relation between the specific data source name and the specific data source instance; the step of switching the access request to a specific data source corresponding to the tenant of the current context under the target service dynamic data source includes: calculating a second target specific data source name corresponding to the tenant of the current context under the target service dynamic data source according to the acquired tenant information of the current context and the naming specification of the matrix data source; and switching the access request to a specific data source corresponding to the second target specific data source name according to the corresponding relation between the specific data source name and the specific data source instance.
Optionally, each dynamic data source of the service corresponds to a service direction, and each specific data source corresponds to a tenant and a service direction; the naming specification of the matrix data source is as follows: and respectively representing the overall dynamic data source, the service dynamic data source and the specific data source by using a first character string, a second character string and a third character string, wherein the name of the overall dynamic data source is the first character string, the name of each service dynamic data source is a combination of a service direction keyword and the second character string which correspond to each other, and the name of each specific data source is a combination of a tenant identification, a service direction keyword and the third character string which correspond to each other.
Optionally, the target service dynamic data source is a service dynamic data source located by the database application system through a service direction specified in a local configuration file of the database application system; and acquiring the current accessed business direction according to the business direction declared by the database application system or the business direction value transmitted by the database application system, wherein the database application system declares the business direction through annotation identification or transmits the business direction value through a first thread-level static method.
Optionally, the tenant information of the current context is obtained by reading a context tenant identification value set in a system attribute by the database application system, or by reading a context tenant identification value transmitted by the database application system by calling a second thread-level static method.
According to another aspect of the embodiments of the present invention, a data source routing apparatus is provided.
A data source routing apparatus, comprising: the access request receiving module is used for receiving an access request of a database application system to a matrix data source, wherein the matrix data source comprises a total dynamic data source, a service dynamic data source and a specific data source, one total data source corresponds to a plurality of service dynamic data sources, and each service dynamic data source corresponds to a plurality of specific data sources; a data source routing module, configured to, when the database application system accesses the overall dynamic data source, obtain, through a matrix data source routing service, tenant information of a current context of the database application system and currently accessed service direction information, and switch the access request to a specific data source corresponding to the tenant of the current context and the currently accessed service direction under the overall dynamic data source; and under the condition that the database application system accesses one target business dynamic data source in the plurality of business dynamic data sources, acquiring 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.
Optionally, the system further includes a data source initialization module, configured to: initializing the matrix data source according to data source configuration information, wherein the matrix data source comprises: initializing the total dynamic data source, a plurality of service dynamic data sources corresponding to the total dynamic data source and a plurality of specific data sources corresponding to each service dynamic data source, wherein the total dynamic data source, the service dynamic data sources and the specific data sources are named according to the naming specifications of the matrix data sources respectively; respectively creating a total dynamic data source instance, each service dynamic data source instance and each specific data source instance, initializing a database connection pool instance for each specific data source, wherein the names of the total dynamic data source, each service dynamic data source and each specific data source respectively have a corresponding relation with the respective instance.
Optionally, the system further includes a data source updating module, configured to dynamically update the initialized matrix data source along with a change of the data source configuration information, where the content of the dynamic update includes: and updating the corresponding business dynamic data source example according to the change of the data source configuration information, and updating the corresponding specific data source example and the database connection pool information thereof.
Optionally, the system further comprises a configuration information query and monitoring module: the data source configuration information acquisition and monitoring service is used for acquiring the data source configuration information and monitoring the change of the data source configuration information through the configuration information query and monitoring service, wherein the acquisition and monitoring mode of the data source configuration information is one of the following three modes: the first method is as follows: acquiring the data source configuration information from a configuration file under a file path name specified by the database application system, and regularly scanning the configuration file to monitor the change of the data source configuration information; the second method comprises the following steps: acquiring 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 the data source configuration information change pushed to a message queue or distributed service by the remote configuration center; the third method comprises the following steps: and respectively acquiring and monitoring the data source configuration information by utilizing a first interface method and a second interface method which are self-defined by the database application system, wherein the first interface method is an interface method for inquiring the data source configuration information, and the second interface method is an interface method for monitoring the change of the data source configuration information.
Optionally, the data source routing module includes a specific data source routing submodule configured to: according to the acquired tenant information of the current context and the current accessed service direction information, and according to the naming specification of the matrix data source, calculating a first target specific data source name corresponding to the tenant of the current context and the current accessed service direction under the overall dynamic data source; switching the access request to a specific data source corresponding to the first target specific data source name according to the corresponding relation between the specific data source name and the specific data source instance; or, according to the acquired tenant information of the current context, calculating a second target specific data source name corresponding to the tenant of the current context under the target service dynamic data source according to the naming specification of the matrix data source; and switching the access request to a specific data source corresponding to the second target specific data source name according to the corresponding relation between the specific data source name and the specific data source instance.
Optionally, each dynamic data source of the service corresponds to a service direction, and each specific data source corresponds to a tenant and a service direction; the naming specification of the matrix data source is as follows: and respectively representing the overall dynamic data source, the service dynamic data source and the specific data source by using a first character string, a second character string and a third character string, wherein the name of the overall dynamic data source is the first character string, the name of each service dynamic data source is a combination of a service direction keyword and the second character string which correspond to each other, and the name of each specific data source is a combination of a tenant identification, a service direction keyword and the third character string which correspond to each other.
Optionally, the target service dynamic data source is a service dynamic data source located by the database application system through a service direction specified in a local configuration file of the database application system; and acquiring the current accessed business direction according to the business direction declared by the database application system or the business direction value transmitted by the database application system, wherein the database application system declares the business direction through annotation identification or transmits the business direction value through a first thread-level static method.
Optionally, the tenant information of the current context is obtained by reading a context tenant identification value set in a system attribute by the database application system, or by reading a context tenant identification value transmitted by the database application system by calling a second thread-level static method.
According to yet another aspect of an embodiment of the present invention, an electronic device is provided.
An electronic device, comprising: one or more processors; a memory for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to implement the data source routing method provided by the present invention.
According to yet another aspect of an embodiment of the present invention, a computer-readable medium is provided.
A computer-readable medium, on which a computer program is stored, which, when executed by a processor, implements the data source routing method provided by the present invention.
One embodiment of the above invention has the following advantages or benefits: receiving an access request of a database application system to a matrix data source, wherein the matrix data source comprises a total dynamic data source, a business dynamic data source and a specific data source; under the condition that the database application system accesses the overall dynamic data source, acquiring tenant information of the current context and currently accessed service direction information of the database application system through a matrix data source routing service, and switching an access request to a specific data source corresponding to the tenant of the current context and the currently accessed service direction under the overall dynamic data source; under the condition that the database application system accesses one target service dynamic data source in a plurality of service dynamic data sources, the tenant information of the current context of the database application system is obtained through the service 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 service dynamic data source. The problem of multi-tenant and multi-service data source routing switching can be solved simultaneously. The embodiment of the invention can be decomposed into three field services of configuration information inquiry and monitoring, matrix data source dynamic initialization and matrix data source dynamic routing (specifically realized by matrix data source routing service and business dynamic data source routing service), each field service supports multiple application access modes to interact with a database application system, and the data source routing device of the embodiment of the invention can be realized as an independent matrix data source routing device application component, thereby realizing code decoupling with the database application system and enhancing reusability of a solution.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
fig. 1 is a schematic diagram of the main steps of a data source routing method according to an embodiment of the present invention;
FIG. 2 is a system architecture diagram of data source routing according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of the main blocks of a data source routing apparatus according to an embodiment of the present invention;
FIG. 4 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 5 is a schematic block diagram of a computer system suitable for use in implementing a terminal device or server of an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
As will be appreciated by one skilled in the art, embodiments of the present invention may be embodied as a system, apparatus, device, method, or computer program product. Accordingly, the present disclosure may be embodied in the form of: entirely hardware, entirely software (including firmware, resident software, micro-code, etc.), or a combination of hardware and software.
Fig. 1 is a schematic diagram of main steps of a data source routing method according to an embodiment of the present invention.
As shown in fig. 1, the data source routing method according to the embodiment of the present invention mainly includes steps S101 to S103.
Step S101: receiving an access request of a database application system to a matrix data source, wherein the matrix data source comprises a total dynamic data source, a service dynamic data source and a specific data source, one total data source corresponds to a plurality of service dynamic data sources, and each service dynamic data source corresponds to a plurality of specific data sources.
Each service dynamic data source corresponds to one service direction, and each specific data source corresponds to one tenant and one service direction. The service direction refers to a service field, a sub-field or a service sub-library in the database application system. Both the global dynamic data source and the business dynamic data source are data sources that do not have channels to a specific connection database, and the specific data source is a data source that has channels to a specific connection database.
Step S102 is performed in case the database application system accesses the global dynamic data source, and step S103 is performed in case the database application system accesses one target business dynamic data source of the plurality of business dynamic data sources. The target business dynamic data source is a business dynamic data source located by the database application system through the business direction specified in the local configuration file.
Step S102: and acquiring the tenant information of the current context and the currently accessed service direction information of the database application system through the 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 currently accessed service direction under the overall dynamic data source.
Specifically, the name of a first target specific data source corresponding to the tenant of the current context and the currently accessed service direction under the overall dynamic data source can be calculated according to the acquired tenant information of the current context (context for short) and the currently accessed service direction information and according to the naming specification of the matrix data source; and switching the access request to a specific data source corresponding to the first target specific data source name according to the corresponding relation between the specific data source name and the specific data source instance.
The current access business direction can be obtained according to the business direction declared by the database application system or the business direction value transmitted by the database application system, wherein the database application system declares the business direction through the annotation mark or transmits the business direction value through a first thread-level static method.
And obtaining the tenant information of the current context by reading the context tenant identification value set in the system attribute by the database application system or by reading the context tenant identification value transmitted by the database application system by calling a second thread-level static method.
The naming convention for the matrix data source is described in detail below. The first character string, the second character string and the third character string respectively represent a general dynamic data source, a business dynamic data source and a specific data source, for example, the first character string is matrix data source, the second character string is dynamic data source, and the third character string is data source. When naming the total dynamic data source, the service dynamic data source and the specific data source, the first character string, the second character string and the third character string are used for distinguishing the total dynamic data source, the service dynamic data source and the specific data source. Specifically, the name of the overall dynamic data source is a first string, for example, named matrixDatasource; the name of each service dynamic data source is a combination of the service direction keyword and the second character string corresponding to each service dynamic data source, for example, the naming rule of the service dynamic data source is as follows: the service direction keyword is connected with a dynamic data source; the name of each specific data source is a combination of the tenant identifier, the service direction keyword and the third character string corresponding to each specific data source, for example, the naming rule of the specific data source is as follows: { tenant identity } # { traffic direction key } # database.
Step S103: and acquiring tenant information of the current context of the database application system through the service 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 service dynamic data source.
Specifically, the name of a second target specific data source corresponding to the tenant of the current context under the target service dynamic data source can be calculated according to the acquired tenant information of the current context and the naming specification of the matrix data source; and switching the access request to a specific data source corresponding to the second target specific data source name according to the corresponding relation between the specific data source name and the specific data source instance.
The method for acquiring the tenant information of the current context is introduced above and is not described again.
Step S101 includes: initializing a matrix data source according to data source configuration information, wherein the matrix data source comprises: initializing a total dynamic data source, a plurality of service dynamic data sources corresponding to the total dynamic data source and a plurality of specific data sources corresponding to each service dynamic data source, wherein the total dynamic data source, the service dynamic data sources and the specific data sources are named according to naming specifications of matrix data sources respectively; respectively creating an overall dynamic data source instance, each service dynamic data source instance and each specific data source instance, and initializing a database connection pool instance for each specific data source, wherein the names of the overall dynamic data source, each service dynamic data source and each specific data source respectively have a corresponding relationship with the respective instance, namely 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 names of the service dynamic data source and the specific data source are in the same way as the corresponding relationship of the instance.
The initialized matrix data source is dynamically updated along with the change of the configuration information of the data source, and the content of the dynamic update comprises the following steps: and updating the corresponding business dynamic data source example according to the change of the data source configuration information, and updating the corresponding specific data source example and the database connection pool information thereof.
The data source configuration information and the change of the data source configuration information can be acquired through the configuration information inquiry and monitoring service, wherein the data source configuration information acquisition and monitoring mode is one of the following three modes:
the first method is as follows: acquiring the data source configuration information from a configuration file under a file path name specified by a database application system, and regularly scanning the configuration file to monitor the change of the data source configuration information;
the second method comprises the following steps: acquiring data source configuration information from a remote configuration center according to a configuration information query interface configured by a database application system, and monitoring data source configuration information change pushed to a message queue or distributed service by the remote configuration center, wherein the distributed service is ZooKeeper for example;
the third method comprises the following steps: the method comprises the steps of utilizing a first interface method and a second interface method which are self-defined by a database application system to respectively acquire and monitor data source configuration information, wherein the first interface method is an interface method for inquiring the data source configuration information, and the second interface method is an interface method for monitoring the change of the data source configuration information.
The data source configuration information format is designed into a JSON (JavaScript Object Notation) format commonly used in the industry, and the cross-platform and easily-extensible characteristics of the data source configuration information format can be well adapted to various application scenes such as configuration files, external configuration centers, self-definition of database application systems and the like. The specific content format is designed as follows:
Figure BDA0002149286900000111
fig. 2 is a system architecture diagram of data source routing according to an embodiment of the present invention.
As shown in fig. 2, the architecture of the embodiment of the present invention generally includes three services, namely, configuration information query and monitoring, dynamic initialization of a matrix data source, and dynamic routing of the matrix data source.
The configuration information query and monitoring service supports local multi-service multi-tenant data source configuration information (data source configuration information for short), also supports query and monitoring of multi-service multi-tenant data source configuration information from a remote unified configuration center (i.e., an external unified configuration and management center in fig. 2), and supports database application system custom data source (for example, an application realizes acquisition of data source configuration information from a Git (open source distributed version control system) repository).
The embodiment of the invention provides three configuration information query and monitoring modes as follows: the database application system is selected as follows: 1. a configuration file mode; 2. a remote configuration center mode; 3. and applying a self-defining mode. The local (i.e. configuration file mode)/remote (i.e. remote configuration center mode)/custom (i.e. application custom mode) mode is designed to be specified by the local configuration attribute queryconfigugtype of the database application system.
Aiming at a configuration file mode, a file path name is specified through a local configuration attribute of a database application system, and the local file, the network system file and the distributed system file are supported, wherein the local configuration attribute is as follows: dbConfigFilePath: JSON, the content of the configuration file completely conforms to the JSON format of the data source configuration information designed above. The configuration information inquiry and monitoring service of the embodiment of the invention regularly scans the content change of the configuration file to realize the monitoring of the configuration information of the data source.
Aiming at the remote configuration center mode, a Restful WebService protocol is selected for the design of the configuration information query interface, and the return value is the JSON format designed in the above. The remote configuration center configuration information query interface URL (uniform resource locator) may be configured by the database application system via a local configuration attribute remoteConfigURL, such as remoteConfigURL: port/queryConfigappCode ═ specified application. The data source configuration information change monitoring supports two modes: firstly, data source configuration information change notification and monitoring based on MQ (message queue); and the other is data source configuration information change notification and monitoring based on ZooKeeper (a distributed application program coordination service with distributed and open source codes) coordination service. Specifically, the local configuration attribute remoteConfigListeningMode of the database application system may be adopted: MQ/ZooKeeper. The remote configuration center is responsible for pushing the data source configuration information change to the MQ/ZooKeeper, and the configuration information query and monitoring service is responsible for monitoring the data source configuration information change of the specified database application system in the MQ/ZooKeeper and carrying out corresponding matrix data source initialization and dynamic update processing.
Aiming at an application self-defining mode, two interface program methods are designed: the first interface method (namely the first interface method) is used for inquiring configuration information, and the returned value is in the JSON format designed above; interface method two (i.e., the second interface method above) listens for configuration changes. The database application system needs to realize two interface methods of the interface, and indicates how to acquire and monitor the change of the multi-service multi-tenant data source configuration information.
When the database application system is started, the initialization method initializedmatrix source () of the embodiment of the present invention is called to perform initial configuration information query and start of the monitoring service. And the unique identifier of the database application system in the unified configuration and management center is indicated by a local configuration attribute systemmapplication code.
No matter which configuration information query and monitoring mode is selected by the database application system, the configuration information query and monitoring service directly calls the dynamic initialization service of the matrix data source when querying the initial multi-service multi-tenant data source configuration information and monitoring and receiving the change of the data source configuration information, the data source configuration information is pushed to the past, and the initialization processing of the multi-service multi-tenant matrix data source of the database application system is uniformly carried out.
The matrix data source dynamic initialization service includes a data source initialization service (initializeDatasource ()) and a data source update service (updateDatasource ()). The data source initialization service is used for initializing the matrix data source according to the data source configuration information, and comprises the steps of initializing a total dynamic data source, a plurality of service dynamic data sources and a plurality of specific data sources, and initializing a database connection pool for each specific data source. And the data source updating service is used for dynamically updating the whole matrix data source according to the monitored data source configuration change information. The matrix data source dynamic initialization service is described in detail below.
The embodiment of the invention designs a matrix data source logic structure to realize the two services of initializedadatasource () and updateDatasource (). The matrix data source refers to a dynamic data source described from two dimensions of business and tenants, and the logical structure of the matrix data source comprises the following components: a global dynamic data source, multiple service-level dynamic data sources (e.g., service a dynamic data source-service M dynamic data source in fig. 2), and several specific data sources (e.g., service a tenant 1 data source, service a tenant 2 data source in fig. 2, etc.). The overall dynamic data source is named matrixDataSource; the multiple service dynamic data sources correspond to the configuration information of the multiple service data sources, namely, a service dynamic data source is initialized for the configuration information of each service data source, and the naming rule is that a service direction keyword is connected with a dynamic data source; the specific data sources are configured to initialize one specific data source for each service data source of each tenant, if M service directions and N tenants exist, M × N specific data sources need to be initialized, and the naming rule of the specific data sources is as follows: { tenant identity } # { traffic direction key } # database. And initializing each specific data source according to the database type, the data source type, the connection parameter and the connection pool configuration parameter information configured for the specific data source.
The data source initialization service receives JSON structure data conforming to the data source configuration information format, creates an overall dynamic data source instance, a plurality of service-level dynamic data source instances and a plurality of specific data source instances according to the matrix data source logical structure and the naming specification thereof designed above, and initializes a database connection pool instance (for example, a service a tenant 1 database connection pool in fig. 2) for each specific data source. And meanwhile, setting the total dynamic data sources as system default data sources, and transmitting the corresponding relation between the names of the data sources and the initialized data source examples to the matrix data source dynamic routing service.
The data source updating service receives JSON structure data which accords with a data source configuration information format and represents changed data source configuration information (including complete configuration information of newly added, modified and deleted data sources and no configuration information of unchanged data sources), newly adds, modifies and deletes corresponding business dynamic data source examples according to the matrix data source logic structure and the naming specification thereof, newly adds, modifies and deletes corresponding specific data source examples and database connection pool information thereof, and transmits the corresponding relation between the names of the updated data sources and the initialized data source examples to the matrix data source dynamic routing service. It should be noted that, the data source update service updates (adds, modifies, and deletes) the above-mentioned instance, i.e., destroys the old original instance and creates a new instance again (i.e., re-initializes).
And the matrix data source dynamic routing service automatically switches the system data source to the corresponding service data source of the corresponding tenant according to the context tenant and the currently accessed service direction. The matrix data source dynamic routing service specifically includes a matrix data source routing service and a service dynamic data source routing service. The matrix data source routing service can automatically switch the access request to a specific data source of a corresponding tenant and a corresponding service according to the context tenant information and the currently accessed service direction information, and the service dynamic data source routing service can automatically switch the access request to a specific data source of a corresponding tenant under the service dynamic data source located by the database application system according to the context tenant information.
The matrix data source dynamic routing service also provides two sub-services, respectively for: and acquiring the context tenant and the current accessed service direction. Context tenant information and currently accessed business direction information can be obtained from a process environment during the runtime of a database application system. According to the logic structure of the matrix data source and the naming specification thereof, the specific data source name corresponding to the context tenant and the current accessed business direction is calculated, then the specific data source example which should be used currently is determined according to the data source name transmitted by the dynamic initialization service of the matrix data source and the corresponding relation of the example, and the specific data source example is returned to the corresponding database connection pool, so that the automatic routing service of the data source corresponding to the business direction corresponding to the corresponding tenant can be realized. The details of obtaining the context tenant and obtaining the current visited traffic direction are described below.
The embodiment of the invention designs two ways to obtain the context tenant information (context tenant identification value): the method comprises the steps that firstly, the data are transmitted through a system attribute _ ContextTenantId, a database application system sets a context tenant identification value into the system attribute before using a data source, and a matrix data source dynamic routing service is responsible for dynamically reading the value from the system attribute; and secondly, the method is transferred through the thread-level static method setContextTenantId (), specifically, a database application system is responsible for calling the method to transfer the context tenant identification value, and a matrix data source dynamic routing service is responsible for reading the value and immediately clearing the value after the value is used in the current thread. The database application system can select one of the two ways to transfer the context tenant information according to the requirement. As a preferred embodiment, the second manner, namely, the context tenant identification value passed through the thread-level static method setcontexttenninid () (i.e., the second thread-level static method above) may be preferentially used, and if not obtained through the second manner, the context tenant identification value is obtained through the first manner, namely, reading the system attribute _ contexttenninid.
The embodiment of the invention designs three modes to obtain the current accessed service direction, and the database application system can freely select one or more modes according to the self service scene. Among the three methods, the first method: and appointing all the services in a certain group of service classes or a certain program package to uniformly use a certain business dynamic data source through a local configuration file by the database application system, wherein the appointed business dynamic data source complies with the naming specification of the matrix data source. For example, a fixed asset (business direction is fixedessets) package of a financial system has all services uniformly configured using fixedesss dynamic data source. The second method comprises the following steps: the embodiment of the invention provides an annotation mark @ DataSource, a database application system declares a business direction (A (only an example)) corresponding to a service through the annotation mark @ DataSource ("business direction A") on a persistence service class, and a matrix data source dynamic routing service runtime tries to read the annotation mark on the persistence service class currently accessed by the database application system to determine the currently accessed business direction. The third method comprises the following steps: the embodiment of the invention provides a thread-level static method setCurrentBusinessKey () (namely, the first thread-level static method) for a database application system to transmit a currently accessed service direction, the database application system is responsible for calling the method to transmit a currently accessed service direction value, and a matrix data source dynamic routing service is responsible for reading the value and immediately clearing the value after being used in a current thread.
Among the three modes of obtaining the currently accessed service direction, the first mode and the second mode are commonly used for a database application system with relatively fixed service direction quantity and name; the third method is often used in a database application system with a variable service direction, and the database application system calculates the current service direction according to the service logic and then transmits the current service direction to the matrix data source dynamic routing service for dynamic routing of the data source, for example, performing service library-based routing by using the service key remainder operation result value as the service direction. The embodiment of the invention preferentially adopts a third mode to obtain the current accessed service direction, if not, the current accessed service direction is obtained according to a second mode, and if not, the current accessed service direction is obtained by the first mode.
From the functional division, the matrix data source dynamic routing service comprises a matrix data source routing service and a service dynamic data source routing service. The matrix data source routing service sets a total dynamic data source as a system default data source, when a database application system accesses the matrix data source, the matrix data source routing service calculates a corresponding specific data source name according to acquired context tenant information and currently accessed service direction information and according to a matrix data source naming specification, determines a specific data source example which should be used currently according to the data source name transmitted by the matrix data source dynamic initialization service and a corresponding relation of the example, and returns to a corresponding database connection pool to realize automatic routing of the specific data source. The service dynamic data source routing service is used for a scene that a database application system configures a specified service dynamic data source for a certain program package, after the database application system configures the specified service dynamic data source for the certain program package (the current accessed service direction is the service direction corresponding to the specified service dynamic data source), when the database application system accesses the service dynamic data source during operation, the service dynamic data source routing service calculates the specific data source name corresponding to the tenant under the service dynamic data source according to the acquired context tenant information and the matrix data source naming specification, then determines the specific data source example which should be used currently according to the data source name and the corresponding relation of the example, and returns to the corresponding database connection pool, thereby realizing the automatic routing of the specific data source in the service.
When the matrix data source routing service or the dynamic traffic data source routing service is used for data source routing, the context tenant information can be acquired through any one of the above two manners of acquiring the context tenant information (preferably, the second manner). In the case of performing data source routing through the matrix data source routing service, a currently accessed service direction is acquired by using a second or third of the three manners of acquiring the currently accessed service direction (preferred manner three), and in the case of performing data source routing through the service for.
The embodiment of the invention supports configuring, initializing and automatically routing a data source from two dimensions of a tenant and a service to form a matrix type data source routing service, and supports declaring the service direction of the matrix type data source routing service on a database application system persistence service class in an annotation identification mode to form an declared type data source routing service.
Fig. 3 is a schematic diagram of main blocks of a data source routing apparatus according to an embodiment of the present invention.
As shown in fig. 3, a data source routing apparatus 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.
A data source initialization module 301, configured to: initializing a matrix data source according to data source configuration information, wherein the matrix data source comprises: initializing a total dynamic data source, a plurality of service dynamic data sources corresponding to the total dynamic data source and a plurality of specific data sources corresponding to each service dynamic data source, wherein the total dynamic data source, the service dynamic data sources and the specific data sources are named according to naming specifications of matrix data sources respectively; respectively creating a total dynamic data source instance, each service dynamic data source instance and each specific data source instance, initializing a database connection pool instance for each specific data source, wherein the names of the total dynamic data source, each service dynamic data source and each specific data source respectively have a corresponding relation with the respective instance.
An access request receiving module 302, configured to receive an access request of a database application system to a matrix data source, where the matrix data source includes a total dynamic data source, a service dynamic data source, and a specific data source, where one total data source corresponds to multiple service dynamic data sources, and each service dynamic data source corresponds to multiple specific data sources. Each service dynamic data source corresponds to one service direction, and each specific data source corresponds to one tenant and one service direction.
The data source routing module 303 is configured to, when the database application system accesses the general dynamic data source, obtain tenant information of a current context and currently accessed service direction information of the database application system through a matrix data source routing service, and switch an access request to a specific data source corresponding to the tenant of the current context and the currently accessed service direction in the general dynamic data source; under the condition that the database application system accesses one target service dynamic data source in a plurality of service dynamic data sources, the tenant information of the current context of the database application system is obtained through the service 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 service dynamic data source.
The data source routing apparatus 300 may further include a data source updating module, configured to dynamically update the initialized matrix data source according to the change of the data source configuration information, where the content of the dynamic update includes: and updating the corresponding business dynamic data source example according to the change of the data source configuration information, and updating the corresponding specific data source example and the database connection pool information thereof.
The data source routing apparatus 300 may further include a configuration information query and listening module: the data source configuration information acquisition and monitoring service is used for acquiring the data source configuration information and monitoring the change of the data source configuration information through the configuration information query and monitoring service, wherein the data source configuration information acquisition and monitoring mode is one of the following three modes: the first method is as follows: acquiring data source configuration information from a configuration file under a file path name specified by a database application system, and monitoring the change of the data source configuration information by scanning the configuration file at regular time; the second method comprises the following steps: acquiring data source configuration information from a remote configuration center according to a configuration information query interface configured by a database application system, and monitoring data source configuration information change pushed to a message queue or distributed service by the remote configuration center; the third method comprises the following steps: the method comprises the steps of utilizing a first interface method and a second interface method which are self-defined by a database application system to respectively acquire and monitor data source configuration information, wherein the first interface method is an interface method for inquiring the data source configuration information, and the second interface method is an interface method for monitoring the change of the data source configuration information.
The data source routing module 303 may specifically include a specific data source routing submodule configured to: calculating the name of a first target specific data source corresponding to the tenant of the current context and the currently accessed service direction under the overall dynamic data source according to the acquired tenant information of the current context and the currently accessed service direction information and the naming specification of the matrix data source; switching the access request to a specific data source corresponding to the first target specific data source name according to the corresponding relation between the specific data source name and the specific data source instance; or, according to the acquired tenant information of the current context, calculating a second target specific data source name corresponding to the tenant of the current context under the target service dynamic data source according to the naming specification of the matrix data source; and switching the access request to a specific data source corresponding to the second target specific data source name according to the corresponding relation between the specific data source name and the specific data source instance.
The naming convention for the matrix data source may be: the first character string, the second character string and the third character string are used for respectively representing a total dynamic data source, a service dynamic data source and a specific data source, the name of the total dynamic data source is the first character string, the name of each service dynamic data source is the combination of a service direction key word and the second character string which correspond to each other, and the name of each specific data source is the combination of a tenant identification, a service direction key word and the third character string which correspond to each other.
The target business dynamic data source can be a business dynamic data source positioned by the database application system through the specified business direction in the local configuration file; and acquiring the current accessed business direction according to the business direction declared by the database application system or the business direction value transmitted by the database application system, wherein the database application system declares the business direction through the annotation mark or transmits the business direction value through a first thread-level static method.
And acquiring the tenant information of the current context by reading the context tenant identification value set in the system attribute by the database application system or by reading the context tenant identification value transmitted by the database application system by calling a second thread-level static method.
The data source routing device of the embodiment of the invention can be realized into an independent application component with a perfect standard and standardized interface, and the component is independent of the database application system and runs in the same operating system process with the database application system. For example as a Jar (Java ARchive) package in the Java language, or as a DLL (dynamic link library file) in the C # language. The configuration information of the multi-service multi-tenant data source supports local file configuration, interaction with an external unified configuration and management center is also supported, and meanwhile, custom configuration inquiry and monitoring of a database application system are supported. And how the current context tenant of the database application system is transferred to the multi-service multi-tenant matrix data source routing device, and how the database application system specifies the corresponding data source during specific service module development and system configuration, the data source routing device is required to uniformly perform standard agreement, and a standardized service interface is formulated. Under the guidance of the convention of relevant specifications, the data source routing device starts with three services of the configuration information inquiry and monitoring, the matrix data source dynamic initialization and the matrix data source dynamic routing, and is respectively grounded. The embodiment of the invention can solve the problems of multi-tenant and multi-service data source dynamic configuration and automatic route switching in a complex database application system.
In addition, in the embodiment of the present invention, the detailed implementation content of the data source routing apparatus has been described in detail in the above data source routing method, so that repeated content herein is not described again.
Fig. 4 illustrates an exemplary system architecture 400 of a data source routing method or data source routing apparatus to which embodiments of the present invention may be applied.
As shown in fig. 4, the system architecture 400 may include terminal devices 401, 402, 403, a network 404, and a server 405. The network 404 serves as a medium for providing communication links between the terminal devices 401, 402, 403 and the server 405. Network 404 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use terminal devices 401, 402, 403 to interact with a server 405 over a network 404 to receive or send messages or the like. The terminal devices 401, 402, 403 may have installed thereon various communication client applications, such as shopping-like applications, web browser applications, search-like applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only).
The terminal devices 401, 402, 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 405 may be a server providing various services, such as a background management server (for example only) providing support for shopping websites browsed by users using the terminal devices 401, 402, 403. The backend management server may analyze and perform other processing on the received data such as the product information query request, and feed back a processing result (for example, target push information, product information — just an example) to the terminal device.
It should be noted that the data source routing method provided by the embodiment of the present invention is generally executed by the server 405, and accordingly, the data source routing apparatus is generally disposed in the server 405.
It should be understood that the number of terminal devices, networks, and servers in fig. 4 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 5, a block diagram of a computer system 500 suitable for use in implementing a terminal device or server of an embodiment of the present application is shown. The terminal device or the server shown in fig. 5 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present application.
As shown in fig. 5, the computer system 500 includes a Central Processing Unit (CPU)501 that 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 section 508 into a Random Access Memory (RAM) 503. In the RAM 503, various programs and data necessary for the operation of the system 500 are also stored. The CPU 501, ROM 502, and RAM 503 are connected to each other via a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
The following components are connected to the I/O interface 505: an input portion 506 including a keyboard, a mouse, and the like; an output portion 507 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 508 including a hard disk and the like; and a communication section 509 including a network interface card such as a LAN card, a modem, or the like. The communication section 509 performs communication processing via a network such as the internet. The driver 510 is also connected to the I/O interface 505 as necessary. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as necessary, so that a computer program read out therefrom is mounted into the storage section 508 as necessary.
In particular, according to embodiments of the present disclosure, the processes described above with reference to the main step schematic may be implemented as computer software programs. For example, the disclosed embodiments of the invention include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method shown in the main step diagram. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 509, and/or installed from the removable medium 511. The above-described functions defined in the system of the present application are executed when the computer program is executed by the Central Processing Unit (CPU) 501.
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 two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present application, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In this application, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The principal step diagrams and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the main step diagrams or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or block diagrams, and combinations of blocks in the block diagrams or block diagrams, can be implemented by special purpose hardware-based systems that perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes an access request receiving module, a data source routing module. The names of these modules do not constitute a limitation on the modules themselves in some cases, for example, the access request receiving module may also be described as a "module for receiving an access request of a database application system to a matrix data source".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: receiving an access request of a database application system to a matrix data source, wherein the matrix data source comprises a total dynamic data source, a service dynamic data source and a specific data source, one total data source corresponds to a plurality of service dynamic data sources, and each service dynamic data source corresponds to a plurality of specific data sources; under the condition that the database application system accesses the overall dynamic data source, acquiring tenant information of the current context and currently accessed service direction information of the database application system 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 currently accessed service direction under the overall dynamic data source; and under the condition that the database application system accesses one target business dynamic data source in the plurality of business dynamic data sources, acquiring 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.
According to the technical scheme of the embodiment of the invention, an access request of a database application system to a matrix data source is received, wherein the matrix data source comprises a total dynamic data source, a business dynamic data source and a specific data source; under the condition that the database application system accesses the overall dynamic data source, acquiring tenant information of the current context and currently accessed service direction information of the database application system through a matrix data source routing service, and switching an access request to a specific data source corresponding to the tenant of the current context and the currently accessed service direction under the overall dynamic data source; under the condition that the database application system accesses one target service dynamic data source in a plurality of service dynamic data sources, the tenant information of the current context of the database application system is obtained through the service 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 service dynamic data source. The problem of multi-tenant and multi-service data source routing switching can be solved simultaneously. The embodiment of the invention can be decomposed into three field services of configuration information inquiry and monitoring, matrix data source dynamic initialization and matrix data source dynamic routing (specifically realized by matrix data source routing service and business dynamic data source routing service), each field service supports multiple application access modes to interact with a database application system, and the data source routing device of the embodiment of the invention can be realized as an independent matrix data source routing device application component, thereby realizing code decoupling with the database application system and enhancing reusability of a solution.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (18)

1. A data source routing method, comprising:
receiving an access request of a database application system to a matrix data source, wherein the matrix data source comprises a total dynamic data source, a service dynamic data source and a specific data source, one total data source corresponds to a plurality of service dynamic data sources, and each service dynamic data source corresponds to a plurality of specific data sources;
under the condition that the database application system accesses the overall dynamic data source, acquiring tenant information of the current context and currently accessed service direction information of the database application system 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 currently accessed service direction under the overall dynamic data source;
and under the condition that the database application system accesses one target business dynamic data source in the plurality of business dynamic data sources, acquiring 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.
2. The method of claim 1, wherein the step of receiving a request for access to the matrix data source from a database application system is preceded by the steps of:
initializing the matrix data source according to data source configuration information, wherein the matrix data source comprises: initializing the total dynamic data source, a plurality of service dynamic data sources corresponding to the total dynamic data source and a plurality of specific data sources corresponding to each service dynamic data source, wherein the total dynamic data source, the service dynamic data sources and the specific data sources are named according to the naming specifications of the matrix data sources respectively;
respectively creating a total dynamic data source instance, each service dynamic data source instance and each specific data source instance, initializing a database connection pool instance for each specific data source, wherein the names of the total dynamic data source, each service dynamic data source and each specific data source respectively have a corresponding relation with the respective instance.
3. The method according to claim 2, wherein the initialized matrix data source is dynamically updated with the change of the data source configuration information, and the content of the dynamic update comprises: and updating the corresponding business dynamic data source example according to the change of the data source configuration information, and updating the corresponding specific data source example and the database connection pool information thereof.
4. The method of claim 3, further comprising: acquiring the data source configuration information and monitoring the change of the data source configuration information through a configuration information query and monitoring service, wherein the acquisition and monitoring mode of the data source configuration information is one of the following three modes:
the first method is as follows: acquiring the data source configuration information from a configuration file under a file path name specified by the database application system, and regularly scanning the configuration file to monitor the change of the data source configuration information;
the second method comprises the following steps: acquiring 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 the data source configuration information change pushed to a message queue or distributed service by the remote configuration center;
the third method comprises the following steps: and respectively acquiring and monitoring the data source configuration information by utilizing a first interface method and a second interface method which are self-defined by the database application system, wherein the first interface method is an interface method for inquiring the data source configuration information, and the second interface method is an interface method for monitoring the change of the data source configuration information.
5. The method according to claim 1, wherein the step of switching the access request to a specific data source corresponding to the tenant of the current context and the currently accessed business direction under the overall dynamic data source comprises:
according to the acquired tenant information of the current context and the current accessed service direction information, and according to the naming specification of the matrix data source, calculating a first target specific data source name corresponding to the tenant of the current context and the current accessed service direction under the overall dynamic data source;
switching the access request to a specific data source corresponding to the first target specific data source name according to the corresponding relation between the specific data source name and the specific data source instance;
the step of switching the access request to a specific data source corresponding to the tenant of the current context under the target service dynamic data source includes:
calculating a second target specific data source name corresponding to the tenant of the current context under the target service dynamic data source according to the acquired tenant information of the current context and the naming specification of the matrix data source;
and switching the access request to a specific data source corresponding to the second target specific data source name according to the corresponding relation between the specific data source name and the specific data source instance.
6. The method according to claim 2 or 5, wherein each dynamic data source of the service corresponds to one service direction, and each specific data source corresponds to one tenant and one service direction;
the naming specification of the matrix data source is as follows:
and respectively representing the overall dynamic data source, the service dynamic data source and the specific data source by using a first character string, a second character string and a third character string, wherein the name of the overall dynamic data source is the first character string, the name of each service dynamic data source is a combination of a service direction keyword and the second character string which correspond to each other, and the name of each specific data source is a combination of a tenant identification, a service direction keyword and the third character string which correspond to each other.
7. The method of claim 1, wherein the target business dynamic data source is a business dynamic data source located by the database application system through a business direction specified in its local configuration file;
and acquiring the current accessed business direction according to the business direction declared by the database application system or the business direction value transmitted by the database application system, wherein the database application system declares the business direction through annotation identification or transmits the business direction value through a first thread-level static method.
8. The method according to claim 1, wherein the tenant information of the current context is obtained by reading a context tenant identification value set in a system attribute by the database application system, or by reading a context tenant identification value transmitted by the database application system by calling a second thread-level static method.
9. A data source routing apparatus, comprising:
the access request receiving module is used for receiving an access request of a database application system to a matrix data source, wherein the matrix data source comprises a total dynamic data source, a service dynamic data source and a specific data source, one total data source corresponds to a plurality of service dynamic data sources, and each service dynamic data source corresponds to a plurality of specific data sources;
a data source routing module, configured to, when the database application system accesses the overall dynamic data source, obtain, through a matrix data source routing service, tenant information of a current context of the database application system and currently accessed service direction information, and switch the access request to a specific data source corresponding to the tenant of the current context and the currently accessed service direction under the overall dynamic data source;
and under the condition that the database application system accesses one target business dynamic data source in the plurality of business dynamic data sources, acquiring 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.
10. The apparatus of claim 9, further comprising a data source initialization module to:
initializing the matrix data source according to data source configuration information, wherein the matrix data source comprises: initializing the total dynamic data source, a plurality of service dynamic data sources corresponding to the total dynamic data source and a plurality of specific data sources corresponding to each service dynamic data source, wherein the total dynamic data source, the service dynamic data sources and the specific data sources are named according to the naming specifications of the matrix data sources respectively;
respectively creating a total dynamic data source instance, each service dynamic data source instance and each specific data source instance, initializing a database connection pool instance for each specific data source, wherein the names of the total dynamic data source, each service dynamic data source and each specific data source respectively have a corresponding relation with the respective instance.
11. The apparatus of claim 10, further comprising a data source updating module, configured to dynamically update the initialized matrix data source according to the change of the data source configuration information, where the content of the dynamic update includes: and updating the corresponding business dynamic data source example according to the change of the data source configuration information, and updating the corresponding specific data source example and the database connection pool information thereof.
12. The apparatus of claim 11, further comprising a configuration information query and listening module: the data source configuration information acquisition and monitoring service is used for acquiring the data source configuration information and monitoring the change of the data source configuration information through the configuration information query and monitoring service, wherein the acquisition and monitoring mode of the data source configuration information is one of the following three modes:
the first method is as follows: acquiring the data source configuration information from a configuration file under a file path name specified by the database application system, and regularly scanning the configuration file to monitor the change of the data source configuration information;
the second method comprises the following steps: acquiring 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 the data source configuration information change pushed to a message queue or distributed service by the remote configuration center;
the third method comprises the following steps: and respectively acquiring and monitoring the data source configuration information by utilizing a first interface method and a second interface method which are self-defined by the database application system, wherein the first interface method is an interface method for inquiring the data source configuration information, and the second interface method is an interface method for monitoring the change of the data source configuration information.
13. The apparatus of claim 9, wherein the data source routing module comprises a data source-specific routing sub-module configured to:
according to the acquired tenant information of the current context and the current accessed service direction information, and according to the naming specification of the matrix data source, calculating a first target specific data source name corresponding to the tenant of the current context and the current accessed service direction under the overall dynamic data source;
switching the access request to a specific data source corresponding to the first target specific data source name according to the corresponding relation between the specific data source name and the specific data source instance;
alternatively, the first and second electrodes may be,
calculating a second target specific data source name corresponding to the tenant of the current context under the target service dynamic data source according to the acquired tenant information of the current context and the naming specification of the matrix data source;
and switching the access request to a specific data source corresponding to the second target specific data source name according to the corresponding relation between the specific data source name and the specific data source instance.
14. The apparatus according to claim 10 or 13, wherein each dynamic data source of the service corresponds to one service direction, and each specific data source corresponds to one tenant and one service direction;
the naming specification of the matrix data source is as follows:
and respectively representing the overall dynamic data source, the service dynamic data source and the specific data source by using a first character string, a second character string and a third character string, wherein the name of the overall dynamic data source is the first character string, the name of each service dynamic data source is a combination of a service direction keyword and the second character string which correspond to each other, and the name of each specific data source is a combination of a tenant identification, a service direction keyword and the third character string which correspond to each other.
15. The apparatus of claim 9, wherein the target business dynamic data source is a business dynamic data source located by the database application system through a business direction specified in its local configuration file;
and acquiring the current accessed business direction according to the business direction declared by the database application system or the business direction value transmitted by the database application system, wherein the database application system declares the business direction through annotation identification or transmits the business direction value through a first thread-level static method.
16. The apparatus according to claim 9, wherein the tenant information of the current context is obtained by reading a context tenant identification value set in a system attribute by the database application system, or by reading a context tenant identification value transferred by the database application system by calling a second thread-level static method.
17. An electronic device, comprising:
one or more processors;
a memory for storing one or more programs,
the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the method of any of claims 1-8.
18. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-8.
CN201910695657.7A 2019-07-30 2019-07-30 Data source routing method and device Pending CN112306984A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910695657.7A CN112306984A (en) 2019-07-30 2019-07-30 Data source routing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910695657.7A CN112306984A (en) 2019-07-30 2019-07-30 Data source routing method and device

Publications (1)

Publication Number Publication Date
CN112306984A true CN112306984A (en) 2021-02-02

Family

ID=74485110

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910695657.7A Pending CN112306984A (en) 2019-07-30 2019-07-30 Data source routing method and device

Country Status (1)

Country Link
CN (1) CN112306984A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113138870A (en) * 2021-05-12 2021-07-20 中国工商银行股份有限公司 Service invocation method, device, system, medium and product in distributed computing

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113138870A (en) * 2021-05-12 2021-07-20 中国工商银行股份有限公司 Service invocation method, device, system, medium and product in distributed computing

Similar Documents

Publication Publication Date Title
CN107491382B (en) Log output method and device
CN110830374B (en) Method and device for gray level release based on SDK
CN110471848B (en) Method and device for dynamically returning message
CN113495921A (en) Routing method and device of database cluster
CN111427701A (en) Workflow engine system and business processing method
CN111478781B (en) Message broadcasting method and device
CN110851468A (en) Method and device for making simulation response to test request of client
CN112835904A (en) Data processing method and data processing device
CN112306984A (en) Data source routing method and device
CN109981546B (en) Method and device for acquiring remote call relation between application modules
CN112948138A (en) Method and device for processing message
CN110764769A (en) Method and device for processing user request
CN111382953A (en) Dynamic process generation method and device
CN113779018A (en) Data processing method and device
CN113556370A (en) Service calling method and device
CN113536748A (en) Method and device for generating chart data
CN112099841A (en) Method and system for generating configuration file
CN108696549B (en) Load balancing method, device and system
CN113760487A (en) Service processing method and device
CN111984616A (en) Method, device and system for updating shared file
CN112559001A (en) Method and device for updating application
CN113495747B (en) Gray scale release method and device
CN113765868B (en) Service processing method and device
CN113760886B (en) Method, apparatus, device and computer readable medium for providing data service
CN113448652A (en) Request processing method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination