activiti-event-logger 쓰기

3913 단어 elasticsearchactiviti

spring-data-elasticsearch 도입


        
            org.springframework.data
            spring-data-elasticsearch
            2.0.1.RELEASE
        

사용자 정의 이벤트 flusher

public class EsEventFlusher extends AbstractEventFlusher {

    private static final Logger logger = LoggerFactory.getLogger(EsEventFlusher.class);

    @Override
    public void closing(CommandContext commandContext) {
        for (EventLoggerEventHandler eventHandler : eventHandlers) {
            try {
                EventLogEntryEntity entryEntity = eventHandler.generateEventLogEntry(commandContext);
                EventLogEs es = EventLogEs.buildFrom(entryEntity);
                EventLogEsRepository repository = ApplicationContextHolder.getContext().getBean(EventLogEsRepository.class);
                repository.save(es);
                logger.info("###{}",es);
                repository.refresh();
            } catch (Exception e) {
                logger.warn("Could not create event log", e);
            }
        }
    }
}

사용자 정의 이벤트 logger (사용자 정의 이벤트 플러그인 사용)

public class EsEventLogger extends EventLogger{

    public static final String EVENT_FLUSHER_KEY = "eventFlusher";

    public EsEventLogger(Clock clock, ObjectMapper objectMapper) {
        super(clock, objectMapper);
    }

    @Override
    public void onEvent(ActivitiEvent event) {
        EventLoggerEventHandler eventHandler = getEventHandler(event);
        if (eventHandler != null) {

            // Events are flushed when command context is closed
            CommandContext currentCommandContext = Context.getCommandContext();
            EventFlusher eventFlusher = (EventFlusher) currentCommandContext.getAttribute(EVENT_FLUSHER_KEY);

            if (eventHandler != null && eventFlusher == null) {

                eventFlusher = createEventFlusher();
                if (eventFlusher == null) {
                    eventFlusher = new EsEventFlusher(); // change to es event logger
                }
                currentCommandContext.addAttribute(EVENT_FLUSHER_KEY, eventFlusher);

                currentCommandContext.addCloseListener(eventFlusher);
                currentCommandContext
                        .addCloseListener(new CommandContextCloseListener() {

                            @Override
                            public void closing(CommandContext commandContext) {
                            }

                            @Override
                            public void closed(CommandContext commandContext) {
                                // For those who are interested: we can now broadcast the events were added
                                if (listeners != null) {
                                    for (EventLoggerListener listener : listeners) {
                                        listener.eventsAdded(EsEventLogger.this);
                                    }
                                }
                            }

                        });
            }

            eventFlusher.addEventHandler(eventHandler);
        }
    }
}

시작 시 이벤트 로거 지정

@Bean
    public CommandLineRunner init() {
        return new CommandLineRunner() {
            public void run(String... strings) throws Exception {
                // event logging
                runtimeService.addEventListener(new EsEventLogger(processEngineConfiguration.getClock(),objectMapper));
            }
        };
    }

es 데이터


http://192.168.99.100:9200/_plugin/head/

TODO


스크롤을 고려해야 합니다. mybatis의 업무와 연결되어 있습니다.

좋은 웹페이지 즐겨찾기