I am using Axon v3.0.7 and have below aggregate and command.
`
`
`
@Aggregate
class AggregateRoot {
@AggregateIdentifier
private String id;
@CommandHandler
public AggregateRoot(CreateAggregateCmd cmd) throws Exception {
String uid= UUID.randomUUID().toString();
AggregateCreatedEvent event = new AggregateCreatedEvent(appId);
event.setAgentId(cmd.getAgentId());
apply(event);
}
}
class AggregateCreatedEvent {
//No targetidentifier field, as we construcing id in AggregateRoot constructor
String description;
}
I am using Aggregate constructor as Command Handler.
The same code works well using SimpleCommandBus ( with Spring Boot).
However, When upgraded to DistribuedCommandBus its throwing below error.
org.axonframework.commandhandling.distributed.CommandDispatchException: The command [CreateAggregateCmd] does not contain a routing key.
at org.axonframework.commandhandling.distributed.AbstractRoutingStrategy.getRoutingKey(AbstractRoutingStrategy.java:57)
at org.axonframework.springcloud.commandhandling.SpringCloudCommandRouter.findDestination(SpringCloudCommandRouter.java:91)
at org.axonframework.commandhandling.distributed.DistributedCommandBus.dispatch(DistributedCommandBus.java:124)
at org.axonframework.commandhandling.gateway.AbstractCommandGateway.send(AbstractCommandGateway.java:79)
at org.axonframework.commandhandling.gateway.DefaultCommandGateway.send(DefaultCommandGateway.java:95)
at org.axonframework.commandhandling.gateway.DefaultCommandGateway.send(DefaultCommandGateway.java:143)
We can update command to have TargetAggregateIdentifier and fix this issue.
Will there any other workaround to make same code work for both SimpleCommandBus & DistributedCommandBus ?
Thanks
`