简体   繁体   English

我可以将奥尔良用于过程演员/谷物吗?

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

I am playing with Orleans but instead of relying on network and hence the configuration of endpoints I would rather like to be able to have grains in process in the code below: 我正在与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);
    }
}

Is it possible? 可能吗?

It is totally possible to use Orleans as a single process without clustering (which I did during testing and pre-production stages), but you will lose availability. 完全可以将Orleans用作单个过程而无需群集(这是我在测试和预生产阶段所做的),但是您将失去可用性。

Silos are supposed to be running as long-running processes in a cluster so ~30 seconds startup time of a single node should never be an issue for cloud environments. 筒仓应该作为长时间运行的进程在集群中运行,因此单个节点的启动时间约30秒对于云环境而言绝对不是问题。 If you need a single-host actor system, akka.net might be a better solution 如果您需要单主机演员系统,则akka.net可能是一个更好的解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM