Application service configuration hot loading method based on message queue and related equipment

A message queue-based method for application service configuration updates addresses the need for real-time database connection management, ensuring continuous service availability and enhanced security by updating connections without service restarts.

CN114780165BActive Publication Date: 2024-12-17CHINA LIFE INSURANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210248577.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-14
Publication Date
2024-12-17
Estimated Expiration
2042-03-14

AI Technical Summary

Technical Problem

Existing application services require restarts when database configuration changes, causing intermittent unavailability and poor user experience due to the need to disconnect and re-establish database connections.

Method used

Implement a message queue-based method to store and manage configuration change information, allowing real-time updates of database connections without service restarts by using a message queue system like Kafka to judge and update connections based on user configuration changes.

Benefits of technology

Ensures continuous service availability and improved security by preventing malicious access while maintaining user experience, as users with unchanged configurations can continue accessing the database without service interruptions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114780165B_ABST
    Figure CN114780165B_ABST
Patent Text Reader

Abstract

The present application provides a method and related equipment for hot loading of application service configuration based on a message queue, wherein a database connection is established between the application service and the data source, and the method comprises: obtaining configuration change information of the data source; storing the configuration change information in a message queue system to form a message queue; in response to a user accessing the data source through the application service, obtaining the configuration change information in the message queue to make a change judgment; in response to a change in the user's configuration information, updating the corresponding database connection. The method and related equipment for hot loading of application service configuration based on a message queue provided by the present application have a good user experience, can ensure that the service is always online, and can achieve real-time hot loading without shutting down the application service, thereby avoiding users whose configuration information has been changed from using the original database connection to access the data source.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of hot loading technology, and in particular to a message queue-based application service configuration hot loading method and related equipment. Background Art

[0002] When an application service accesses a database through JDBC (Java Database Connectivity), a corresponding database connection is established. When the database configuration information changes, such as changes in the user name, password, or permissions, in order to prevent the changed user from continuing to access the database using the original database connection, the application service usually needs to be restarted, disconnecting the original database connection, thereby updating the configuration and establishing a new database connection. However, the application service restart will be intermittently unavailable, which will cause inconvenience to other users and poor service experience. Summary of the invention

[0003] In view of this, the purpose of this application is to propose a message queue-based application service configuration hot loading method and related equipment to solve the above technical problems.

[0004] In a first aspect of the present application, a method for hot loading application service configuration based on a message queue is provided, wherein a database connection is established between the application service and a data source, and the method comprises: obtaining configuration change information of the data source; storing the configuration change information in a message queue system to form a message queue; in response to a user accessing the data source through the application service, obtaining the configuration change information in the message queue to perform change judgment; in response to a change in the user's configuration information, updating the corresponding database connection.

[0005] Furthermore, the message queue-based application service configuration hot loading method further includes: in response to the configuration information of the user not being changed, maintaining the database connection.

[0006] Further, the updating of the corresponding database connection includes: when the application service is online, closing the original database connection of the user and creating a new database connection changed by the user.

[0007] Furthermore, the configuration change information includes a user name change, a password change and a user authority change, and the configuration information includes a user name, a password and a user authority.

[0008] Furthermore, the message queue system is Kafka, and the configuration change information in the message queue is arranged in chronological order of change time.

[0009] Furthermore, the data source includes multiple databases, and the types of the databases are one or more of Impala database, Sqlserver database, Mysql database, Gauss database, OceanBase database, Oracle database and PolarDB database.

[0010] Furthermore, the application service is provided with a database connection pool, and the database connection pool is configured to manage a plurality of the database connections.

[0011] Furthermore, the obtaining of the configuration change information of the data source includes: setting an expiration time of the database connection and a storage time of the configuration change information in the message queue system, the expiration time being shorter than the storage time.

[0012] In a second aspect of the present application, a message queue-based application service configuration hot loading device is provided, comprising: an acquisition module, configured to acquire configuration change information of a data source; a storage module, configured to store the configuration change information in a message queue system to form a message queue; a judgment module, configured to obtain the configuration change information in the message queue for change judgment in response to a user accessing the data source through an application service; and an update module, configured to update the corresponding database connection in response to a change in the user's configuration information.

[0013] The third aspect of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the message queue-based application service configuration hot loading method as described in the first aspect above when executing the computer program.

