我一直在使用带有 MassTransit 的自动状态机。我喜欢使用那个状态/传奇机器,尤其是它是如何配置和设置的,以及我可以为状态机提供实现合约以用作消息的事件。
这就是它的样子:
//define the statemachine with a State class (ServiceState)
public class ServiceStateMachine :
AutomatonymousStateMachine<ServiceState>{
//define available states
public State Available { get; set; }
public State WaitForItem { get; set; }
//define available events
public Event<RequestItem> RequestItem { get; set; }
//configure the state machine and configure the store to use the ServiceState class
public void ConfigureStateMachineCorrelations(StateMachineSagaRepositoryConfigurator<ServiceState> r)
//bind events to contracts and conditions
r.Correlate(RequestItem,
(state, message) =>
state.CorrelationId == message.CorrelationId)
}
public ServiceStateMachine(IStateMachineActivityFactory activityFactory
{
State(() => Available);
State(() => WaitForItem);
Event(() => RequestItem);
//bind states, events, activities, custom actions...
During(Available,
When(RequestItem)
.Then((state, message) =>
{
state.ServiceId = message.ServiceId; // just an example baby!
})
.TransitionTo(WaitForItem)
.Then(() => _activityFactory.GetActivity<RequestItemActivity, ServiceState>())
}
有哪些类似但未连接到 MQ 架构的替代 Saga 实现?我想我真正在寻找的是至少具有内存持久存储的状态机或 Saga 实现。