盘古BPM体验地址    盘古BPM交流群盘古BPM交流群号:963222735

《Flowable基础十五 Flowable异步处理日志数据(act_evt_log表)》

分享牛 5361℃

Flowable 异步处理日志数据(act_evt_log表)

    摘要:Flowable中已经将历史日志数据单独抽取出来,使用定时器进行处理,而并不是像Flowable5版本或者activiti5版本一样,在同一个事务中处理历史日志数据。这也意味着实例运行的速度以及性能会大大提升。注意一点:这里我们说的是历史日志数据数据,对应act_evt_log表中的数据,诸如act_hi_taskinst等历史细节表中的数据,flowable并不会使用定时器进行处理。这一点再次强调一点。

    1.既然涉及到了act_evt_log表,那我们肯定需要开启历史日志数据收集功能,怎么开启该功能呢,这个相对最简单,代码如下:

<bean id="processEngineConfiguration"
class="org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="dataSource" ref="dataSource" />
<property name="databaseSchemaUpdate" value="true" />
<property name="enableDatabaseEventLogging" value="true" />
</bean>


enableDatabaseEventLogging:开启日志数据收集功能。

    2.如果我们打算使用异步方式处理日志数据,则开启方式如下:

	<bean id="processEngineConfiguration"
class="org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="asyncHistoryExecutorActivate" value="true" />
<property name="asyncHistoryEnabled" value="true" />
</bean>

asyncHistoryEnabled:开启异步处理日志功能,默认值为false。

asyncHistoryExecutorActivate:开启异步处理日志的定时器,必须开启,否则没法用。


    3.注意点:

    act_ru_history_job表对应历史日志定时作业。

    act_ge_bytearray:该表会暂存历史日志的数据信息,定时作业被处理完毕之后,对应的数据会被清除。

   4.实战

    部署文档

文档的内容如下:

 <process id="myProcess" name="My process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="User Task"></userTask>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
<userTask id="usertask2" name="User Task"></userTask>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="usertask2"></sequenceFlow>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow3" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow>
</process>

部署文档

// 获取到Activiti ProcessEngine
ProcessEngine processEngine = null;
// 获取RepositoryService 实例对象
RepositoryService repositoryService = null;
// 资源名称
String resourceName = "shareniu_addInputStream.bpmn";
RuntimeService runtimeService = null;
IdentityService identityService = null;
TaskService taskService = null;
HistoryService historyService;

@Before
public void init1() {
ProcessEngineConfigurationImpl createProcessEngineConfigurationFromResource = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration
.createProcessEngineConfigurationFromResource("cn/huimin/process/ch4/flowable.cfg.xml");
// createProcessEngineConfigurationFromResource.setAsyncHistoryEnabled(true);
processEngine =createProcessEngineConfigurationFromResource.buildProcessEngine();
repositoryService = processEngine.getRepositoryService();
runtimeService = processEngine.getRuntimeService();
identityService = processEngine.getIdentityService();
taskService = processEngine.getTaskService();
historyService = processEngine.getHistoryService();
}

@Test
public void start() throws Exception {
String name = "cn/huimin/process/ch4/ch4.bpmn";
InputStream in = ProcessEnginesTest.class.getClassLoader().getResourceAsStream(name);
Deployment deploy = repositoryService.createDeployment().addInputStream(resourceName, in).deploy();
System.out.println(deploy.getId());
}

启动实例

	@Test
public void start1() throws Exception {
Map<String, Object> var=new HashMap<>();
runtimeService.startProcessInstanceByKey("myProcess",var);
}
String processDefinitionId="myProcess:1:7504";
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
System.out.println(bpmnModel);

act_ru_history_job数据如下

转载请注明:分享牛 » 《Flowable基础十五 Flowable异步处理日志数据(act_evt_log表)》