簡體   English   中英

我可以將奧爾良用於過程演員/谷物嗎?

[英]Can I use Orleans for in process actors / grains?

我正在與Orleans一起玩,而不是依靠網絡,因此不希望端點的配置,我希望能夠在下面的代碼中進行處理:

public interface IGreeter : IActorGrain
{
}

public class Greeter : DispatchActorGrain, IGreeter
{
    void On(Greet msg) => WriteLine($"Hello, {msg.Who}");
}

[SerializableAttribute]
public class Greet
{
    public string Who { get; set; }
}

public static class Program
{
    public static async Task Main()
    {
        WriteLine("Running example. Booting cluster might take some time ...\n");

        var host = new SiloHostBuilder()
            .Configure<ClusterOptions>(options =>
            {
                options.ClusterId = "localhost-demo";
                options.ServiceId = "localhost-demo-service";
            })
            .Configure<SchedulingOptions>(options =>
            {
                options.AllowCallChainReentrancy = false;
            })
            .Configure<SiloMessagingOptions>(options =>
            {
                options.ResponseTimeout = TimeSpan.FromSeconds(5);
                options.ResponseTimeoutWithDebugger = TimeSpan.FromSeconds(5);
            })
            .ConfigureLogging(logging =>
            {
                logging.SetMinimumLevel(LogLevel.Information);
                logging.AddConsole();
            })
            .UseDevelopmentClustering(options => options.PrimarySiloEndpoint = new IPEndPoint(IPAddress.Loopback, 30000))
            .ConfigureEndpoints(IPAddress.Loopback, 11111, 30000)
            .ConfigureApplicationParts(x => x
                .AddApplicationPart(Assembly.GetExecutingAssembly())
                .WithCodeGeneration())
            .UseOrleankka()
            .Build();

        await host.StartAsync();

        var client = new ClientBuilder()
            .Configure<ClusterOptions>(options => {
                options.ClusterId = "localhost-demo";
                options.ServiceId = "localhost-demo-service";
            })
            .UseStaticClustering(options => options.Gateways.Add(new IPEndPoint(IPAddress.Loopback, 30000).ToGatewayUri()))
            .ConfigureApplicationParts(x => x
                .AddApplicationPart(Assembly.GetExecutingAssembly())
                .WithCodeGeneration())
            .UseOrleankka()
            .Build();

        await client.Connect();

        var greeter = client.ActorSystem().ActorOf<IGreeter>("id");
        await greeter.Tell(new Greet {Who = "world"});

        Write("\n\nPress any key to terminate ...");
        ReadKey(true);
    }
}

可能嗎?

完全可以將Orleans用作單個過程而無需群集(這是我在測試和預生產階段所做的),但是您將失去可用性。

筒倉應該作為長時間運行的進程在集群中運行,因此單個節點的啟動時間約30秒對於雲環境而言絕對不是問題。 如果您需要單主機演員系統,則akka.net可能是一個更好的解決方案

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM