// we start the application context
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("upcaster-config.xml");
// we fetch the EventStore from the application context
EventStore eventStore = applicationContext.getBean(EventStore.class);
// we append some events. Notice we append a "ToDoItemCreatedEvent".
eventStore.appendEvents("UpcasterSample", new SimpleDomainEventStream(
new GenericDomainEventMessage("todo1", 0, new ToDoItemCreatedEvent("todo1", "I need to do this today")),
new GenericDomainEventMessage("todo1", 1, new ToDoItemCompletedEvent("todo1"))
));
eventStore.appendEvents("UpcasterSample", new SimpleDomainEventStream(
new GenericDomainEventMessage("todo2", 0, new ToDoItemCreatedEvent("todo2", "I also need to do this"))
));
// now, we read the events from the "todo1" stream
DomainEventStream upcastEvents = eventStore.readEvents("UpcasterSample", "todo1");
while (upcastEvents.hasNext()) {
// and print them, so that we can see what we ended up with
System.out.println(upcastEvents.next().getPayload().toString());
}
IOUtils.closeQuietlyIfCloseable(upcastEvents);