資源的建立有順序性,先有A才能有B,且B要建立完成A才算建立完成,否則A建立失敗。建立B時失敗則做補償交易的狀況。
plantuml
@startuml
participant client
participant app
database db
participant remote
skinparam sequenceMessageAlign center
skinparam ParticipantPadding 50
client ->> app : create request
activate app
app -->> client : accepted
app -> db : CREATE record A\n with state 'building'
activate db
db -->> app : success
deactivate db
|||
app -> remote : CREATE resource A
activate remote
remote -->> app : success
deactivate remote
|||
app -> db : CREATE record B\n with state 'building'
activate db
db -->> app : failed
note over db : record B not created
deactivate db
|||
app -> remote : DELETE resource A
note over remote : compensating transaction
activate remote
remote --> app : success
deactivate remote
|||
app -> db : UPDATE record A state\n to 'create-failed'
activate db
db -> app : success
deactivate db
|||
app ->> client : failed message
deactivate app
@enduml
動作步驟:
- create A record
- create A resource
- create B record (failed)
- delete A resource (compensating)
- update A record (compensating)
沒有留言:
張貼留言