Do not restart dynamic parameter method for refreshing under a kind of framework based on micro services
Technical field
The invention belongs to software technology field, be related to the micro services under a kind of micro services framework does not restart dynamic parameter brush
New mechanism, the mechanism are realized, specifically a kind of base based on HTTP Long Polling and unified parameter configuration management
Do not restart dynamic parameter method for refreshing under micro services framework.
Background technology
In micro services framework, since quantity of service is numerous, various configuration resources such as address of service, database, caching,
File system, message queue and the relevant configuration of business etc. are required for being configured and be managed, and set of system is also required to
Multiple environment, such as development environment, test environment, demo environment, production environment are configured, if using traditional configuration file management
Mode, configuration file are dispersed in each project, are not easy to manage concentratedly and be safeguarded.And traditional configuration information processing mode
It is configuration information to be written in the configuration files such as xml .properties, and application is packaged together, changes configuration information every time,
It is required for re-starting packing, extremely inefficient, dynamic configuration center is exactly in order to solve this problem.Dynamic configuration center is also
One micro services, the configuration modification of configuration center each time can be flushed to dynamically among each micro services of registration and be gone, often
A micro services and no longer need to repack and restart.
The configuration dynamic state of parameters of the extension and micro services of realizing configuration center parameter refreshes, and not only needs in view of configuration
The sphere of action of center configuration parameter, clustered deploy(ment), distributed deployment environment etc., it is also contemplated that the high concurrent of dynamic refresh, high
Availability, high serious forgiveness.It so needs to plan the dynamic refresh of configuration center well and designs a kind of mature and reliable
Flush mechanism.
Invention content
In view of the necessity that the configuration dynamic state of parameters of configuration center refreshes, the object of the present invention is to provide one kind based in incognito
Do not restart dynamic parameter method for refreshing under business framework, this method can carry out dynamic expansion and refresh configuration parameter, to adapt to
The program of micro services uses.This method has been additionally contemplates that under configuration center offline environment that micro services obtain the fault-tolerant machine for configuring parameter
System.
The purpose of the present invention is achieved through the following technical solutions:
Do not restart dynamic parameter method for refreshing under a kind of framework based on micro services, it is characterised in that:This method is based in configuration
The unified parameter configuration management of the heart is joined the configuration of configuration center using SpringMvc HTTP Long Polling technologies
Number, dynamically flushes in the local cache system of micro services;It is specific as follows:
1)The dynamic refresh integrated framework of a configuration parameter is established, frame content includes:In configuration center server-side and configuration
Two parts of heart client;
Configuration center server-side:It is a unified parameter configuration management micro services, centralization is provided for each micro services
Exterior arrangement storage and management service system;
11)Configuration service Config Service:
Configuration interface service is provided for configuration center client;Configuration update push interface is provided(Based on Http long
polling);Realize that Asynchronous Request is handled using Spring DeferredResult, to greatly improve service performance;Mesh
Preceding SpringBoot is most 10000 connections using tomcat embed default configurations(It can adjust), used 4C8G's
Virtual machine actual measurement can support 10000 connections(One application example can only initiate a long connection), so can expire substantially
Sufficient High Availabitity demand.
12)Admin Service;Configuration management interface, service object Portal are provided;Configuration modification, publication are provided
Equal interfaces.
13)Portal Server;Web interface is provided and configures configuration center client for user management:For micro services application
The functions such as configuration acquisition, real-time update are provided, client Load balance, mistake is supported to retry.
2)Access configuration center:Each micro services client indicates the environment of the Id and access of itself, gets configuration
Data;
Application mode:It is supplied to micro services system with jar packet modes;
Dynamic updates:Client and server-side keep a long connection, and newer push is configured to obtain at the first time.
Configuration center server-side:All micro services using configuration center are required for registering an Id in configuration center,
Identity and corresponding configuration parameter set are closed when for accessing;
For real time push to client, the process for configuring publication is as follows after configuration is issued for configuration center server-side:
User issues in Portal operative configurations, and Portal calls the interface operation publication of Admin Service;Admin
Service publications send ReleaseMessage to each Config Service with postponing;Config Service are received
After ReleaseMessage, corresponding client is notified;
Configuration center gives out information as follows to client process:
Configuration center Admin Service notify all Config Service to have configuration to issue after configuration is issued, to
Config Service notify corresponding client to pull newest configuration;It is simple by database realizing one in realization
Message queue;
Realization method is as follows:
Admin Service can be inserted into a piece of news record after configuration is issued toward ReleaseMessage tables, and message content is just
It is the configuration information key value of configuration publication;
Config Service there are one thread can run-down ReleaseMessage tables per second, see whether new message
Record;
Config Service are if it find that have new Message Record, then notifying all message listeners;
After NotificationController obtains the key value of configuration publication, corresponding client is notified;
Configuration center client realization method is as follows:
Client initiates a Http request to the NotificationController of Config Service, will not return immediately
Return as a result, but by Spring DeferredResult request hang up, if in 30 seconds without the client be concerned about
Configuration publication, then returning to Http conditional codes 304 to client;If there is the configuration that the client is concerned about is issued,
NotificationControlle calls the setResult methods of DeferredResult, the incoming configuration for having configuration variation to join
Number information, while the request returns immediately;Client is stood after getting the namespace of configuration variation in the result of return
I.e. request Config Service obtain the latest configuration of the configuration parameter.
The present invention can carry out dynamic expansion and refresh configuration parameter, and the program to adapt to micro services uses.This method is also
Consider the fault tolerant mechanism that micro services under configuration center offline environment obtain configuration parameter.
Description of the drawings
Fig. 1 is the basic model figure of the present invention;
Fig. 2 is the system architecture diagram of the present invention;
Fig. 3 is real time push figure after the configuration publication of configuration center server-side;
Fig. 4 is configuration center released version message realization method figure;
Fig. 5 is configuration center notice client realization method figure;
Fig. 6 is that configuration center client obtains PUSH message realization method figure.
Specific implementation mode
Below in conjunction with attached drawing and specific example, the present invention is described in detail.
It includes configuration center server-side and configuration center client that configuration center dynamic parameter proposed by the present invention, which refreshes frame,
Hold two parts.
Configuration center server-side
All micro services using configuration center be required in configuration center register an Id, when for accessing identity and
Corresponding configuration parameter set is closed.It is multi-environment in order to realize, the configuration between high-availability cluster, and different micro services configuration sets
It is shared, devise privately owned parameter and common parameter.It devises NameSpace for the ease of configuration parameter management and is grouped
Management.
Fig. 3 illustrates what the design of real time push to client after configuration is issued of configuration center server-side was realized.Configuration
The substantially process of publication:
User issues in Portal operative configurations;
Portal calls the interface operation publication of Admin Service;
Admin Service publications send ReleaseMessage to each Config Service with postponing;
After Config Service receive ReleaseMessage, corresponding client is notified;
Fig. 4, which illustrates configuration center and how to send, to give out information to client.Configuration center Admin Service are issued in configuration
Afterwards, it needs that all Config Service is notified to have configuration to issue, to which Config Service can notify corresponding visitor
Family end pulls newest configuration.In view of the importance of configuration center configuration parameter data persistence, and in order to as far as possible
External dependence is reduced, is by one simple message queue of database realizing in realization.
Realization method is as follows:
Admin Service can be inserted into a piece of news record after configuration is issued toward ReleaseMessage tables, and message content is just
It is the configuration information key value of configuration publication.
Config Service there are one thread can run-down ReleaseMessage tables per second, see whether new
Message Record.
Config Service are if it find that have new Message Record, then being informed about all message listeners
(ReleaseMessageListener)Such as NotificationController.
After NotificationController obtains the key value of configuration publication, it is notified that corresponding client.
Configuration center client
Fig. 5 illustrates the realization method of Config Service notice clients:
Client can initiate a Http request will not be immediately to the NotificationController of Config Service
It returns the result, but request is hung up by Spring DeferredResult
If issued without the configuration that the client is concerned about in 30 seconds, Http conditional codes 304 can be returned to client;
If there is the configuration publication that the client is concerned about, NotificationControlle can call DeferredResult
SetResult methods, the incoming configuration parameter information for having configuration variation, while the request can return immediately.Client is from return
Result in get the namespace of configuration variation after, can immediately request Config Service obtain the configuration parameter
Latest configuration.
Fig. 6 illustrates the realization principle that configuration center client obtains configuration:
Client and server-side maintain a long connection, so as to obtain the newer push of configuration at the first time.(Pass through Http
Long Polling are realized);
Client can also periodically pull the latest configuration of application from configuration center server-side.
This is a fallback mechanism, and push-mechanism failure in order to prevent causes configuration not update;Client timing is drawn
Local version can be reported by taking, so under normal circumstances, for the operation periodically pulled, server-side can all return to 304-Not
Modified;
Timing frequency is defaulted as pulling for every 5 minutes once, and client can also pass through specifies System at runtime
Property:Apollo.refreshInterval is covered, and unit is minute.
Client can preserve in memory after configuration center server-side gets the latest configuration of application;Client meeting
The configuration got from server-side is cached portion in local file system;When the service that encounters is unavailable or obstructed network
It waits, can still be configured from local recovery;Application program can obtain newest configuration from configuration center client, subscribe to configuration more
New notice.