篇章引言
桂花流程引擎(Osmanthus),是基于Camunda 7.20+扩展,旨在满足国内精细化的审批需求的国产流程引擎。桂花流程引擎为桂云网络公司旗下的标准化流程产品,之所以取名为“桂花”,其一是因为桂云网络公司主商标“桂云”的实物化产品品牌延伸,其二是因为桂花是中国传统文化名花,其淡雅的清香给人一种古典而唯美的体验感官。桂花流程引擎中“桂花”为桂云网络公司指定在商标尼斯分类第0901组软件类产品的商标,本文由桂云网络OSG独家贡献。
关键字: 桂云网络, 桂云, OSG, 桂花流程引擎, 桂花流程, 桂花, bpmn
在流程引擎中,需要使用到缓存,缓存是可以自定义扩展的,本文主要讲解桂花流程引擎配置类自定义扩展示例
实现过程
桂花流程引擎(Osmanthus)的缓存,我们需要定义是否启用缓存enabled、生效时间ttl和缓存的前缀prefix三个参数。在spring-boot-starter中定义相关的配置参数,定义一个缓存属性类
public class CacheProperty {
private boolean enabled;
private int ttl;
private String prefix;
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public int getTtl() {
return ttl;
}
public void setTtl(int ttl) {
this.ttl = ttl;
}
public String getPrefix() {
return prefix;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
@Override
public String toString() {
return joinOn(this.getClass())
.add("enabled=" + enabled)
.add("ttl=" + ttl)
.add("prefix=" + prefix)
.toString();
}
}
然后在CamundaBpmProperties类中,增加一个属性cache
package org.camunda.bpm.spring.boot.starter.property;
import org.apache.commons.lang3.RandomStringUtils;
import org.camunda.bpm.engine.ProcessEngineConfiguration;
import org.camunda.bpm.engine.ProcessEngines;
import org.camunda.bpm.spring.boot.starter.configuration.id.IdGeneratorConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import java.net.URL;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.StringJoiner;
import static org.springframework.core.io.support.ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX;
@ConfigurationProperties(CamundaBpmProperties.PREFIX)
public class CamundaBpmProperties {
public static final String PREFIX = "camunda.bpm";
public static final String UNIQUE_ENGINE_NAME_PREFIX = "processEngine";
public static final String UNIQUE_APPLICATION_NAME_PREFIX = "processApplication";
public static final String[] DEFAULT_BPMN_RESOURCE_SUFFIXES = new String[]{"bpmn20.xml", "bpmn" };
public static final String[] DEFAULT_CMMN_RESOURCE_SUFFIXES = new String[]{"cmmn11.xml", "cmmn10.xml", "cmmn" };
public static final String[] DEFAULT_DMN_RESOURCE_SUFFIXES = new String[]{"dmn11.xml", "dmn" };
static String[] initDeploymentResourcePattern() {
final Set<String> suffixes = new HashSet<>();
suffixes.addAll(Arrays.asList(DEFAULT_DMN_RESOURCE_SUFFIXES));
suffixes.addAll(Arrays.asList(DEFAULT_BPMN_RESOURCE_SUFFIXES));
suffixes.addAll(Arrays.asList(DEFAULT_CMMN_RESOURCE_SUFFIXES));
final Set<String> patterns = new HashSet<>();
for (String suffix : suffixes) {
patterns.add(String.format("%s**/*.%s", CLASSPATH_ALL_URL_PREFIX, suffix));
}
return patterns.toArray(new String[patterns.size()]);
}
static StringJoiner joinOn(final Class<?> clazz) {
return new StringJoiner(", ", clazz.getSimpleName() + "[", "]");
}
public static String getUniqueName(String name) {
return name + RandomStringUtils.randomAlphanumeric(10);
}
/**
* name of the process engine
*/
private String processEngineName = ProcessEngines.NAME_DEFAULT;
private Boolean generateUniqueProcessEngineName = false;
private Boolean generateUniqueProcessApplicationName = false;
private String idGenerator = IdGeneratorConfiguration.STRONG;
private Boolean jobExecutorAcquireByPriority = null;
private Integer defaultNumberOfRetries = null;
/**
* the history level to use
*/
private String historyLevel = ProcessEngineConfiguration.HISTORY_FULL;
/**
* the default history level to use when 'historyLevel' is 'auto'
*/
private String historyLevelDefault = ProcessEngineConfiguration.HISTORY_FULL;
/**
* enables auto deployment of processes
*/
private boolean autoDeploymentEnabled = true;
/**
* resource pattern for locating process sources
*/
private String[] deploymentResourcePattern = initDeploymentResourcePattern();
/**
* default serialization format to use
*/
private String defaultSerializationFormat = Defaults.INSTANCE.getDefaultSerializationFormat();
private URL licenseFile;
/**
* deactivate camunda auto configuration
*/
private boolean enabled = true;
/**
* metrics configuration
*/
@NestedConfigurationProperty
private MetricsProperty metrics = new MetricsProperty();
/**
* database configuration
*/
@NestedConfigurationProperty
private DatabaseProperty database = new DatabaseProperty();
/**
* Spring eventing configuration
*/
@NestedConfigurationProperty
private EventingProperty eventing = new EventingProperty();
/**
* job execution configuration
*/
@NestedConfigurationProperty
private JobExecutionProperty jobExecution = new JobExecutionProperty();
/**
* webapp configuration
*/
@NestedConfigurationProperty
private WebappProperty webapp = new WebappProperty();
@NestedConfigurationProperty
private AuthorizationProperty authorization = new AuthorizationProperty();
@NestedConfigurationProperty
private GenericProperties genericProperties = new GenericProperties();
@NestedConfigurationProperty
private AdminUserProperty adminUser = new AdminUserProperty();
@NestedConfigurationProperty
private FilterProperty filter = new FilterProperty();
// 增加的配置
@NestedConfigurationProperty
private CacheProperty cache = new CacheProperty();
public String getProcessEngineName() {
return processEngineName;
}
public void setProcessEngineName(String processEngineName) {
this.processEngineName = processEngineName;
}
public String getHistoryLevel() {
return historyLevel;
}
public void setHistoryLevel(String historyLevel) {
this.historyLevel = historyLevel;
}
public String getHistoryLevelDefault() {
return historyLevelDefault;
}
public void setHistoryLevelDefault(String historyLevelDefault) {
this.historyLevelDefault = historyLevelDefault;
}
public boolean isAutoDeploymentEnabled() {
return autoDeploymentEnabled;
}
public void setAutoDeploymentEnabled(boolean autoDeploymentEnabled) {
this.autoDeploymentEnabled = autoDeploymentEnabled;
}
public String[] getDeploymentResourcePattern() {
return deploymentResourcePattern;
}
public void setDeploymentResourcePattern(String[] deploymentResourcePattern) {
this.deploymentResourcePattern = deploymentResourcePattern;
}
public String getDefaultSerializationFormat() {
return defaultSerializationFormat;
}
public void setDefaultSerializationFormat(String defaultSerializationFormat) {
this.defaultSerializationFormat = defaultSerializationFormat;
}
public URL getLicenseFile() {
return licenseFile;
}
public void setLicenseFile(URL licenseFile) {
this.licenseFile = licenseFile;
}
public MetricsProperty getMetrics() {
return metrics;
}
public void setMetrics(MetricsProperty metrics) {
this.metrics = metrics;
}
public DatabaseProperty getDatabase() {
return database;
}
public void setDatabase(DatabaseProperty database) {
this.database = database;
}
public EventingProperty getEventing() {
return eventing;
}
public void setEventing(EventingProperty eventing) {
this.eventing = eventing;
}
public JobExecutionProperty getJobExecution() {
return jobExecution;
}
public void setJobExecution(JobExecutionProperty jobExecution) {
this.jobExecution = jobExecution;
}
public WebappProperty getWebapp() {
return webapp;
}
public void setWebapp(WebappProperty webapp) {
this.webapp = webapp;
}
public AuthorizationProperty getAuthorization() {
return authorization;
}
public void setAuthorization(AuthorizationProperty authorization) {
this.authorization = authorization;
}
public GenericProperties getGenericProperties() {
return genericProperties;
}
public void setGenericProperties(GenericProperties genericProperties) {
this.genericProperties = genericProperties;
}
public AdminUserProperty getAdminUser() {
return adminUser;
}
public void setAdminUser(AdminUserProperty adminUser) {
this.adminUser = adminUser;
}
public FilterProperty getFilter() {
return filter;
}
public void setFilter(FilterProperty filter) {
this.filter = filter;
}
// 增加的配置
public CacheProperty getCache() {
return cache;
}
// 增加的配置
public void setCache(CacheProperty cache) {
this.cache = cache;
}
public String getIdGenerator() {
return idGenerator;
}
public void setIdGenerator(String idGenerator) {
this.idGenerator = idGenerator;
}
public Boolean getJobExecutorAcquireByPriority() {
return jobExecutorAcquireByPriority;
}
public void setJobExecutorAcquireByPriority(Boolean jobExecutorAcquireByPriority) {
this.jobExecutorAcquireByPriority = jobExecutorAcquireByPriority;
}
public Integer getDefaultNumberOfRetries() {
return defaultNumberOfRetries;
}
public void setDefaultNumberOfRetries(Integer defaultNumberOfRetries) {
this.defaultNumberOfRetries = defaultNumberOfRetries;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public Boolean getGenerateUniqueProcessEngineName() {
return generateUniqueProcessEngineName;
}
public void setGenerateUniqueProcessEngineName(Boolean generateUniqueProcessEngineName) {
this.generateUniqueProcessEngineName = generateUniqueProcessEngineName;
}
public Boolean getGenerateUniqueProcessApplicationName() {
return generateUniqueProcessApplicationName;
}
public void setGenerateUniqueProcessApplicationName(Boolean generateUniqueProcessApplicationName) {
this.generateUniqueProcessApplicationName = generateUniqueProcessApplicationName;
}
@Override
public String toString() {
return joinOn(this.getClass())
.add("enabled=" + enabled)
.add("processEngineName=" + processEngineName)
.add("generateUniqueProcessEngineName=" + generateUniqueProcessEngineName)
.add("generateUniqueProcessApplicationName=" + generateUniqueProcessApplicationName)
.add("historyLevel=" + historyLevel)
.add("historyLevelDefault=" + historyLevelDefault)
.add("autoDeploymentEnabled=" + autoDeploymentEnabled)
.add("deploymentResourcePattern=" + Arrays.toString(deploymentResourcePattern))
.add("defaultSerializationFormat=" + defaultSerializationFormat)
.add("licenseFile=" + licenseFile)
.add("metrics=" + metrics)
.add("database=" + database)
.add("jobExecution=" + jobExecution)
.add("webapp=" + webapp)
.add("authorization=" + authorization)
.add("genericProperties=" + genericProperties)
.add("adminUser=" + adminUser)
.add("filter=" + filter)
.add("cache=" + cache) // 增加的配置
.add("idGenerator=" + idGenerator)
.add("jobExecutorAcquireByPriority=" + jobExecutorAcquireByPriority)
.add("defaultNumberOfRetries" + defaultNumberOfRetries)
.toString();
}
}
这样即可完成缓存的配置参数,如
camunda:
bpm:
generic-properties:
properties:
historyTimeToLive: P1D
database:
schema-update: true
auto-deployment-enabled: false
history-level: full
authorization:
enabled: true
job-execution:
enabled: true
# 缓存配置
cache:
enabled: true
ttl: 7200
prefix: "osg:bpm"
作者: 桂云网络, 桂云, OSG