🍖Smooth hot refresh
LiteFlow supports the feature of smooth hot refresh.
You can reload rules without restarting the service. And when refreshing under high concurrency, the thread that is executing the process is completely smooth, and there will be no interruption due to the refreshing process.
When refreshing, the process being executed is still the old process. After the refresh, the request will automatically switch to the new process.
The zookeeper configuration source natively supported by LiteFlow does not require you to do anything. As long as the rules on zk are changed, it will be refreshed automatically and smoothly.
But for custom configuration sources, LiteFlow provides two interfaces: active refresh and passive refresh, which can be selected according to your needs.
# Rules file based - active refresh
You can call the following interface after getting the FlowExecutor
object in the spring container:
flowExecutor.reloadRule();
This method will pull your latest process configuration information according to the method at startup, and perform smooth hot refresh.
# Rules file based - passive refresh
Passive refresh is suitable for using custom configuration sources such as configuration center, nacos, etcd, which can push the latest data in reverse. For the java client side, there must be a listener listen for data changes.
If the listener listens for changes, you can achieve smooth hot refresh by calling this method:
FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, newContent);
The first parameter refers to the file format. It supports xml/json/yml. Note here that under the EL expression, it is in the form of TYPE_EL_XXX
. The one without EL is the old form, please do not use it wrong!
The second parameter refers to the latest configuration text data
# Build-Refresh from Dynamic Code
If based on dynamic rules, it means that there is no rule file, and the above two methods are based on rule files.
In fact, based on dynamic rules, it is recommended that you encapsulate the code into a method. When there are changes, just re-execute the build again. rules will be overwritten. And this process is also smooth.