我正在尝试使用 Automatonymous 和 RabbitMQ 为状态机实现一个简单的示例/演示。不幸的是,我找不到一个可以重建/学习的东西(我找到了ShoppingWeb,但在我看来它绝不简单)。同样在我看来,文档缺乏信息。
这是我想到的状态机示例(对不起,它很丑):
请注意,这个例子完全是虚构的,它是否有意义并不重要。这个项目的目的是让 Automatonymous 变得“温暖”。
我想做/拥有的是:
我的状态机实现如下所示:
public class InterpreterStateMachine : MassTransitStateMachine<InterpreterInstance>
{
public InterpreterStateMachine()
{
InstanceState(x => x.CurrentState);
Event(() => Requesting, x => x.CorrelateBy(request => request.Request.RequestString, context => context.Message.Request.RequestString)
.SelectId(context => Guid.NewGuid()));
Event(() => Validating, x => x.CorrelateBy(request => request.Request.RequestString, context => context.Message.Request.RequestString));
Event(() => Interpreting, x => x.CorrelateBy(request => request.Request.RequestString, context => context.Message.Request.RequestString));
Initially(
When(Requesting)
.Then(context =>
{
context.Instance.Request = new Request(context.Data.Request.RequestString);
}) …Run Code Online (Sandbox Code Playgroud)