Hey there! I’m running into a strange issue with Axon Framework in a small proof-of-concept application I’m working on to try out various features. Here’s the components I’m using:
- Axon Server 4.5.5
- Axon Framework 4.5
- Axon Reactor Plugin 4.5
- Spring Boot 2.5.2
- Kotlin 1.4.32
I have a WebFlux controller set up that sends a command on the command gateway to create new instances of the aggregate, like so:
@PostMapping
fun createNewUser(@Valid @RequestBody user: NewUserRequest): Mono<UUID> {
require(!user.username.isNullOrBlank() || !user.emailAddress.isNullOrBlank()) { "A user must provide a username or email address." }
require(user.firstName.isNotBlank() && user.lastName.isNotBlank()) { "First name and last name cannot be blank." }
val newUserCommand = CreateUserCommand(
user.username ?: user.emailAddress ?: throw NullPointerException("Expect username or password"),
user.firstName,
user.lastName,
user.emailAddress
)
return commandGateway.send<User>(newUserCommand).map { it.id }.toMono()
}
On the aggregate side, I have a command handler set up on the constructor to handle the creation of the aggregate:
@Aggregate
class User() {
@AggregateIdentifier
lateinit var id: UUID
var state = UserState.Closed
@AggregateMember(eventForwardingMode = ForwardMatchingInstances::class)
val productSubscriptions = mutableMapOf<Product, Subscription>()
@CommandHandler(payloadType = CreateUserCommand::class)
constructor(command: CreateUserCommand, validationErrors: Errors): this() {
require(command.username.isNotBlank() && command.username.length > 6) { "Username must be greater than six characters in length." }
require(command.firstName.isNotBlank() && command.lastName.isNotBlank()) { "First name and last name are required." }
handleValidationErrors(validationErrors)
applyEvent(NewUserEvent(UUID.randomUUID(), command.username, command.firstName, command.lastName, command.emailAddress))
}
...
}
When I start the application, I can see from the logs that the command handler is found and registered:
2021-07-21 13:09:52.130 DEBUG 9118 --- [ restartedMain] o.a.a.c.command.AxonServerCommandBus : Subscribing command with name [com.poc.model.commands.user.CreateUserCommand] to this distributed CommandBus. Expect similar logging on the local segment.
2021-07-21 13:09:52.147 INFO 9118 --- [ restartedMain] i.a.a.c.command.impl.CommandChannelImpl : CommandChannel for context 'default' connected, 0 command handlers registered
2021-07-21 13:09:52.149 INFO 9118 --- [ restartedMain] i.a.a.c.command.impl.CommandChannelImpl : Registered handler for command 'com.poc.model.commands.user.CreateUserCommand' in context 'default'
But when I invoke the endpoint and the command gets sent, Axon Server replies that it couldn’t find a command handler:
org.axonframework.commandhandling.CommandExecutionException: No handler available to handle command [com.poc.model.commands.user.CreateUserCommand]
Any recommendations on how I can further troubleshoot this? Is there something I’m missing in terms of how this is all tied together and set up that’s causing this issue? Thanks!