Hi, I'm just wondering why Axon implicitly instantiate another aggregate. This behavior causes multiple event handling and I don't think this overhead is expected.
Having this endpoint:
@PostMapping("ship")
public void shipOrder(@RequestBody Product product) {
String orderId = UUID.randomUUID().toString();
commandGateway.sendAndWait(new PlaceOrderCommand(orderId, product.getName()));
commandGateway.sendAndWait(new ConfirmOrderCommand(orderId));
}
and following aggregate:
@Aggregate
public class Order {
@AggregateIdentifier
private String orderId;
private boolean orderConfirmed;
@CommandHandler
public Order(PlaceOrderCommand command) {
System.out.println("Calling COMMAND constructor");
apply(new OrderPlacedEvent(command.getOrderId(), command.getProduct()));
}
protected Order() {
System.out.println("Calling PARAMLESS constructor");
}
@CommandHandler
public void handle(ConfirmOrderCommand command) {
apply(new OrderConfirmedEvent(command.getOrderId()));
}
@EventSourcingHandler
public void on(OrderPlacedEvent event) {
System.out.println(">>>>>> Handling OrderPlacedEvent: " + this);
this.orderId = event.getOrderId();
orderConfirmed = false;
}
@EventSourcingHandler
public void on(OrderConfirmedEvent event) {
System.out.println(">>>>>> Handling OrderConfirmedEvent: " + this);
orderConfirmed = true;
}
}
After calling endpoint once I'm getting this log:
Calling COMMAND constructor
>>>>>> Handling OrderPlacedEvent: Order@3eecb9e2
Calling PARAMLESS constructor
>>>>>> Handling OrderPlacedEvent: Order@cd10277
>>>>>> Handling OrderConfirmedEvent: Order@cd10277
As you can see OrderPlacedEvent is called twice, along with constructor without parameters. Anyone know why I'm experiencing following behavior?
I have a repository with this example: https://github.com/matty-matt/orders-axon
It would be nice of you to state why you opening and closing an issue, @matty-matt. Luckily, we monitor StackOverflow too and I noticed this question of yours which can and has been answered with "this is Event Sourcing at work".
Additionally, questions like this are better placed on StackOverflow or the user group, as we prefer to keep GitHub for feature requests and bugs.
Yes I should've explain why I closed this question. As you noticed I asked also on StackOverflow and got satisfying explanation. Next time I will turn my doubts to StackOverflow community first. Thanks.
Thank you for circling back @matty-matt, that's much appreciated. :-)
Hope to see more questions (or maybe feature requests?) from you in the future!