[0014] The fourth aspect of the present application provides a non-transitory computer-readable storage medium, which stores computer instructions, characterized in that the computer instructions are used to enable the computer to execute the message queue-based application service configuration hot loading method as described in the first aspect above.

[0015] As can be seen from the above, the present application provides a method and related equipment for hot loading of application service configuration based on a message queue. A message queue is set between the application service and the data source. The message queue contains configuration change information of the data source. When any user accesses the data source through the application service, the configuration change information in the message queue can be consumed. If the user's configuration information changes, the corresponding database connection is updated. In this way, for users whose configuration information has changed, there is no need to restart the application service, and the original database connection can be avoided. Hot loading of the application service configuration is realized, malicious user access is avoided, and the security of the application service is improved; for users whose configuration information has not changed, continuous access to the database is possible, and the user experience is good, avoiding the inconvenience caused by restarting the application service; the method and related equipment for hot loading of application service configuration based on a message queue have a good user experience, can ensure that the service is always online, and can realize real-time hot loading without shutting down the application service, avoiding users whose configuration information has changed from using the original database connection to access the data source. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the technical solutions in the present application or related technologies, the drawings required for use in the embodiments or related technical descriptions are briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0017] Figure 1 A flow chart of a method for hot loading application service configuration based on a message queue according to an embodiment of the present application;

[0018] Figure 2 A schematic diagram of the principle of a message queue-based application service configuration hot loading method according to an embodiment of the present application;

[0019] Figure 3 A schematic diagram of the structure of a message queue-based application service configuration hot loading device according to an embodiment of the present application;

[0020] Figure 4 A schematic diagram of the structure of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0021] In order to make the objectives, technical solutions and advantages of the present application more clearly understood, the present application is further described in detail below in combination with specific embodiments and with reference to the accompanying drawings.

[0022] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in the embodiments of the present application should be understood by people with ordinary skills in the field to which the present application belongs. The "first", "second" and similar words used in the embodiments of the present application do not represent any order, quantity or importance, but are only used to distinguish different components. "Including" or "comprising" and similar words mean that the elements or objects appearing in front of the word cover the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connect" or "connected" and similar words are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect.

[0023] The client application service mainly connects to the data source through JDBC (Java Database Connectivity). The data source refers to the database used by the application service. JDBC is an application program interface in the Java language that specifies how the application service accesses the relational database. It provides methods such as querying and updating data in the database, including applications with C / S or B / S structures. The C / S structure, namely the Client / Server structure, is a common software system architecture. By reasonably allocating tasks to the Client and Server ends, the communication overhead of the system is reduced, and the advantages of the hardware environment at both ends can be fully utilized. The B / S structure, namely the Browser / Server structure, is a variation or improvement of the C / S structure. Under the B / S structure, the user interface is completely implemented through a WWW browser.

[0024] When an application service accesses a database through JDBC, a corresponding database connection is established. When the database configuration information changes, such as changes in the user name, password, or permissions, in order to prevent the changed user from continuing to access the database using the original database connection, the application service usually needs to be restarted to disconnect the original database connection and update the configuration. However, the application service restart will result in intermittent unavailability, which will cause inconvenience to other users.

[0025] For example, in order to save resources and improve efficiency, the application service will manage database connections through a database connection pool, and usually set an expiration time for the database connection. When the expiration time exceeds the user's failure to access the database through the application service, the database connection pool will close the database connection. However, if the user accesses the database through the application service within the expiration time, the expiration time of the database connection will be refreshed.

[0026] After the administrator updates the database configuration information, for users whose configuration information has been changed, if they access the database after the expiration time, they need to re-establish a new database connection; however, if they access the database within the expiration time, the original database connection is still valid because the expiration time is refreshed. For example, for users with expired permissions, there will be a vulnerability that allows them to access the database even if the database configuration information has been changed, which will reduce security. In this case, the usual practice is to restart the application service and update the configuration, so that the original database connection is closed. After the restart, the user will use the new database connection when accessing again to avoid malicious access by the user.

[0027] However, restarting the application service will cause a brief shutdown of the application service, for example, 10 minutes. During this period, users whose configuration information has not changed cannot access the database, which brings inconvenience to users and poor service experience. Therefore, a method that can realize hot loading of application service configuration is urgently needed. Hot loading simply means not restarting a project, updating part of the code, reloading the class (development environment) at runtime, not releasing memory, and not restarting the server.

