|
- # Licensed to the Apache Software Foundation (ASF) under one or more
- # contributor license agreements. See the NOTICE file distributed with
- # this work for additional information regarding copyright ownership.
- # The ASF licenses this file to You under the Apache License, Version 2.0
- # (the "License"); you may not use this file except in compliance with
- # the License. You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- Name: "OrderSaga"
- Version: "1.0"
- StartState: "CreateOrder"
- trans_operation_timeout: 30000
- States:
- CreateOrder:
- Type: "ServiceTask"
- serviceType: "local"
- serviceName: "orderService"
- serviceMethod: "createOrder"
- CompensateState: "CancelOrder"
- ForCompensation: false
- ForUpdate: false
- Retry:
- - Exceptions:
- - "OrderCreationException"
- - "InventoryUnavailableException"
- IntervalSeconds: 2
- MaxAttempts: 3
- BackoffRate: 1.5
- Catches:
- - Exceptions:
- - "OrderCreationException"
- - "InventoryUnavailableException"
- Next: "ErrorHandler"
- Status:
- "return.code == 'SUCCESS'": "SUCCEEDED"
- "return.code == 'FAIL'": "FAILED"
- "$exception{*}": "UNKNOWN"
- Input:
- - orderInfo: "$.orderInfo"
- Output:
- orderId: "$.#root"
- Next: "CheckStock"
- Loop:
- Parallel: 1
- Collection: "$.orderItems"
- ElementVariableName: "item"
- ElementIndexName: "index"
- CompletionCondition: "[nrOfInstances] == [nrOfCompletedInstances]"
-
- CheckStock:
- Type: "ServiceTask"
- serviceType: "local"
- serviceName: "inventoryService"
- serviceMethod: "checkAvailability"
- CompensateState: "RollbackStock"
- ForCompensation: false
- ForUpdate: false
- Retry:
- - Exceptions:
- - "StockCheckException"
- IntervalSeconds: 2
- MaxAttempts: 2
- BackoffRate: 1.2
- Catches:
- - Exceptions:
- - "StockCheckException"
- Next: "ErrorHandler"
- Status:
- "return.available == true": "IN_STOCK"
- "return.available == false": "OUT_OF_STOCK"
- "$exception{*}": "UNKNOWN"
- Input:
- - orderId: "$.orderId"
- - itemsList: "$.orderItems"
- Output:
- stockAvailable: "$.#root"
- Next: "DecideStock"
-
- DecideStock:
- Type: "Choice"
- Choices:
- - Expression: "stockAvailable == true"
- Next: "ReserveStock"
- - Expression: "stockAvailable == false"
- Next: "CancelOrder"
- Default: "ErrorHandler"
-
- ReserveStock:
- Type: "ServiceTask"
- serviceType: "local"
- serviceName: "inventoryService"
- serviceMethod: "reserveItems"
- CompensateState: "RollbackStock"
- ForCompensation: false
- ForUpdate: false
- Retry:
- - Exceptions:
- - "StockReservationException"
- IntervalSeconds: 2
- MaxAttempts: 2
- BackoffRate: 1.2
- Catches:
- - Exceptions:
- - "StockReservationException"
- Next: "ErrorHandler"
- Status:
- "return.code == 'RESERVED'": "STOCK_RESERVED"
- "return.code == 'FAILED'": "FAILED"
- "$exception{*}": "UNKNOWN"
- Input:
- - orderId: "$.orderId"
- - itemList: "$.orderItems"
- Output:
- stockReservationId: "$.#root"
- Next: "ProcessPayment"
-
- ProcessPayment:
- Type: "ServiceTask"
- serviceType: "local"
- serviceName: "paymentService"
- serviceMethod: "processPayment"
- CompensateState: "RefundPayment"
- ForCompensation: false
- ForUpdate: false
- Retry:
- - Exceptions:
- - "PaymentProcessingException"
- IntervalSeconds: 3
- MaxAttempts: 3
- BackoffRate: 1.5
- Catches:
- - Exceptions:
- - "PaymentProcessingException"
- Next: "ErrorHandler"
- Status:
- "return.code == 'PAID'": "PAYMENT_SUCCESS"
- "return.code == 'DECLINED'": "PAYMENT_FAILED"
- "$exception{*}": "UNKNOWN"
- Input:
- - orderId: "$.orderId"
- - amount: "$.orderTotal"
- Output:
- paymentTransactionId: "$.#root"
- Next: "CompleteOrder"
-
- CompleteOrder:
- Type: "Succeed"
-
- CancelOrder:
- Type: "ServiceTask"
- serviceType: "local"
- serviceName: "orderService"
- serviceMethod: "cancelOrder"
- ForCompensation: true
- ForUpdate: true
- Input:
- - orderId: "$.orderId"
- Output:
- cancelResult: "$.#root"
- Next: "RollbackStock"
-
- RollbackStock:
- Type: "ServiceTask"
- serviceType: "local"
- serviceName: "inventoryService"
- serviceMethod: "releaseItems"
- ForCompensation: true
- ForUpdate: true
- Input:
- - orderId: "$.orderId"
- - stockReservationId: "$.stockReservationId"
- Output:
- rollbackResult: "$.#root"
- Next: "RefundPayment"
-
- RefundPayment:
- Type: "ServiceTask"
- serviceType: "local"
- serviceName: "paymentService"
- serviceMethod: "refundPayment"
- ForCompensation: true
- ForUpdate: true
- Input:
- - orderId: "$.orderId"
- - paymentTransactionId: "$.paymentTransactionId"
- Output:
- refundResult: "$.#root"
- Next: "FailState"
-
- ErrorHandler:
- Type: "Fail"
- ErrorCode: "ORDER_PROCESSING_ERROR"
- Message: "订单处理过程中发生不可恢复的错误。"
-
- FailState:
- Type: "Fail"
- ErrorCode: "ORDER_CANCELLED"
- Message: "订单已取消,触发补偿完成。"
|