学习篇-Activiti-13-事件日志

文章目录

一、事件日志
  • 配置Event Logging

    • 实验性的事件记录机制,性能影响较大
    • 开启默认记录所有数据的变化过程,表记录快速增长
    • 日志内容json格式,建议存入mongoDB、Elastic Search
  • 具体实现代码

    package 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 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 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>
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值