[0028] In the process of implementing this application, it was found that it is possible to consider setting up a message queue between the application service and the database. The message queue stores configuration change information. When any user accesses the database, the configuration change information in the message queue can be consumed. If the user's configuration information changes, the corresponding database connection is updated. Without restarting the application service, users whose configuration information has changed are prevented from using the original database connection, so as to solve the inconvenience caused by restarting the application service.

[0029] Below, through specific embodiments and combined Figure 1-4 To describe the technical solution of this application in detail.

[0030] Some embodiments of the present application provide a method for hot loading application service configuration based on a message queue, wherein a database connection is established between the application service 21 and the data source 22, such as Figure 1 and Figure 2 As shown, the method comprises the following steps:

[0031] S1. Obtain configuration change information of the data source 22.

[0032] The data source 22 includes multiple databases, and the type of database can be one or more of Impala database, Sqlserver database, Mysql database, Gauss database, OceanBase database, Oracle database and PolarDB database, without specific limitation.

[0033] The configuration change information of the data source 22 includes user name change, password change, user authority change, etc., which are not specifically limited. Usually, after the administrator updates the data source 22, the configuration change information can be obtained from the data source 22.

[0034] S2. Storing the configuration change information in the message queue system 23 to form a message queue.

[0035] The configuration change information is arranged in the order of change time in the message queue system 23 to form a message queue, so that the subsequent application service 21 can make change judgments; the message queue system 23 can be Kafka, which is a distributed, high-throughput, and highly scalable message queue system that can support millions of messages per second and has relatively high stability and efficiency.

[0036] S3. In response to the user accessing the data source 22 through the application service 21, the configuration change information in the message queue is obtained to perform change judgment.

[0037] A message queue is set between the application service 21 and the data source 22. The message queue contains configuration change information of the data source 22. When any user accesses the data source 22 through the application service 21, the application service 21 can consume the configuration change information in the message queue and make a change judgment. The change judgment is to judge whether the user's configuration information has changed. The configuration information includes user name, password, user authority, etc., which is not specifically limited.

[0038] S4. In response to a change in the user's configuration information, update the corresponding database connection.

[0039] If the user's configuration information is changed, the corresponding database connection is updated. In this way, for users whose configuration information is changed, there is no need to restart the application service 21, and the use of the original database connection for access can be avoided, thereby realizing hot loading of the application service 21 configuration, avoiding malicious access by users, and improving the security of the application service 21. For users whose configuration information has not been changed, they can continue to access the data source 22, with a good user experience. The application service 21 is always online, avoiding the inconvenience caused by the restart of the application service 21.

[0040] The message queue-based application service configuration hot loading method has a good user experience and can ensure that the service is always online. It can achieve real-time hot loading without shutting down the application service 21, and avoid users whose configuration information has been changed from using the original database connection to access the data source 22.

[0041] In some embodiments, multiple databases can be managed through DMBS (Database Management System), which is a large-scale software for manipulating and managing databases. It is used to establish, use and maintain databases. It manages and controls the databases in a unified manner to ensure the security and integrity of the databases.

[0042] In some embodiments, the application service 21 is a JavaApplication, and the core framework is built by springboot, in which the tomcat server is integrated, and MyBatis is referenced as the persistence layer framework for storing basic operation content.

[0043] In some embodiments, the message queue-based application service configuration hot loading method further includes:

[0044] S5. In response to the configuration information of the user not being changed, maintaining the database connection.

[0045] For users whose configuration information has not been changed, the original database connection can be used to access the data source 22, and the application service 21 is always online, providing a good user experience.

[0046] Making a change judgment on the accessing users is equivalent to classifying the users and performing different treatments on users of different classifications, instead of a "one-size-fits-all" treatment such as restarting the application service 21. This can keep the application service 21 online all the time, continuously provide services, and improve the user experience.

[0047] In some embodiments, updating the corresponding database connection includes:

[0048] S401. When the application service 21 is online, close the original database connection of the user and create a new database connection changed by the user.

[0049] Close the original database connection of the user whose configuration information has been changed, so as to avoid the situation where the user continues to access the data source 22 using the original database connection, thereby avoiding security vulnerabilities; create a new changed database connection, so that the user can use the changed database connection to access the data source 22 again, and the data source 22 can allow or deny access to the user based on the user's permissions and other information.

[0050] In some embodiments, the application service 21 is provided with a database connection pool, and the database connection pool is configured to manage a plurality of the database connections.

