I have created a project springaxon with axon-spring-boot-starter for studying axonframework. . It works fine if I using event sourcing on command side. (In fact, because JPA is available, and bean userOrderRepository is not declared, an Event Store with a JPA Event Storage Engine is used by default) I can see the log "...received OrderCreatedEvent..." from query side. The following is related source code.

UserOrder.java:
@Aggregate
@Entity
public class UserOrder

AxonConfiguration.java:
//Do not declare a repository

I'd like JPA-based Repository on command side instead of event sourcing, so I annotated a repository for the aggregate, and declared this repository. The following is related source code.

UserOrder.java:
@Aggregate(repository="orderRepository")
@Entity
public class UserOrder

AxonConfiguration.java:
@Bean
@Autowired
public Repository<UserOrder> orderRepository(EntityManagerProvider entityManagerProvider, EventBus eventBus) {
    return new GenericJpaRepository<UserOrder>(entityManagerProvider, UserOrder.class, eventBus);
}  

But I cannot get the log "...received OrderCreatedEvent..." from query side this time.

I have no idea for this, any suggest is appreciated, thanks.

1

There are 1 answers

7
Steven On

Adjusting the type of repository you use for an aggregate shouldn't have any impact on the event bus capabilities, it just stores the events a little different.

The main adjustment it accompanies for events, is that they change from DomainEventMessages to regular EventMessags internally. The difference in this is that DomainEventMessages have aggregate specific field required for event sourcing your aggregate based on events. And since you prefer to not event source the aggregate, there is no longer the need to use those DomainEventMessages.

That said, they should still be stored and thus retrievable from you're query side.

Did you verify your events are still stored in the event store? Did you maybe also adjust your EventStore to an (Simple)EventBus? The default in Axon when using the Spring Boot starter dependency is an EmbeddedEventStore, which stores and sends events.