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

activiti 专栏收录该内容
32 篇文章 1 订阅

文章目录

一、事件日志
  • 配置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
    点赞
  • 0
    评论
  • 1
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 技术工厂 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值