Setup Axon 4.4 + axon-cdi 4.0-alpha1

Hello all,

For some days I am fighting to have my setup to work. I want to try out a configuration without Spring.

I have a very simple setup with JPA event store and it seems to work since the error I am facing is not what my test says:

My fixtureConfiguration test works as expected

fixture
    .given()
    .when(new CreateEmployee(new EmployeeId("1234"), "John", "Constantine", LocalDate.now()))
    .expectSuccessfulHandlerExecution()
    .expectEvents(
        new EmployeeCreated(new EmployeeId("1234"), "John", "Constantine", LocalDate.now()));

But when I ran it locally I got the following error:

Resulted in: org.jboss.resteasy.spi.UnhandledException: org.axonframework.commandhandling.NoHandlerForCommandException: No handler was subscribed to command [com.acme.poc.hr.command.application.employee.commands.CreateEmployee]

My config so far:

@Produces
public EventStorageEngine eventStorageEngine() {
    return JpaEventStorageEngine.builder()
        .entityManagerProvider(entityManagerProvider)
        .eventSerializer(JacksonSerializer.defaultSerializer())
        .build();
}

@Produces
public Configuration axonConfiguration() {
    return DefaultConfigurer.defaultConfiguration()
        .configureCommandBus(
            config ->
                AsynchronousCommandBus.builder()
                    .transactionManager(NoTransactionManager.INSTANCE)
                    .messageMonitor(
                        config.messageMonitor(AsynchronousCommandBus.class, "commandBus"))
                    .build())
        .configureEventStore(
            conf -> EmbeddedEventStore.builder().storageEngine(eventStorageEngine()).build())
        .start();
}

I didn’t find any code sample with a complete config for non-spring or non-AxonServer projects, someone face the same or is trying something similar?

Hello Rogério,

Could you also share the code snippet with the CommandHandler for the CreateEmployee command?

Thanks,

Yvonne

Hi @Yvonne_Ceelie!

Here you have:

import org.axonframework.cdi.stereotype.Aggregate;
import org.axonframework.commandhandling.CommandHandler;
import org.axonframework.eventsourcing.EventSourcingHandler;
import org.axonframework.modelling.command.AggregateIdentifier;

@Aggregate
public class Employee {

  @AggregateIdentifier private EmployeeId id;
  private String name;
  private String surname;
  private LocalDate birthday;

  @CommandHandler
  public Employee(CreateEmployee createEmployee) {
    apply(
        new EmployeeCreated(
            createEmployee.getEmployeeId(),
            createEmployee.getName(),
            createEmployee.getSurname(),
            createEmployee.getBirthday()));
  }

  @EventSourcingHandler
  public void on(EmployeeCreated event) {
    this.id = event.id();
    this.name = event.name();
    this.surname = event.surname();
    this.birthday = event.birthday();
  }

  public Employee() {
    // Axon required
  }

Trying to troubleshoot the issue it seems that command handler was not recognized and as result not added in the subscriptions Map.

Does the CreateEmployee have the id annotated with TargetAggregateIdentifier?

I thought I have also added this one:

public class CreateEmployee {
  @NotBlank @AggregateIdentifier private final EmployeeId employeeId;

  @NotBlank(message = "Name cannot be blank")
  private final String name;

  @NotBlank(message = "Surname cannot be blank")
  private final String surname;

  @NotNull
  @PastOrPresent(message = "The birthday cannot be on future")
  private final LocalDate birthday;

//constructor suppressed
//getters suppressed

}

You should use the TargetAggregateIdentifier instead of AggregateIdentifier there.

Doh! Stupid mistake, even though I have the same issue.

Is there something else needed to register a command handler?

I tried before to register manually in the config using registerCommandHandler and configureAggregate but I got the same issue

Do you use the same commandBus implementation in your test as the one on which the handler is registered?

I have no special config for testing, I am just using the regular fixture

class EmployeeTest {

  private FixtureConfiguration<Employee> fixture;

  @BeforeEach
  public void setup() {
    fixture = new AggregateTestFixture<>(Employee.class);
  }

Make sense to share my project? Is it just a PoC there is no privacy or business secret to prevent any sharing

Yes, that’s fine I’ll take a look.

Hi @Yvonne_Ceelie I would like to thank you for any advise that can help here

The code is hosted here

The steps I am using to run it are:

  1. docker-compose up
  2. ./gradlew clean quarkusDev
  3. curl -v -H “Content-Type: application/json” -d ‘{“employeeId”: “1235”, “name”: “John”, “surname”: “Constantine”, “birthday”: “1970-10-23”}’ localhost:8080/v1/employee

I have no issues running Axon with Spring + Mongo, but this new setup I am trying is really tough