[0051] The database connection pool is used to manage multiple database connections, which can save resources and improve efficiency. The database connection pool can be Druid, and there is no specific limitation. Druid is an efficient data query system that is compatible with multiple databases.

[0052] In some embodiments, before step S1, the step further includes:

[0053] S0. Set the expiration time of the database connection and the storage time of the configuration change information in the message queue system 23, wherein the expiration time is less than the storage time.

[0054] An expiration time can be set for the database connection. The expiration time is, for example, 90 seconds, but there is no specific limit. In this way, there are two situations when the user accesses the data source 22. In the first situation, when the user does not access the data source 22 within the expiration time, the database connection pool will close the database connection. In the second situation, if the user accesses the data source 22 within the expiration time, the expiration time of the database connection will be refreshed.

[0055] For the second case, steps S1 to S4 can avoid the continuous refreshing of the expiration time of the original database connection of the user whose configuration information is changed; further, in order to reduce the occupancy of the message queue in the message queue system 23, the storage time of the configuration change information can be set, and the storage time is, for example, 7 days, which is not specifically limited. The expired configuration change information is deleted to reduce memory; the storage time must be greater than the expiration time, so as to avoid the risk of the configuration change information expiring if the user whose configuration information is changed does not access the data source 22 within the storage time, but the user accesses the data source 22 within the expiration time, and there is still a risk of using the original database connection.

[0056] The message queue-based application service configuration hot loading method has good user experience and high security, and can ensure that the service is always online, and realize real-time hot loading without shutting down the application service 21.

[0057] It should be noted that the above describes some embodiments of the present application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the above embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0058] Based on the same inventive concept, corresponding to any of the above-mentioned embodiments, the present application also provides another application service configuration hot loading device based on a message queue, referring to Figure 3 ,include:

[0059] An acquisition module 31 is configured to acquire configuration change information of a data source;

[0060] The storage module 32 is configured to store the configuration change information in a message queue system to form a message queue;

[0061] The judgment module 33 is configured to obtain the configuration change information in the message queue to perform change judgment in response to the user accessing the data source through the application service;

[0062] The updating module 34 is configured to update the corresponding database connection in response to a change in the configuration information of the user.

[0063] For the convenience of description, the above device is described in terms of functions divided into various modules. Of course, when implementing the present application, the functions of each module can be implemented in the same or multiple software and / or hardware.

[0064] The device of the above embodiment is used to implement the corresponding message queue-based application service configuration hot loading method in any of the above embodiments, and has the beneficial effects of the corresponding method embodiment, which will not be repeated here.

[0065] In some embodiments, the application service 21, the data source 22 and the message queue system 23 are stored on different servers respectively.

[0066] Based on the same inventive concept, corresponding to any of the above-mentioned embodiments, the present application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the message queue-based application service configuration hot loading method described in any of the above embodiments is implemented.

[0067] Figure 4 A more specific schematic diagram of the hardware structure of an electronic device provided in this embodiment is shown, and the device may include: a processor 1010, a memory 1020, an input / output interface 1030, a communication interface 1040 and a bus 1050. It is characterized in that the processor 1010, the memory 1020, the input / output interface 1030 and the communication interface 1040 realize communication connection with each other inside the device through the bus 1050.

[0068] The processor 1010 can be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.

[0069] The memory 1020 may be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 1020 may store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program codes are stored in the memory 1020 and are called and executed by the processor 1010.

[0070] The input / output interface 1030 is used to connect the input / output module to realize information input and output. The input / output module can be configured as a component in the device (not shown in the figure), or it can be externally connected to the device to provide corresponding functions. It is characterized in that the input device can include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output device can include a display, a speaker, a vibrator, an indicator light, etc.

[0071] The communication interface 1040 is used to connect a communication module (not shown) to realize communication interaction between the device and other devices. The communication module can realize communication through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).

[0072] The bus 1050 includes a path that transmits information between the various components of the device (eg, the processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040).

[0073] It should be noted that, although the above device only shows the processor 1010, the memory 1020, the input / output interface 1030, the communication interface 1040 and the bus 1050, in the specific implementation process, the device may also include other components necessary for normal operation. In addition, it can be understood by those skilled in the art that the above device may also only include the components necessary for implementing the embodiments of the present specification, and does not necessarily include all the components shown in the figure.

[0074] The electronic device of the above embodiment is used to implement the corresponding message queue-based application service configuration hot loading method in any of the above embodiments, and has the beneficial effects of the corresponding method embodiment, which will not be repeated here.

