A micro-service-based multi-data-source link management method and system
By using the microservice registry center and multi-data source connection pool components for dynamic management, the problem of dynamic switching of multiple data sources in microservice systems is solved, and dynamic management of data source numbers and connection information is realized, thereby improving the flexibility and efficiency of the system.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- STATE GRID INFORMATION & TELECOMM GRP CO LTD
- Filing Date
- 2022-06-27
- Publication Date
- 2026-07-21
AI Technical Summary
In existing technologies, microservice systems struggle to dynamically switch between multiple data sources and dynamically manipulate data sources when front-end data changes. In particular, the data source type is fixed after system startup, which cannot meet the front-end's need for dynamic connections to multiple types of databases.
By registering data source information and configuring microservices through a microservice registry, and dynamically selecting data sources using a multi-data source connection pool component and a soft load balancing algorithm, combined with a preset multi-data source storage database and national cryptographic algorithm encryption, dynamic management of data source numbers and connection information and creation and updating of database connection pools are achieved.
It enables dynamic connection and management of multiple data sources. The front end can dynamically obtain connections to different data sources through the data source number, realizing the separation of data source information from user access and use, and improving the system's flexibility and efficiency.
Smart Images

Figure CN116340015B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of microservices technology, and in particular to a method and system for managing multiple data source links based on microservices. Background Technology
[0002] With the development of technology, the reusability of the front-end interface has become the key to reducing development costs. These reusable front-end components need to connect to different databases when implemented in different systems. When the data required by the front end changes, the back-end service is required to support dynamic switching of multiple types of databases as data sources.
[0003] In existing technologies, data source connections are implemented based on JPA or MyBatis frameworks. These connection methods are generally for single data source connections, or even for multiple data source connections, the data source type is fixed after system startup, making it difficult to dynamically manipulate the data source when the data required by the front end changes. Summary of the Invention
[0004] To address the aforementioned shortcomings of existing technologies, this invention provides a microservice-based multi-data source link management and system to solve the aforementioned technical problems.
[0005] Firstly, this application provides a microservice-based multi-data source connection management method, characterized by the following steps: registering several data source information configuration management microservices through a microservice registry center to obtain a list of data source information configuration management microservice addresses; when a multi-data source connection pool component receives a data source invocation instruction, determining the data source number corresponding to the data source invocation instruction through the multi-data source connection pool component, and obtaining the list of data source information configuration management microservice addresses from the microservice registry center; based on a soft load balancing algorithm, determining the actual data source information configuration management microservice being invoked from the list of data source information configuration management microservice addresses through the multi-data source connection pool component, and subscribing to the actual invoked data source information configuration management microservice; and through... The multi-data source connection pool component sends a database query command containing the data source ID to the microservice that actually calls the data source information configuration management system to obtain the data source connection information corresponding to the data source ID from the microservice. Based on the connection information, the multi-data source connection pool component creates a database connection pool; it stores the database connection pool and the mapping relationship between the database connection pool and the data source ID; when the multi-data source connection pool component receives a data source modification or deletion message pushed by the microservice that actually calls the data source information configuration management system, it determines the data source ID corresponding to the data source modification or deletion message; based on the mapping relationship, it closes and deletes the database connection pool corresponding to the data source ID.
[0006] Furthermore, when the microservice registry receives updated data source connection information, it updates the database connection pool of the multi-data source connection pool component through the microservice registry based on the long connection.
[0007] Furthermore, a pre-defined multi-data source storage database is used to store data source numbers, data source link information, and the correspondence between data source numbers and data source link information. The data source link information corresponding to the data source number is obtained from the data source information configuration management microservice that is actually called. Specifically, the pre-defined multi-data source storage database is called through the data source information configuration management microservice that is actually called, thereby obtaining the data source link information corresponding to the data source number.
[0008] Furthermore, the data source number is unique and corresponds one-to-one with the database ID of the database corresponding to the data source link information; the data source information stored in the database is transmitted and stored using a preset national cryptographic algorithm.
[0009] Furthermore, before determining the data source number corresponding to the data source modification or deletion message, the method also includes: detecting the data source modification or deletion operation performed by the front-end interface through the data source information configuration management microservice to generate a data source modification or deletion message; and then sending the data source modification or deletion message to the multi-data source connection pool component by calling the message middleware.
[0010] Secondly, this application provides a microservice-based multi-data source connection management system. The system includes: an acquisition module, used to register several data source information configuration management microservices through a microservice registry center and obtain a list of data source information configuration management microservice addresses; an acquisition module, used to determine the data source number corresponding to the data source call instruction through the multi-data source connection pool component when the multi-data source connection pool component receives a data source call instruction, and obtain the list of data source information configuration management microservice addresses from the microservice registry center; and a subscription module, used to determine the actually invoked data source information configuration management microservice from the list of data source information configuration management microservice addresses through the multi-data source connection pool component based on a soft load balancing algorithm, and subscribe to the actually invoked data source information configuration management microservice. It is also used to send a database query command containing the data source number to the microservice for configuring and managing the data source information that is actually called, through the multi-data source connection pool component, so as to obtain the data source connection information corresponding to the data source number from the microservice for configuring and managing the data source information that is actually called; the storage module is used to create a database connection pool based on the connection information through the multi-data source connection pool component; store the database connection pool and the mapping relationship between the database connection pool and the data source number; the close and delete module is used to determine the data source number corresponding to the data source modification or deletion message pushed by the microservice for configuring and managing the data source information when the multi-data source connection pool component receives the data source modification or deletion message pushed by the microservice for configuring and managing the data source information; and close and delete the database connection pool corresponding to the data source number based on the mapping relationship.
[0011] Furthermore, the system also includes an update module, which, when the microservice registry receives updated data source connection information, updates the updated connection information to the database connection pool of the multi-data source connection pool component via a long connection.
[0012] Furthermore, the close / delete module also includes a sending unit; the sending unit is used to detect data source modification or deletion operations performed by the front-end interface through the data source information configuration management microservice to generate data source modification or deletion messages; and then send the data source modification or deletion messages to the multi-data source connection pool component by calling the message middleware.
[0013] Those skilled in the art will understand that the present invention has at least the following beneficial effects:
[0014] A multi-data source connection pool component provides the creation and storage of database connection pools for various data sources. Users can select the data source to access by obtaining dynamic parameters (different data source IDs) to perform operations such as calling different data sources, without needing to specify the specific information of the data source beforehand. Different data source connections can be dynamically obtained by passing the data source ID to the front end. A message middleware handles the updating of the stored database connection pool, separating the maintenance of data source information from the user's acquisition and use of data source connections, thus enabling dynamic connections. Attached Figure Description
[0015] The following description refers to some embodiments of this disclosure, in which:
[0016] Figure 1 This is a flowchart of a multi-data source link management method based on microservices provided in an embodiment of this application.
[0017] Figure 2 This is a schematic diagram of the internal structure of a microservice-based multi-data source link management system provided in an embodiment of this application. Detailed Implementation
[0018] Those skilled in the art should understand that the embodiments described below are merely preferred embodiments of this disclosure and do not imply that this disclosure can only be implemented through these preferred embodiments. These preferred embodiments are merely used to explain the technical principles of this disclosure and are not intended to limit the scope of protection of this disclosure. Based on the preferred embodiments provided by this disclosure, all other embodiments obtained by those skilled in the art without creative effort should still fall within the scope of protection of this disclosure.
[0019] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0020] The technical solutions proposed in the embodiments of this application will be described in detail below with reference to the accompanying drawings.
[0021] This application also provides a method for managing multiple data source connections based on microservices, such as... Figure 2 As shown in the embodiments of this application, the method mainly includes the following steps:
[0022] Step 110: Register several data source information configuration management microservices through the microservice registry center to obtain a list of data source information configuration management microservice addresses.
[0023] It should be noted that the list of microservice addresses for data source information configuration management stores the name of the microservice for data source information configuration management and its calling address.
[0024] Step 120: When the multi-data source connection pool component receives a data source call instruction, it determines the data source number corresponding to the data source call instruction through the multi-data source connection pool component, and obtains the data source information from the microservice registry center to configure and manage the microservice address list.
[0025] It should be noted that the multi-data source connection pool component can receive data source invocation instructions in the following ways: other business microservices using the component send data source invocation instructions to the multi-data source connection pool component.
[0026] Step 130: Based on the soft load balancing algorithm, determine the actual data source information configuration management microservice to be called from the list of microservice addresses of data source information configuration management through the multi-data source connection pool component, and subscribe to the actual data source information configuration management microservice to be called.
[0027] Step 140: Send a database query command containing the data source number to the data source information configuration management microservice that is actually called through the multi-data source connection pool component, so as to obtain the data source connection information corresponding to the data source number from the data source information configuration management microservice that is actually called.
[0028] It should be noted that the data source number is unique and corresponds one-to-one with the database ID of the database storing the data source link information; and multiple data source storage databases can be preset to store the data source number, data source link information, and the correspondence between the data source number and the data source link information; in addition, the data source information stored in the database can be transmitted and stored using preset national cryptographic algorithms.
[0029] Based on the above description, it can be understood that the step of "obtaining the data source link information corresponding to the data source number from the data source information configuration management microservice actually called" can be specifically as follows: by calling the preset multi-data source storage database through the data source information configuration management microservice actually called, the data source link information corresponding to the data source number can be obtained.
[0030] Step 150: Based on the link information, create a database connection pool using the multi-data source connection pool component; store the database connection pool and the mapping relationship between the database connection pool and the data source number.
[0031] It should be noted that connection pools can be created using DBCP (DataBase connection pool) technology, and ConcurrentHashMap can be used to store the database connection pools.
[0032] Furthermore, when the microservice registry receives updated data source connection information, this application can update the updated connection information to the database connection pool of the multi-data source connection pool component through the microservice registry based on a long connection.
[0033] Step 160: When the multi-data source connection pool component receives the data source modification or deletion message pushed by the actual data source information configuration management microservice, it determines the data source number corresponding to the data source modification or deletion message through the multi-data source connection pool component; based on the mapping relationship, it closes and deletes the database connection pool corresponding to the data source number.
[0034] In addition, before determining the data source number corresponding to the data source modification or deletion message, the method may also include: detecting the data source modification or deletion operation performed by the front-end interface through the data source information configuration management microservice to generate a data source modification or deletion message; and then sending the data source modification or deletion message to the multi-data source connection pool component by calling the message middleware.
[0035] In addition, embodiments of this application provide a microservice-based multi-data source connection management system. For example... Figure 1 As shown in the embodiments of this application, the system mainly includes:
[0036] Module 210 is used to register several data source information configuration management microservices through the microservice registry center and obtain a list of data source information configuration management microservice addresses.
[0037] The acquisition module 220 is used to determine the data source number corresponding to the data source invocation instruction through the multi-data source connection pool component when the multi-data source connection pool component receives the data source invocation instruction, and to obtain the data source information configuration management microservice address list from the microservice registry center.
[0038] The subscription module 230 is used to determine the actual data source information configuration management microservice to be called from the list of microservice addresses of data source information configuration management based on the soft load balancing algorithm and through the multi-data source connection pool component, and to subscribe to the actual data source information configuration management microservice to be called.
[0039] The acquisition module 240 is also used to send a database query instruction containing the data source number to the data source information configuration management microservice that is actually called through the multi-data source connection pool component, so as to obtain the data source connection information corresponding to the data source number from the data source information configuration management microservice that is actually called.
[0040] Storage module 250 is used to create database connection pools based on link information through a multi-data source connection pool component; store the database connection pools; and store the mapping relationship between the database connection pools and the data source numbers.
[0041] The 260 module is used to determine the data source number corresponding to the data source modification or deletion message pushed by the configuration management microservice when the multi-data source connection pool component receives the actual data source information modification or deletion message. Based on the mapping relationship, it closes and deletes the database connection pool corresponding to the data source number.
[0042] In addition, the shutdown / deletion module 260 can also send data source modification or deletion messages to the multi-data source connection pool component by calling the message middleware. Specifically, the sending unit 261 in the shutdown / deletion module 260 detects the data source modification or deletion operation performed by the front-end interface through the data source information configuration management microservice to generate a data source modification or deletion message; and then sends the data source modification or deletion message to the multi-data source connection pool component by calling the message middleware.
[0043] In addition, the system can update data source information. Specifically, the update module 270 is used to update the updated link information to the database connection pool of the multi-data source connection pool component through the microservice registry when the microservice registry receives the updated data source link information, based on a long connection.
[0044] The technical solutions of this disclosure have been described in conjunction with the preceding embodiments. However, it will be readily understood by those skilled in the art that the scope of protection of this disclosure is not limited to these specific embodiments. Without departing from the technical principles of this disclosure, those skilled in the art can disassemble and combine the technical solutions in the above embodiments, and can also make equivalent changes or substitutions to the relevant technical features. Any changes, equivalent substitutions, improvements, etc., made within the technical concept and / or technical principles of this disclosure will fall within the scope of protection of this disclosure.
Claims
1. A micro-service based multi-data source link management method, characterized in that, The method includes: Register several data source information configuration management microservices through the microservice registry center to obtain a list of data source information configuration management microservice addresses. When the multi-data source connection pool component receives a data source call instruction, it determines the data source number corresponding to the data source call instruction through the multi-data source connection pool component, and obtains the data source information from the microservice registry center to configure and manage the microservice address list. Based on a soft load balancing algorithm, the actual data source information configuration management microservice to be called is determined from the list of addresses of the data source information configuration management microservice through a multi-data source connection pool component, and the actual data source information configuration management microservice to be called is subscribed to. The multi-data source connection pool component sends a database query instruction containing the data source number to the data source information configuration management microservice that is actually called, so as to obtain the data source connection information corresponding to the data source number from the data source information configuration management microservice that is actually called; based on the connection information, a database connection pool is created through the multi-data source connection pool component; the database connection pool is stored, and the mapping relationship between the database connection pool and the data source number is stored. When the multi-data source connection pool component receives the data source modification or deletion message pushed by the data source information configuration management microservice, it determines the data source number corresponding to the data source modification or deletion message; based on the mapping relationship, it closes and deletes the database connection pool corresponding to the data source number. The method further includes: updating the storage database connection pool through a message middleware to separate the maintenance of data source information from the user's acquisition and use of data source connections, thereby achieving dynamic connection.
2. The microservice-based multi-data source link management method according to claim 1, characterized in that, The method further includes: When the microservice registry receives updated data source connection information, it updates the database connection pool of the multi-data source connection pool component through the microservice registry based on long-lived connections.
3. The microservice-based multi-data source link management method according to claim 1, characterized in that, By pre-setting a multi-data source storage database, the data source number, data source link information, and the correspondence between the data source number and the data source link information are stored; The data source connection information corresponding to the data source number is obtained from the data source information configuration management microservice that is actually invoked. Specifically, this includes: The microservice configures and manages the data source information through the actual call to call the preset multi-data source storage database, thereby obtaining the data source link information corresponding to the data source number.
4. The multi-data source connection management method based on microservices according to claim 1, characterized in that, The data source number is unique and corresponds one-to-one with the database ID corresponding to the data source link information; The data source stored in the database is transmitted and stored using a preset national cryptographic algorithm.
5. The microservice-based multi-data source link management method according to claim 1, characterized in that, Before determining the data source number corresponding to the data source modification or deletion message, the method further includes: The microservice for configuring and managing data source information detects data source modification or deletion operations performed by the front-end interface to generate data source modification or deletion messages; then, it sends the data source modification or deletion messages to the multi-data source connection pool component by calling the message middleware.
6. A microservice-based multi-data source connection management system, characterized in that, The system includes: The module is used to register several data source information configuration management microservices through the microservice registry center and obtain a list of data source information configuration management microservice addresses. The acquisition module is used to determine the data source number corresponding to the data source call instruction through the multi-data source connection pool component when the multi-data source connection pool component receives the data source call instruction, and to obtain the list of data source information configuration management microservice addresses from the microservice registry. The subscription module is used to determine the actual data source information configuration management microservice to be called from the list of data source information configuration management microservice addresses through the multi-data source connection pool component based on a soft load balancing algorithm, and to subscribe to the actual data source information configuration management microservice to be called. The acquisition module is also used to send a database query instruction containing the data source number to the actual data source information configuration management microservice to be called through the multi-data source connection pool component, so as to obtain the data source connection information corresponding to the data source number from the actual data source information configuration management microservice to be called. The storage module is used to create a database connection pool based on the link information through a multi-data source connection pool component; store the database connection pool; and store the mapping relationship between the database connection pool and the data source number. The close / delete module is used to determine the data source number corresponding to the data source modification or deletion message pushed by the data source information configuration management microservice after the multi-data source connection pool component receives the data source modification or deletion message. Based on the mapping relationship, it closes and deletes the database connection pool corresponding to the data source number. The system is also configured to perform the following steps: The message middleware is used to update the storage database connection pool, thereby separating the maintenance of data source information from the user's acquisition and use of data source connections, and enabling dynamic connections.
7. The microservice-based multi-data source connection management system according to claim 6, characterized in that, The system also includes: The update module is used to update the database connection pool of the multi-data source connection pool component through the microservice registry when the microservice registry receives updated data source connection information, based on a long connection.
8. The microservice-based multi-data source connection management system according to claim 6, characterized in that, The deletion module also includes a sending unit; The sending unit is used to detect data source modification or deletion operations performed by the front-end interface through the data source information configuration management microservice, so as to generate data source modification or deletion messages; and then send the data source modification or deletion messages to the multi-data source connection pool component by calling the message middleware.