Read event from EventStore when using GenericJpaRespository per aggregate

Hi,
We are using AxonFramework 3.1.1 with Spring Boot 1.5.16.

I would like to retrieve events from EventStore to resend them (through different channels then usually) in case of infrastructure problems or bugs.

We are not using event sourcing, but our aggregates’ state is stored twice:

  • in JPA repository per aggregate (with @Aggregate(repository = “myAggregateRepository”) where myAggregateRepository is GenericJpaRepository)

  • using JpaEventStorageEngine, as list of events in domain_event_entry DB table.

We are using axon-spring-boot-starter to simplify configuration so I simply inject EventStore when I am trying to retrieve events from EventStore like this:


  DomainEventStream domainEventStream = eventStore.readEvents('5e9fdeff-acfc-40a0-8e7c-074a733240e8');
  EventMessage<?> eventMessage = domainEventStream.next();

However, it is failing with “java.util.NoSuchElementException: No value present” in EventUtils when trying to construct GenericDomainEventMessage, because AggregateType is null. It is indeed not set in database.

Exception:

`

java.util.NoSuchElementException: No value present
at java.util.Optional.get(Optional.java:135)
at org.axonframework.eventsourcing.eventstore.EventUtils.lambda$upcastAndDeserializeDomainEvents$1(EventUtils.java:120)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at org.axonframework.eventsourcing.eventstore.BatchingEventStorageEngine$EventStreamSpliterator.tryAdvance(BatchingEventStorageEngine.java:167)
at java.util.stream.StreamSpliterators$WrappingSpliterator.lambda$initPartialTraversalState$222(StreamSpliterators.java:294)
at java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.fillBuffer(StreamSpliterators.java:206)

`

I understand that AggregateType is not set, because we have aggregate repository implemented with GenericJpaRespository and event is stored in DB with AggregateType set to null.
Is there any other way to retrieve event from the database with this type of configuration (when AggregateType is not set)? Another solution would be to store AggregateType - is it possible to configure Axon to do that without event sourcing?

Mariusz

How about simply creating an EventHandler that resends the event ?

@ProcessingGroup(“myEventResender”)
@Component
public class EventResender{
@EventHandler
public void resend(EventType event){
… send event
}

}

And if you want to send those events from the beginning:

EventProcessingConfiguration config;

config.eventProcessor(“projections”)
.ifPresent ( projections -> {
projections.shutDown()
projections.resetTokens()
projections.start()
});

Small mistake:

config.eventProcessor(“projections”)

should be

config.eventProcessor(“myEventResender”)

Hi David,
Thanks for replying.
Unfortunately, it will not work for me. I need to pick and retrieve only specific events (by UUID). Tracking processor is not something I am looking for.I just need to retrieve event from EventStore by UUID.

Hi Mariusz, David,

The aggregateType is omitted, since (in Axon Framework internal terms), your not publishing DomainEventMessages, but regular EventMessages, if you’re not using Event Sourcing for your aggregates.
What’s meant with that inside the framework, is that the events do not originate from a (in pre Axon 3.2 situation) Event Sourced Domain object, but from a regular source.
This thus means you cannot use the API to retrieve an EventStream per Aggregate, which leaves you with the openStream function that’ll return the entire stream.

However, we did resolve this discrepancy in the life cycle of Axon 3.
Axon 3.2 already resolves this problem and actual publishes DomainEventMessages for ‘State Stored Aggregates’.
Hence, in Axon 3.2 or above, you are able to have a StateStored Aggregate and read an Event Stream based on the aggregate identifier from the EventStore.

I’d this like to suggest you’d upgrade to a more recent version than Axon 3.1.1.
The latest Axon 3 version is 3.4.2, whilst we’re mostly developing for Axon 4 at the moment (where the latest version is 4.0.3).

This however does no resolve your current predicament, as you already have events being stored as regular event messages rather than domain event message

.For that, I’d likely pair the version upgrade with an update to your event store, to include the aggregate type to all the events your’e certain of they’re part of a specific aggregate.

I am aware that the suggested update is not ideal, but I can’t currently think of another thorough solution to your problem.

Hope this helps Mariusz!

Cheers,
Steven

Hi Steven,
Thank you for very clear answer.
I will follow your advice and plan update to Axon 3.4.2. For existing events I will start with setting the type to “undefined” in the database. This way I will be able to read events from event store.

Mariusz