【问题标题】:Saving state that resides in POCO/DTO using Actor Model使用 Actor 模型保存驻留在 POCO/DTO 中的状态
【发布时间】:2015-12-30 10:53:24
【问题描述】:

我一直在寻找一些用例或代码示例,以说明如何使用执行业务逻辑的 Actor 模型保存驻留在简单 DTO/POCO 模型类中的状态。

谢谢

【问题讨论】:

    标签: akka poco dto orleans actor-model


    【解决方案1】:

    我只能回答奥尔良。

    有一些示例显示了保持状态所需的各个部分:

    https://github.com/dotnet/orleans/tree/master/Samples/StorageProviders

    基本上,您创建一个类来存储您的颗粒状态,如下所示:

    public class MyState : GrainState
    {
      public string StringValue { get; set; }
      public int IntValue { get; set; }
      public DateTime DateTimeValue { get; set; }
      public Guid GuidValue { get; set; }
      public IGrain1 GrainValue { get; set; }
    }
    

    (好吧,这不是 POCO)

    然后你可以创建一个使用这个类作为它的状态的grain:

    [ StorageProvider( ProviderName = "myprovider" ) ]
    public class Grain1 : Grain< MyState >, IGrain1
    {
      public Task Set( string stringValue, int intValue, DateTime dateTimeValue, Guid guidValue, IGrain1 grainValue )
      {
        State.StringValue = stringValue;
        State.IntValue = intValue;
        State.DateTimeValue = dateTimeValue;
        State.GuidValue = guidValue;
        State.GrainValue = grainValue;
        return WriteStateAsync();
      }
    }
    

    用于实际存储状态的底层机制是一个配置选项。开箱即用的 Azure 表存储,但还有其他几个选项,包括 Redis、Azure Blob 存储和 SQL Server。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-04
      • 2010-10-28
      • 2013-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多