【发布时间】:2015-02-25 23:16:24
【问题描述】:
我一直在使用带有 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>())
}
有哪些替代 Saga 实现类似但未连接到 MQ 架构?我想我真正在寻找的是至少具有内存持久存储的状态机或 Saga 实现。
【问题讨论】:
-
您可以单独使用 Automatonymous,与 MassTransit 完全分离。事实上,NHibernate 集成也是一个单独的库。
-
@ChrisPatterson 您能否举个例子回答这个问题。我有或多或少与 OP 相同的问题,但很难找到一个完整的持久性示例。谢谢!
标签: .net state-machine masstransit saga