以编程方式创建 Camunda 配置时,如何设置 `backoff-time-in-millis` 参数?
How can I set `backoff-time-in-millis` parameter when creating a Camunda configuration programmatically?
我有下面的 class,我想在其中配置我的 Camunda 流程引擎。
我想让引擎部署感知并设置 backoff-time-in-millis。
我可以使用 config.setJobExecutorDeploymentAware(true);
来做前者。
如何设置作业执行器的backoff-time-in-millis
等参数?
显而易见的解决方案(config.getJobExecutor().setBackoffTimeInMillis(100);
)不适用,因为调用方法org.example.Config#processEngineConfiguration
时,config.getJobExecutor()
等于null
。
@Configuration
@Import( SpringProcessEngineServicesConfiguration.class )
public class Config {
private static final Logger LOGGER = LoggerFactory.getLogger(Config.class);
@Autowired
@Qualifier("camundaBpmDataSource")
private DataSource dataSource;
@Autowired
@Qualifier("camundaTxManager")
private PlatformTransactionManager txManager;
@Autowired
private ResourcePatternResolver resourceLoader;
@Bean
public SpringProcessEngineConfiguration processEngineConfiguration() {
final SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration();
config.setJobExecutorDeploymentAware(true);
config.setIdGenerator(new StrongUuidGenerator());
config.setDataSource(dataSource);
config.setTransactionManager(txManager);
config.setDatabaseSchemaUpdate("true");
config.getProcessEnginePlugins().add(new SpinProcessEnginePlugin());
config.setHistory(HistoryLevel.HISTORY_LEVEL_FULL.getName());
config.setJobExecutorActivate(true);
config.setMetricsEnabled(false);
final Logger logger = LoggerFactory.getLogger("History Event Handler");
final HistoryEventHandler testHistoryEventHandler = new HistoryEventHandler() {
@Override
public void handleEvent(final HistoryEvent evt) {
LOGGER.debug("handleEvent | " + evt.getProcessInstanceId() + " | "
+ evt.toString());
}
@Override
public void handleEvents(final List<HistoryEvent> events) {
for (final HistoryEvent curEvent : events) {
handleEvent(curEvent);
}
}
};
config.setHistoryEventHandler(new CompositeHistoryEventHandler(Collections.singletonList(testHistoryEventHandler)));
try {
final Resource[] bpmnResources = resourceLoader.getResources("classpath:*.bpmn");
final Resource[] dmnResources = resourceLoader.getResources("classpath:*.dmn");
config.setDeploymentResources(addAll(bpmnResources, dmnResources));
} catch (final IOException exception) {
exception.printStackTrace();
LOGGER.error("An error occurred while trying to deploy BPMN and DMN files", exception);
}
return config;
}
}
将以下代码添加到上面的方法 processEngineConfiguration()
中:
final ThreadPoolJobExecutor executor = new DefaultJobExecutor();
executor.setMaxJobsPerAcquisition(3);
executor.setWaitTimeInMillis(500);
executor.setLockTimeInMillis(300000);
executor.setMaxBackoff(150);
executor.setMaxWait(50);
final SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration();
config.setJobExecutor(executor);
config.setJobExecutorDeploymentAware(true);
我有下面的 class,我想在其中配置我的 Camunda 流程引擎。
我想让引擎部署感知并设置 backoff-time-in-millis。
我可以使用 config.setJobExecutorDeploymentAware(true);
来做前者。
如何设置作业执行器的backoff-time-in-millis
等参数?
显而易见的解决方案(config.getJobExecutor().setBackoffTimeInMillis(100);
)不适用,因为调用方法org.example.Config#processEngineConfiguration
时,config.getJobExecutor()
等于null
。
@Configuration
@Import( SpringProcessEngineServicesConfiguration.class )
public class Config {
private static final Logger LOGGER = LoggerFactory.getLogger(Config.class);
@Autowired
@Qualifier("camundaBpmDataSource")
private DataSource dataSource;
@Autowired
@Qualifier("camundaTxManager")
private PlatformTransactionManager txManager;
@Autowired
private ResourcePatternResolver resourceLoader;
@Bean
public SpringProcessEngineConfiguration processEngineConfiguration() {
final SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration();
config.setJobExecutorDeploymentAware(true);
config.setIdGenerator(new StrongUuidGenerator());
config.setDataSource(dataSource);
config.setTransactionManager(txManager);
config.setDatabaseSchemaUpdate("true");
config.getProcessEnginePlugins().add(new SpinProcessEnginePlugin());
config.setHistory(HistoryLevel.HISTORY_LEVEL_FULL.getName());
config.setJobExecutorActivate(true);
config.setMetricsEnabled(false);
final Logger logger = LoggerFactory.getLogger("History Event Handler");
final HistoryEventHandler testHistoryEventHandler = new HistoryEventHandler() {
@Override
public void handleEvent(final HistoryEvent evt) {
LOGGER.debug("handleEvent | " + evt.getProcessInstanceId() + " | "
+ evt.toString());
}
@Override
public void handleEvents(final List<HistoryEvent> events) {
for (final HistoryEvent curEvent : events) {
handleEvent(curEvent);
}
}
};
config.setHistoryEventHandler(new CompositeHistoryEventHandler(Collections.singletonList(testHistoryEventHandler)));
try {
final Resource[] bpmnResources = resourceLoader.getResources("classpath:*.bpmn");
final Resource[] dmnResources = resourceLoader.getResources("classpath:*.dmn");
config.setDeploymentResources(addAll(bpmnResources, dmnResources));
} catch (final IOException exception) {
exception.printStackTrace();
LOGGER.error("An error occurred while trying to deploy BPMN and DMN files", exception);
}
return config;
}
}
将以下代码添加到上面的方法 processEngineConfiguration()
中:
final ThreadPoolJobExecutor executor = new DefaultJobExecutor();
executor.setMaxJobsPerAcquisition(3);
executor.setWaitTimeInMillis(500);
executor.setLockTimeInMillis(300000);
executor.setMaxBackoff(150);
executor.setMaxWait(50);
final SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration();
config.setJobExecutor(executor);
config.setJobExecutorDeploymentAware(true);