I’m working on migrating an existent app from Java to Groovy.
Previously it has been working – being in pure Java.
There’s a lot of @EventHandler-annotated methods.
Everything is wired with Spring and <axon:annotation-config />
But only those in aggregate roots are called.
I have a @CompileStatic class F extends AbstractAnnotatedAggregateRoot
A method in class calls apply(K k)
There’s an @EventHandler handle(K k), and it is called
I have a @CompileStatic@Component class BooDtoMapper
There’s an @EventHandler handle(K k)
It never gets called!
I’m really stuck. Even don’t understand how to debug it.
The first class is not a bean, but it’s an aggregate root. It works.
The second class is a bean, not an aggregate. It do exist in AppContext, so bean is instantiated.
you’re probably best off debugging the “AbstractAnnotationHandlerBeanPostProcessor” class. Put a breakpoint in the “postProcessAfterInitialization” method and wait for your event handler bean to pass by. The isPostProcessingCandidate() method will probably return false. The trick would be to find out why.
I am not a groovy expert, so I can’t really provide more detail than this, for now.
Good luck.
it should be fairly easy to debug the dispatching of the handlers. If you can see it’s properly registered, just put a breakpoint in the EventBusTerminal. It will iterator over all clusters, which will iterate over each registered handler.
There must be a very obvious reason why hour handlers isn’t called. We’ll find it.
Well, for some reason I wasn’t able (and still not able) to connect Idea debugger to my app running on Tomcat with Gradle. Debugger connects, but never stops on breakpoints. So I was debugging like we were doing it a century ago: with println, copy-pasting external code in case of private modifiers.
Ugly, slow, but always works.
Finally I found the problem. It’s related both with Groovy and Axon, I think.
Groovy. Comparable interferes with @EqualsToAndHashCode, leading to a stack overflow. So the code has thrown exception during committing the changes of aggregate root: that’s why only aggregate’s handlers were called.
Axon. It ignores the failure, prints nothing to console, and just keeps working. It was really hard to notice the concrete piece of failing code. And – stack overflow exception is quite a weird one…
What was I expecting – given that I have more Akka experience. I thought it will force me to make my decisions on case of failure, like with Supervisor in Akka.
It looks like exceptions in both command and event handlers are usually ignored, in docs it’s said that you should avoid throwing exceptions in handlers.
Well, of course I should, but this one was an… exception
Allard, thanks a lot for your assistance! Your advice finally moved me ahead