我试图创造一个传奇,并通过触发事件开始这一传奇。然而,在事件被触发后,我只会得到一个无休止的循环,用于“令牌上的声明”。它总是尝试执行这段代码。几秒钟后它就能运行了。
@StartSaga
@SagaEventHandler(associationProperty = "eventId")
fun on(event: CreateTargetReferenceEvent) {
println(event.eventId)
}
我在这里的问题是,我试图触发@EndSaga事件,但从未发生过。我确信eventId在@StartSaga和@EndSaga中是相同的,这两个事件都是以正确的方式触发的,因为相应的事件处理程序是在其他地方触发的。
我不知道我错过了什么让@EndSaga触发。请帮帮忙。
这是@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
发布于 2022-11-02 06:40:13
正如Vaelyr所说,不要使用@Component
。它不是一个组件,因为它有一个不同的生命周期。通常使用Saga,您可以在不同的集合上进行编排。因此,UpdateTargetReferenceEvent
将由佐贺发送的命令触发。
https://stackoverflow.com/questions/74275584
复制相似问题