一、事件日志
配置Event Logging
- 实验性的事件记录机制,性能影响较大
- 开启默认记录所有数据的变化过程,表记录快速增长
- 日志内容json格式,建议存入mongoDB、Elastic Search
具体实现代码
javapackage com.laogoubi.config; import org.activiti.engine.event.EventLogEntry; import org.activiti.engine.runtime.ProcessInstance; import org.activiti.engine.task.Task; import org.activiti.engine.test.ActivitiRule; import org.activiti.engine.test.Deployment; import org.junit.Rule; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.List; /** * @ClassName ConfigEventLogTest * @Description EventLog * @Author eastern * @Date 2020/6/27 下午10:55 * @Version 1.0 **/ public class ConfigEventLogTest { private static final Logger logger = LoggerFactory.getLogger(ConfigEventLogTest.class); @Rule public ActivitiRule activitiRule = new ActivitiRule("activiti_eventlog.cfg.xml"); @Test @Deployment(resources = {"com/laogoubi/my-process.bpmn20.xml"}) public void test() { ProcessInstance processInstance = activitiRule.getRuntimeService().startProcessInstanceByKey("my-process"); Task task = activitiRule.getTaskService().createTaskQuery().singleResult(); activitiRule.getTaskService().complete(task.getId()); List<EventLogEntry> eventLogEntryList = activitiRule.getManagementService().getEventLogEntriesByProcessInstanceId(processInstance.getProcessInstanceId()); for (EventLogEntry eventLogEntry : eventLogEntryList) { logger.info("eventLogEntry.type = {}, eventLogEntry.data = {}", eventLogEntry.getType(), new String(eventLogEntry.getData())); } logger.info("eventLogEntryList.size = {}", eventLogEntryList.size()); } }
配置文件:activiti_eventlog.cfg.xml
xml<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration"> <property name="enableDatabaseEventLogging" value="true"/> </bean> </beans>
配置文件:my-process.bpmn20.xml
xml<?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test"> <process id="my-process"> <startEvent id="start" /> <sequenceFlow id="flow1" sourceRef="start" targetRef="someTask" /> <userTask id="someTask" name="Activiti is awesome!" /> <sequenceFlow id="flow2" sourceRef="someTask" targetRef="end" /> <endEvent id="end" /> </process> </definitions>