You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Axon框架:@EndSaga事件处理器未触发,@StartSaga反复重试问题

Axon框架Saga问题排查:@EndSaga未触发及Token重试循环

问题概述

基于Axon框架实现Saga,触发启动事件CreateTargetReferenceEvent后,出现「claim on token」无限循环,标注@StartSaga的事件处理器持续每隔几秒重试。核心问题是标注@EndSaga的UpdateTargetReferenceEvent处理器完全未触发,已确认两个事件的eventId一致,且两个事件均已正常触发(其他组件的对应事件处理器可正常执行)。

Saga组件代码

@Component
@Saga
internal class TestSaga {
    var testString: String = ""

    @Autowired
    private lateinit var commandGateway: CommandGateway
    
    @StartSaga
    @SagaEventHandler(associationProperty = "eventId")
    fun on(event: CreateTargetReferenceEvent) {
        println(event.eventId)
    }

    @EndSaga
    @SagaEventHandler(associationProperty = "eventId")
    fun on(event: UpdateTargetReferenceEvent) {
        println(event.eventId)
    }
}

相关日志输出

2022-11-01 21:49:10.529  WARN 11916 --- [agaProcessor]-0] o.a.e.TrackingEventProcessor             : Releasing claim on token and preparing for retry in 4s
Hibernate: update token_entry set owner=null where owner=? and processor_name=? and segment=?
2022-11-01 21:49:10.530  INFO 11916 --- [agaProcessor]-0] o.a.e.TrackingEventProcessor             : Released claim
Hibernate: update token_entry set timestamp=? where processor_name=? and segment=? and owner=?
Hibernate: update token_entry set timestamp=? where processor_name=? and segment=? and owner=?
Hibernate: update token_entry set timestamp=? where processor_name=? and segment=? and owner=?
Hibernate: select tokenentry0_.processor_name as processo1_7_0_, tokenentry0_.segment as segment2_7_0_, tokenentry0_.owner as owner3_7_0_, tokenentry0_.timestamp as timestam4_7_0_, tokenentry0_.token as token5_7_0_, tokenentry0_.token_type as token_ty6_7_0_ from token_entry tokenentry0_ where tokenentry0_.processor_name=? and tokenentry0_.segment=? for update
Hibernate: update token_entry set owner=?, timestamp=?, token=?, token_type=? where processor_name=? and segment=?
2022-11-01 21:49:14.536  INFO 11916 --- [agaProcessor]-0] o.a.e.TrackingEventProcessor             : Fetched token: null for segment: Segment[0/0]
Hibernate: update token_entry set token=?, token_type=?, timestamp=? where owner=? and processor_name=? and segment=?
Hibernate: select associatio0_.saga_id as col_0_0_ from association_value_entry associatio0_ where associatio0_.association_key=? and associatio0_.association_value=? and associatio0_.saga_type=?
baccd32c-1547-4621-a04c-3a5cb285a9af
2022-11-01 21:49:14.551  WARN 11916 --- [agaProcessor]-0] o.a.e.TrackingEventProcessor             : Releasing claim on token and preparing for retry in 8s
Hibernate: update token_entry set owner=null where owner=? and processor_name=? and segment=?
2022-11-01 21:49:14.553  INFO 11916 --- [agaProcessor]-0] o.a.e.TrackingEventProcessor             : Released claim

排查建议

  • 检查Saga关联与实例状态:

    1. 确认UpdateTargetReferenceEvent的eventId与启动事件的eventId完全一致,无大小写、格式差异。
    2. 查询association_value_entry表,验证对应eventId关联的Saga实例ID是否存在,且该实例在saga_entry表中状态正常(未被提前终止)。
  • 定位Token重试循环的根源:
    日志显示TrackingEventProcessor反复释放并重试Token,说明@StartSaga的处理器执行时存在未捕获异常或事务回滚:

    1. 检查on(CreateTargetReferenceEvent)方法是否有隐性异常(如println输出异常、CommandGateway注入失败等),可添加try-catch块捕获日志。
    2. 确认Saga处理的事务配置是否正确,若事务回滚,Saga实例无法持久化,后续Update事件无法匹配到对应实例,导致@EndSaga不触发。
  • 验证@EndSaga方法的有效性:

    1. 检查UpdateTargetReferenceEvent的类路径是否正确,避免因类加载器差异导致事件类型不匹配。
    2. 将Saga类及事件处理方法的访问修饰符改为public,避免Axon无法通过反射调用internal方法。
  • 检查事件处理顺序与Processor状态:
    TrackingEventProcessor卡在重试Create事件时,后续的Update事件会被阻塞处理。先解决Token重试问题,再验证@EndSaga是否触发。

内容的提问来源于stack exchange,提问作者user4816915

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 02:15:49