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.
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 regularEventMessags
internally. The difference in this is thatDomainEventMessages
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 thoseDomainEventMessages
.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 anEmbeddedEventStore
, which stores and sends events.