replay on the AbstractAnnotatedAggregateRoot does not seem to work

Hi List,

I’ve been using axon for quite a while now in a setup with scala and scynapse - some code to glue scala and axon together in a friendly way.
This setup uses 2 replay clusters that update the views and a cluster that does not replay (for sending mails and stuff)
The default cluster ( <axon:cluster id=“default” default=“true”/> ) has no additional replay config.

As far as I am aware, this setup used to replay events on the Aggregate Root. Somehow, the @EventHandler isn’t called anymore.
Did someone see this behaviour before - or - has a hint in what direction I may look for a solution ?

Kind regards,
Olger

Hi,

aggregates aren’t (re)constructed through a Cluster. An Aggregate’s event handlers are only invoked when it is loaded from the event store.
Only beans that don’t implement EventListener or AggregateRoot are automatically subscribed to an Event Bus. If you implement EventListener, you must subscribe it yourself. Subscribing an Aggregate to an EventBus wouldn’t make much sense, as aggregates should only react to commands (and their own events, if they’re event sourced).

Cheers,

Allard

Cheers,

Allard

Hi Allard,

Intresting as it seems that my aggregate root is not reacting on its own events during a replay (it is when it is handling commands in a normal way)

What are the options to check what is going on ?

Kind regards,

Olger

What do you mean with ‘the replay’? Are you replaying on a cluster?

Hi Allard,

Let’s see if I am able to explain this without getting into definition problems.

When my app is started, all events are replayed based on this configuration:

<axon:cluster id=“default” default=“true”/>

<axon:cluster id=“identityCluster” order=“0”>
<axon:replay-config event-store=“eventStore” />
axon:selectors
<axon:package prefix=“com.giffdiff.identity.view”/>
</axon:selectors>
</axon:cluster>

<axon:cluster id=“projectCluster” order=“0”>
<axon:replay-config event-store=“eventStore” />
axon:selectors
<axon:package prefix=“com.giffdiff.project.view”/>
</axon:selectors>
</axon:cluster>

<axon:cluster id=“invitationMailerCluster” order=“0”>

axon:selectors
<axon:package prefix=“com.giffdiff.identity.usercommunication”/>
<axon:package prefix=“com.giffdiff.project.usercommunication”/>
</axon:selectors>
</axon:cluster>

This works fine for the views (found in the *.view sub packages)

The events are not re-send to the AggregateRoot instance though, this instance contains some event handling like: (Aggregate is named UserAccount)

@EventHandler
def on(e : AccountCreated) {
log.debug(“called “ + e)
id = e.accountId
email = e.email
fullName = e.name
bcryptedPassword = e.password
}

that expects the id, email, fullName and password to be kept with the state of the specific instance of this aggregate.

Now, after startup, it seems that these events were not called and the internal state of the aggregate is not as it should be.

Till now, my assumptions comes from the debug log message that is shown when you have the application in normal running mode and a command fires an AccountCreated event (CreateAccount command), the log message is shown.
When you re-start the application (Event stored via JPA in mysql, JVM process gone and created again), the log message is not shown.

Does this help to explain the issue ?

Kind regards,

Olger

That’s because aggregates aren’t reconstructed by replaying a cluster. Aggregate state is constructed when it is loaded from the repository. And that happens when a command is sent that targets it.

Ah, clear. Thanks for your explanation. Must say that it makes me wonder how snaphots work