如何获取在 Axon 错误处理程序中产生错误的事件处理程序?

huangapple go评论63阅读模式
英文:

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&lt;*&gt;, 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.

huangapple
  • 本文由 发表于 2020年8月13日 19:07:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/63393836.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定