Search code examples
axonsaga

Axon @EndSaga SagaEventHandler is not triggered at all, and @StartSaga SagaEventHandler is retried multiple times


I am trying to create a saga, and start this saga by triggering an event. However, after the event is triggered, I just get an endless loop for "claim on token". and it retries to execute this code all the time. and it just runs it after a few seconds.

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

My issue here is that I try to trigger @EndSaga event, but it never happened. I am sure the eventId is the same in the @StartSaga and @EndSaga, and both of the events are triggered in the right way since the corresponding event handlers are triggered elsewhere.

I'm not sure what I have missed here to make the @EndSaga triggered. Please help.

This the @Saga component

@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)
    }
}

And there are the outputs:



    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


Solution

  • Yes, adding @Transient above commandGateway in Saga makes it work like magic. Thanks
    Vaelyr