📜  轴突流读取 - 任何代码示例

📅  最后修改于: 2022-03-11 14:56:00.690000             🧑  作者: Mango

代码示例1
@Autowired
EventStore eventStore;
    
@Test
public void testReplay() {
    
    String aggregateIdentifier = "1234";
    long startFrom = 0;
    String eventType = "org.sample.model.events.MyEvent";
    Class projectorClass = MyProjector.class;
    
    AnnotationEventHandlerAdapter eventHandlerAdapter = new AnnotationEventHandlerAdapter(projectorClass);
    DomainEventStream eventStream = eventStore.readEvents(aggregateIdentifier, startFrom);
    eventStream.asStream()
        .filter(event -> {
            // add any type of filtering based on the event here
            return event.getType() == eventType;
        })
        .forEach(event1 -> {
            try {
                eventHandlerAdapter.handle(event1);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
}