Closed olijaun closed 5 years ago
I think it would be better to improve stream iterators/splitterators, that could return Collections.emptyIterator()
or Stream.empty()
in case of stream not found or deleted.
other options at the moment could be:
boolean exists = eventstore.readEvent("stream", 0, false)
.thenApply(r -> r.status == EventReadStatus.Success)
.join();
List<ResolvedEvent> events = new ArrayList<>();
StreamEventsSlice slice; long position = StreamPosition.START;
do { slice = eventstore.readStreamEventsForward("stream", position, 1028, false).join(); events.addAll(slice.events); position = slice.nextEventNumber; } while (!slice.isEndOfStream);
Thanks for the hints I will try that. Of course your proposed solution regarding iterators/splitterators would be fine. Thanks! Regards Oliver
now throws specific exceptions StreamNotFoundException
or StreamDeletedException
instead of IllegalStateException
Hi
Thanks for the great library!
I'm trying to implement my first event sourcing application using DDD. I have a repository with a get(id) method. In this method I try to load an aggregate by id (each stream represents an aggregate). If the stream does not exist I want to return 'null'. However with eventStore.streamEventsForward() I get "java.lang.IllegalStateException: Unexpected read status: StreamNotFound".
I would like this method to return a specific exception. Is this intentionally implemented this way? An additional check to see whether the stream exists would cause another roundtrip which I want to avoid.
Could you throw a specific exception? Or do you want me to create a pull request?
Heres my code: `List domainEventList = null;
try {
domainEventList = eventStore.streamEventsForward(streamId.getValue(), 0, 4096, false) //
.map(e -> toObject(e)).collect(Collectors.toList());
As you can see I'm returning null if I get an exception, but this is just a workaround.
Regards Oliver