I'm building a simple application just to learn about CQRS and Axon
framework.
I have a main class where I'm initializing command and event bus.
Command is executed successfully and event is persisted, but event
listener doesn't fire.
CommandBus bus = new SimpleCommandBus();
SimpleEventBus eventBus = new SimpleEventBus();
I think the problem is in the command handler. Your wiring looks allright.
Currently, there is a feature missing that will be included in the 0.7 version. The problem you probably now have (it’s a guess, since command handler code is not included), is that new events are registered with your “UnitOfWork” (a.k.a. transaction), but they aren’t committed. Do you do a repository.save(modifiedAggregate) in your command handler? Alternatively, you can also do “CurrentUnitOfWork.commit()”. In the 0.7 release, you won’t have to do this anymore (see issue #94).
I see you do “save(new Customer(UUID.random…))”. Does this constructor do an “apply(someEvent)”?
What kind of repository is the CustomerRepository? If it is a GenericEventSourcingRepository, you could get in trouble, as it expects the constructor with UUID parameter to be one that doesn’t apply any events.
When you do, you should see the event being fired. The UUID-only constructor is used by the GenericEventSourcingRepository, and is used to create a non-initialized instance of an aggregate, in order to replay events on it.