Eventstore not ready after ContextRefreshedEvent

Hi, I’m trying to iterate all events from a certain type that are available in the eventstore. In a Spring CommandLineRunner, I do:
val events = eventStore.openStream(null)
while (events.hasNextAvailable()) {
val eventMessage = events.nextAvailable()

When I debug, there are events, when I do not debug, no events. So, I thought: the eventstore is not initialized yet, so I waited for the ContextRefreshedEvent. However, the eventstore still has no events when not debugging.
Any tips, anyone?

Regards, R. Olsthoorn.

Note that 'hasNextAvailablechecks if there is an event available (locally) for immediate consumption. If that's not the case, it returnfalse. When you're not debugging, the hasNextAvailable` is probably invoked before the first messages made their way to the local machine.

Instead, you could use hasNextAvailable(5, SECONDS). This waits for events to become available for at most 5 seconds. You can pick any timeout that suits your needs.

1 Like