AbstractAggregateRoot (no event sourcing)

Hi,

I have a @CommandHandler on a constructor where I want to create an aggregate.
In this constructor I create a new event and do registerEvent(evt).

When I put a command on the eventBus it gets picked up by the commandhandler but not by the EventHandler. Is there a step I am missing?

Kind regards,
Kevin

Hello Kevin,
Here’s a simple implementation that might perhaps help you figure out what your issue is…

Without seeing any sort of code sample, my best guess is that you’re missing an annotation on your event handler.
Hope this helps.

@Aggregate
public class MyAggregate {
public MyAggregate() {}

@CommandHandler
public MyAggregate(CreateMyAggregate cmd) {
AggregateLifecycle.apply(new MyAggregateCreated(cmd.getId()));
}

@EventSourcingHandler
public void myAggregateCreated(MyAggregateCreated event) {
setId(event.getId());
}
}

Hello again,
I realized after-the-fact that you specified “no event sourcing”. I haven’t tried that out before, but I did look in the documentation for answers. Did you register your event handler? eg. annotating class as @Component with @EventHandler annotated methods.

ICYMI… Notice that the aggregate only has a @CommandHandler.

@Entity // Mark this aggregate as a JPA Entity

public class MyAggregate {

@Id // When annotating with JPA @Id, the @AggregateIdentifier annotation
// is not necessary
private String id;

// fields containing state…

@CommandHandler
public MyAggregate(CreateMyAggregateCommand command) {
// … update state
apply(new MyAggregateCreatedEvent(…));
}

// constructor needed by JPA
protected MyAggregate() {
}
}

Hi Kevin,

which version of Axon do you use? “registerEvent” doesn’t exist anymore in Axon 4.

I’m not completely clear on the problem. Do you mean you put an event on the event bus, which isn’t picked up in an event handler?

Allard