gpt4 book ai didi

c# - MassTransit Saga 状态到实例状态映射

转载 作者:太空宇宙 更新时间:2023-11-03 18:56:46 30 4
gpt4 key购买 nike

我是 MassTransit 的新手,我似乎无法弄清楚它如何将我在 saga (MassTransitStateMachine) 上定义的状态映射到相关 SagaStateMachineInstance 类的“状态”属性。

例如,如果我有一个具有三个状态的状态机类:

public class MySaga :
MassTransitStateMachine<MySagaState>
{
public State Executing { get; private set; }
public State Completed { get; private set; }
public State Failed { get; private set; }
...
}

我的状态机实例类有一个“状态”属性

public class MySagaState : SagaStateMachineInstance
{
public Guid CorrelationId { get; set; }
public int State { get; set; }
}

MT如何决定哪个saga状态是哪个整数?

似乎还有两个内置的 saga 状态,“Initial”和“Final”,所以这个例子会有 5 个状态。 State 到整数的映射是如何完成的?

最佳答案

您需要指定状态,以便在状态机定义中为它们分配编号:

public class MySaga :
MassTransitStateMachine<MySagaState>
{
public MySaga()
{
InstanceState(x => x.State, Executing, Completed, Failed);
// 1 = Initial, 2 = Final, 3 = Executing, 4 = Completed
// 5 - Failed (1 & 2 are built-in states)
}

public State Executing { get; private set; }
public State Completed { get; private set; }
public State Failed { get; private set; }
...
}

关于c# - MassTransit Saga 状态到实例状态映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43220877/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com