I have the below error when i send the CreateAgent command
org.axonframework.commandhandling.NoHandlerForCommandException: No matching handler available to handle command [com.test.domains.partner.api.CreateAgent]. To find a matching handler, note that the command handler’s name should match the command’s name, and all the parameters on the command handling method should be resolvable. It is thus recommended to validate both the name and the parameters.
@Aggregate
open class PartnerAggregate() {
@AggregateIdentifier
lateinit var partnerId: String
}
@Aggregate
class AgentAggregate() : PartnerAggregate() {
@CommandHandler
@CreationPolicy(AggregateCreationPolicy.CREATE_IF_MISSING)
fun handle(command: CreateAgent) {
}
}
Based on your title, the CreateAgent command is either an abstract class or interface. This means that the aggregate is able to handle a command with the name com.example.mypackage.CreateAgent.
The message your are sending is a concrete class. I can imagine something like com.example.mypackage.CreateApmAgent. The command will also have that name.
By sending a CommandMessage with the proper name, you can match the correct handler. You can do this in the following manner: new GenericCommandMessage(new GenericCommandMessage(payload), "com.example.mypackage.CreateAgent")).