英文:
How can I get the event handler that produced an error in a Axon Error handler?
问题
I just implemented a dead letter for errors handled in ListenerInvocationErrorHandler:
override fun onError(exception: Exception, event: EventMessage<*>, eventHandler: EventMessageHandler) {
// Insert in dead letter
}
This works ok, as I've got the information I need (exception, event and event handler), so I can reprocess by just invoking eventHandler.process(event).
However, for errors handled in ErrorHandler (normally persistence errors) I am missing event handler info:
override fun handleError(errorContext: ErrorContext) {
// No event handler info
}
Taking into account that each Event handler is isolated in a different Processing group, so each Event handler should run in its own transaction...
Is there any way to obtain the event handler that produced the error?
英文:
I just implemented a dead letter for errors handled in ListenerInvocationErrorHandler:
override fun onError(exception: Exception, event: EventMessage<*>, eventHandler: EventMessageHandler) {
// Insert in dead letter
}
This works ok, as I've got the information I need (exception, event and event handler), so I can reprocess by just invoking eventHandler.process(event).
However, for errors handled in ErrorHandler (normally persistence errors) I am missing event handler info:
override fun handleError(errorContext: ErrorContext) {
// No event handler info
}
Taking into account that each Event handler is isolated in a different Processing group, so each Event handler should run in its own transaction...
Is there any way to obtain the event handler that produced the error?
答案1
得分: 1
在ErrorHandler
级别,您“丢失”了事件处理程序信息,因为在Axon Framework中调用ErrorHandler
并不一定意味着实际调用了带有@EventHandler
注解的函数。
因此,在这一点上不能保证有任何事件处理程序。
此外,如果达到了ErrorHandler
,通常意味着事务(UnitOfWork
)将被回滚。因此,对于任何事件处理程序或事件处理组件,操作都将被调整。
因此,进入ErrorHandler
的异常本质上意味着应重新调用事件处理器中的所有事件处理程序。因此,了解确切的实例不是立刻必要的。
相反,您需要一个进程,定期/在调用时检查死信队列并调用给定事件处理器的所有处理程序,以重新处理给定的事件。
这是我对这种情况的看法,希望这对你有所帮助,Juan。
英文:
At the ErrorHandler
level you are "missing" the Event Handler info, as invoking the ErrorHandler
from within Axon Framework doesn't necessarily mean an actual @EventHandler
annotated function has been invoked.
Hence, there is no guarantee on that matter and as such no Event Handler is given at this point.
Additionally though, if the ErrorHandler
is reached that typically means the transaction (the UnitOfWork
) would be rolled back. Thus, for any event handler or event handling component, the operation would be adjusted.
Hence, an exception entering the ErrorHandler
essentially means all Event Handlers part of the Event Processor should be invoked again. As such knowing the exact instance wouldn't be an immediate necessity.
Instead, you would require a process which [periodically / on invocation] checks the dead letter queue and invokes all handlers for the given Event Processor to process the given event again.
That's my two cents to the scenario, hope this helps you out Juan.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论