[0075] Based on the same inventive concept, corresponding to any of the above-mentioned embodiment methods, the present application also provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the message queue-based application service configuration hot loading method as described in any of the above embodiments.

[0076] The computer-readable medium of this embodiment includes permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device.

[0077] The computer instructions stored in the storage medium of the above embodiment are used to enable the computer to execute the message queue-based application service configuration hot loading method as described in any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.

[0078] Those skilled in the art should understand that the discussion of any of the above embodiments is merely illustrative and is not intended to imply that the scope of the present application (including the claims) is limited to these examples. In line with the concept of the present application, the technical features in the above embodiments or different embodiments may be combined, the steps may be implemented in any order, and there are many other variations of the different aspects of the embodiments of the present application as described above, which are not provided in detail for the sake of simplicity.

[0079] In addition, to simplify the description and discussion, and in order not to make the embodiments of the present application difficult to understand, the device can be shown in the form of a block diagram, so as to avoid making the embodiments of the present application difficult to understand, and this also takes into account the following fact, that is, the details of the implementation method of these block diagram devices are highly dependent on the platform to be implemented in the embodiments of the present application (that is, these details should be fully within the scope of understanding of those skilled in the art). In the case of elaborating specific details to describe the exemplary embodiments of the present application, it is obvious to those skilled in the art that the embodiments of the present application can be implemented without these specific details or when these specific details are changed. Therefore, these descriptions should be considered to be illustrative rather than restrictive.

[0080] Although the present application has been described in conjunction with specific embodiments thereof, many alternatives, modifications and variations of these embodiments will be apparent to those skilled in the art in light of the foregoing description.

[0081] The embodiments of the present application are intended to cover all such substitutions, modifications and variations that fall within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the embodiments of the present application should be included in the scope of protection of the present application.

Claims

1. A method for hot loading application service configuration based on a message queue, wherein a database connection is established between the application service and a data source, the application service is provided with a database connection pool, and the database connection pool is configured to manage multiple database connections, characterized in that: The method comprises: Setting the expiration time of the database connection and the storage time of the configuration change information in the message queue system, wherein the expiration time is less than the storage time; Acquire configuration change information of the data source; the data source includes multiple databases, and the type of the database is one or more of Impala database, Sqlserver database, Mysql database, Gauss database, OceanBase database, Oracle database and PolarDB database; The configuration change information is stored in a message queue system to form a message queue; the message queue system is Kafka, and the configuration change information in the message queue is arranged in the order of change time; In response to a user accessing the data source through the application service, obtaining the configuration change information in the message queue to perform change judgment; In response to a change in the configuration information of the user, the corresponding database connection is updated; the updating of the corresponding database connection includes: when the application service is online, closing the original database connection of the user and creating a new database connection of the user change; the configuration change information includes a user name change, a password change and a user authority change, and the configuration information includes a user name, a password and a user authority; In response to the configuration information of the user not being changed, maintaining the database connection.

2. A hot loading device for application service configuration based on a message queue, wherein a database connection is established between the application service and the data source, the application service is provided with a database connection pool, and the database connection pool is configured to manage multiple database connections, characterized in that: include: An acquisition module is configured to set an expiration time of the database connection and a storage time of the configuration change information in the message queue system, wherein the expiration time is less than the storage time; Obtain configuration change information of a data source; the data source includes multiple databases, and the type of the database is one or more of an Impala database, a Sqlserver database, a Mysql database, a Gauss database, an OceanBase database, an Oracle database, and a PolarDB database; A storage module is configured to store the configuration change information in Kafka to form a message queue; the message queue system is Kafka, and the configuration change information in the message queue is arranged in the order of change time; A judgment module is configured to obtain the configuration change information in the message queue to perform change judgment in response to a user accessing the data source through an application service; the message queue system is Kafka, and the configuration change information in the message queue is arranged in chronological order of change time; An updating module, configured to update the corresponding database connection in response to a change in the configuration information of the user; The updating of the corresponding database connection includes: when the application service is online, closing the original database connection of the user and creating a new database connection of the user change; the configuration change information includes a user name change, a password change and a user authority change, and the configuration information includes a user name, a password and a user authority; In response to the configuration information of the user not being changed, maintaining the database connection.

3. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the message queue-based application service configuration hot loading method according to claim 1 is implemented.