Axon Implementation of Mark Nijhof's CQRS Example

Hi everybody,

I implemented Mark Nijhof’s CQRS Example in Axon. It will be useful to new users I hope. New use cases will be added and some improvements are on the way.
Your feedback is welcome to discover problems and improve the codebase. Any comments, bug reports, patches would be helpful to make it a better Axon sample.

https://code.google.com/p/nijhof2axon/

Cheers,
Bahadır Konu

Hi Bahadir

Nice example and i could get it running ;-). Its not that easy to
setup the infrastructure when you don't know a lot about Spring. So
thank you for the example.

Well, i have some questions and here is the first one:

You share the Data between the Domain and the Query Model?
The (generated?) table domainevententry looks like you can not replay
the events - missing the event data?

Before i start a "cqrs" Projekt i want to know what happens with
infrastructure, commands and events... if i can force the query
database to have a invalid state (and how to avoid that ;-), how to
replay events to integrate new features, how i can monitor the system
(maybe the command and event queue)... The infrastructure makes me
more worried then the "domain" :wink:

Cheers, Reto

Hi Reto,

You share the Data between the Domain and the Query Model?

I dont fully understand what you mean but,
When a command is dispatched, a CommandHandler uses the aggregate root to handle the command. Aggregate root fires DomainEvents.
=> Query layer related code listens to domain events and updates the query model. (Example: ClientTableUpdater)

Domain entities are first class objects but Query Model classes are just DTOs with getters and setters. We have Client as entity and ClientDetailsEntry as DTO.

The (generated?) table domainevententry looks like you can not replay e events - missing the >>event data?

To observe how events are replayed by the framework, you can follow these steps:

Click on sample client
change name
change name
stop server
put a breakpoint to EventSourcingRepository.doLoad() method
put a breakpoint to Client.handleClientNameChangedEvent() method
start server in debug mode
open the client that you changed
change name
=> you stop at the doLoad() breakpoint

reach to this line:

aggregate.initializeState(…

Here the events will be replayed to initialize aggregate state.
=> hit the breakpoint of Client.handleClientNameChangedEvent()

So, we have to implement the handlers that handle state changes properly.

if i can force the query database to have a invalid state

You can do that by not listening to domain events and not updating query tables. So updating the query tables properly is our duty.

how to replay events to integrate new features

I added a test class to nijhof2axon. Please have a look at SampleEventVisitorTest

how i can monitor the system (maybe the command and event queue)

I would use Log4J logs (and maybe AOP techniques not to pollute the code.)

There seems to be an org.axonframework.auditing.AuditingInterceptor class but I haven’t ever used that.

Cheers,
Bahadır Konu
http://twitter.com/bahadir_konu

17 Aralık 2011 19:25 tarihinde Reto <reto.fabbri@gmail.com> yazdı: