diff --git a/ProtoActor.sln b/ProtoActor.sln index b4977a0bdd..b7b021ce91 100644 --- a/ProtoActor.sln +++ b/ProtoActor.sln @@ -256,6 +256,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkyriseMiniClient", "benchm EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkyriseMiniServer", "benchmarks\SkyriseMini\Server\SkyriseMiniServer.csproj", "{7C08B7D5-90BD-45E9-BADF-1B6CEB1A3E97}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AspNetGrains", "AspNetGrains", "{85F44707-946F-453E-9969-E3CDA6CB8F3C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Node1", "examples\AspNetGrains\Node1\Node1.csproj", "{FBD971F3-689A-491D-986B-B9ADBE0656B6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Node2", "examples\AspNetGrains\Node2\Node2.csproj", "{296010B4-B52A-4049-9C0D-497B7AC21C32}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Messages", "examples\AspNetGrains\Messages\Messages.csproj", "{82D29895-93F1-4BD6-938D-7BEDD4D1D2BF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1274,6 +1282,42 @@ Global {7C08B7D5-90BD-45E9-BADF-1B6CEB1A3E97}.Release|x64.Build.0 = Release|Any CPU {7C08B7D5-90BD-45E9-BADF-1B6CEB1A3E97}.Release|x86.ActiveCfg = Release|Any CPU {7C08B7D5-90BD-45E9-BADF-1B6CEB1A3E97}.Release|x86.Build.0 = Release|Any CPU + {FBD971F3-689A-491D-986B-B9ADBE0656B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FBD971F3-689A-491D-986B-B9ADBE0656B6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FBD971F3-689A-491D-986B-B9ADBE0656B6}.Debug|x64.ActiveCfg = Debug|Any CPU + {FBD971F3-689A-491D-986B-B9ADBE0656B6}.Debug|x64.Build.0 = Debug|Any CPU + {FBD971F3-689A-491D-986B-B9ADBE0656B6}.Debug|x86.ActiveCfg = Debug|Any CPU + {FBD971F3-689A-491D-986B-B9ADBE0656B6}.Debug|x86.Build.0 = Debug|Any CPU + {FBD971F3-689A-491D-986B-B9ADBE0656B6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FBD971F3-689A-491D-986B-B9ADBE0656B6}.Release|Any CPU.Build.0 = Release|Any CPU + {FBD971F3-689A-491D-986B-B9ADBE0656B6}.Release|x64.ActiveCfg = Release|Any CPU + {FBD971F3-689A-491D-986B-B9ADBE0656B6}.Release|x64.Build.0 = Release|Any CPU + {FBD971F3-689A-491D-986B-B9ADBE0656B6}.Release|x86.ActiveCfg = Release|Any CPU + {FBD971F3-689A-491D-986B-B9ADBE0656B6}.Release|x86.Build.0 = Release|Any CPU + {296010B4-B52A-4049-9C0D-497B7AC21C32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {296010B4-B52A-4049-9C0D-497B7AC21C32}.Debug|Any CPU.Build.0 = Debug|Any CPU + {296010B4-B52A-4049-9C0D-497B7AC21C32}.Debug|x64.ActiveCfg = Debug|Any CPU + {296010B4-B52A-4049-9C0D-497B7AC21C32}.Debug|x64.Build.0 = Debug|Any CPU + {296010B4-B52A-4049-9C0D-497B7AC21C32}.Debug|x86.ActiveCfg = Debug|Any CPU + {296010B4-B52A-4049-9C0D-497B7AC21C32}.Debug|x86.Build.0 = Debug|Any CPU + {296010B4-B52A-4049-9C0D-497B7AC21C32}.Release|Any CPU.ActiveCfg = Release|Any CPU + {296010B4-B52A-4049-9C0D-497B7AC21C32}.Release|Any CPU.Build.0 = Release|Any CPU + {296010B4-B52A-4049-9C0D-497B7AC21C32}.Release|x64.ActiveCfg = Release|Any CPU + {296010B4-B52A-4049-9C0D-497B7AC21C32}.Release|x64.Build.0 = Release|Any CPU + {296010B4-B52A-4049-9C0D-497B7AC21C32}.Release|x86.ActiveCfg = Release|Any CPU + {296010B4-B52A-4049-9C0D-497B7AC21C32}.Release|x86.Build.0 = Release|Any CPU + {82D29895-93F1-4BD6-938D-7BEDD4D1D2BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {82D29895-93F1-4BD6-938D-7BEDD4D1D2BF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {82D29895-93F1-4BD6-938D-7BEDD4D1D2BF}.Debug|x64.ActiveCfg = Debug|Any CPU + {82D29895-93F1-4BD6-938D-7BEDD4D1D2BF}.Debug|x64.Build.0 = Debug|Any CPU + {82D29895-93F1-4BD6-938D-7BEDD4D1D2BF}.Debug|x86.ActiveCfg = Debug|Any CPU + {82D29895-93F1-4BD6-938D-7BEDD4D1D2BF}.Debug|x86.Build.0 = Debug|Any CPU + {82D29895-93F1-4BD6-938D-7BEDD4D1D2BF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {82D29895-93F1-4BD6-938D-7BEDD4D1D2BF}.Release|Any CPU.Build.0 = Release|Any CPU + {82D29895-93F1-4BD6-938D-7BEDD4D1D2BF}.Release|x64.ActiveCfg = Release|Any CPU + {82D29895-93F1-4BD6-938D-7BEDD4D1D2BF}.Release|x64.Build.0 = Release|Any CPU + {82D29895-93F1-4BD6-938D-7BEDD4D1D2BF}.Release|x86.ActiveCfg = Release|Any CPU + {82D29895-93F1-4BD6-938D-7BEDD4D1D2BF}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1392,6 +1436,10 @@ Global {DF09798D-20CC-418C-901B-DEFEEFF02E1B} = {0F3AB331-C042-4371-A2F0-0AFDFA13DC9F} {8B0466D8-C57E-4D29-98B3-CB2D087765DC} = {DF09798D-20CC-418C-901B-DEFEEFF02E1B} {7C08B7D5-90BD-45E9-BADF-1B6CEB1A3E97} = {DF09798D-20CC-418C-901B-DEFEEFF02E1B} + {85F44707-946F-453E-9969-E3CDA6CB8F3C} = {59DCCC96-DDAF-469F-9E8E-9BC733285082} + {FBD971F3-689A-491D-986B-B9ADBE0656B6} = {85F44707-946F-453E-9969-E3CDA6CB8F3C} + {296010B4-B52A-4049-9C0D-497B7AC21C32} = {85F44707-946F-453E-9969-E3CDA6CB8F3C} + {82D29895-93F1-4BD6-938D-7BEDD4D1D2BF} = {85F44707-946F-453E-9969-E3CDA6CB8F3C} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {CD0D1E44-8118-4682-8793-6B20ABFA824C} diff --git a/benchmarks/HostedService/Controllers/WeatherForecastController.cs b/benchmarks/HostedService/Controllers/WeatherForecastController.cs deleted file mode 100644 index a14eab309c..0000000000 --- a/benchmarks/HostedService/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; - -namespace HostedService.Controllers; - -[ApiController, Route("[controller]")] -public class WeatherForecastController : ControllerBase -{ - private static readonly string[] Summaries = - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - private readonly ILogger _logger; - - public WeatherForecastController(ILogger logger) => _logger = logger; - - [HttpGet] - public IEnumerable Get() - { - var rng = new Random(); - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateTime.Now.AddDays(index), - TemperatureC = rng.Next(-20, 55), - Summary = Summaries[rng.Next(Summaries.Length)] - } - ) - .ToArray(); - } -} \ No newline at end of file diff --git a/benchmarks/HostedService/HostedService.csproj b/benchmarks/HostedService/HostedService.csproj index b6734a3b3f..6241a100cc 100644 --- a/benchmarks/HostedService/HostedService.csproj +++ b/benchmarks/HostedService/HostedService.csproj @@ -16,4 +16,8 @@ + + + + diff --git a/benchmarks/HostedService/WeatherForecast.cs b/benchmarks/HostedService/WeatherForecast.cs deleted file mode 100644 index 720b2b369e..0000000000 --- a/benchmarks/HostedService/WeatherForecast.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace HostedService; - -public class WeatherForecast -{ - public DateTime Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int) (TemperatureC / 0.5556); - - public string Summary { get; set; } -} \ No newline at end of file diff --git a/examples/AspNetGrains/Messages/Messages.csproj b/examples/AspNetGrains/Messages/Messages.csproj new file mode 100644 index 0000000000..03a95f7fc9 --- /dev/null +++ b/examples/AspNetGrains/Messages/Messages.csproj @@ -0,0 +1,21 @@ + + + + net6.0 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/AspNetGrains/Messages/Protos.proto b/examples/AspNetGrains/Messages/Protos.proto new file mode 100644 index 0000000000..2480e34e7e --- /dev/null +++ b/examples/AspNetGrains/Messages/Protos.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; +package HelloHelloWorld; +option csharp_namespace = "AspNetGrains.Messages"; + +message HelloRequest {} +message HelloResponse { + string Message=1; +} + +service HelloGrain { + rpc SayHello(HelloRequest) returns (HelloResponse) {} +} \ No newline at end of file diff --git a/examples/AspNetGrains/Node1/Node1.csproj b/examples/AspNetGrains/Node1/Node1.csproj new file mode 100644 index 0000000000..8b87cdd55d --- /dev/null +++ b/examples/AspNetGrains/Node1/Node1.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/examples/AspNetGrains/Node1/Program.cs b/examples/AspNetGrains/Node1/Program.cs new file mode 100644 index 0000000000..3f356898b6 --- /dev/null +++ b/examples/AspNetGrains/Node1/Program.cs @@ -0,0 +1,30 @@ +using AspNetGrains.Messages; +using Proto; +using Proto.Cluster; +using Proto.Cluster.Seed; +using Proto.Remote; +using Proto.Remote.Healthchecks; + +var builder = WebApplication.CreateBuilder(args); +builder.Services.AddLogging(x => x.AddConsole()); + +builder.Services.AddProtoCluster("MyCluster", + configureRemote: r => r.WithProtoMessages(AspNetGrains.Messages.ProtosReflection.Descriptor), + configureCluster: c => c, clusterProvider:SeedNodeClusterProvider.JoinSeedNode("localhost",8090)); + +builder.Services.AddHealthChecks().AddCheck("proto", null, new[] { "ready", "live" }); + +var app = builder.Build(); + +app.MapGet("/", async (Cluster cluster) => +{ + var helloGrain = cluster.GetHelloGrain("MyGrain"); + + var res = await helloGrain.SayHello(new HelloRequest(), CancellationTokens.FromSeconds(5)); + Console.WriteLine(res.Message); + + res = await helloGrain.SayHello(new HelloRequest(), CancellationTokens.FromSeconds(5)); + return res.Message; +}); + +app.Run(); \ No newline at end of file diff --git a/examples/AspNetGrains/Node1/Properties/launchSettings.json b/examples/AspNetGrains/Node1/Properties/launchSettings.json new file mode 100644 index 0000000000..5521624f0b --- /dev/null +++ b/examples/AspNetGrains/Node1/Properties/launchSettings.json @@ -0,0 +1,28 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:33861", + "sslPort": 44325 + } + }, + "profiles": { + "Node1": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:7189;http://localhost:5110", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/examples/AspNetGrains/Node1/appsettings.Development.json b/examples/AspNetGrains/Node1/appsettings.Development.json new file mode 100644 index 0000000000..0c208ae918 --- /dev/null +++ b/examples/AspNetGrains/Node1/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/examples/AspNetGrains/Node1/appsettings.json b/examples/AspNetGrains/Node1/appsettings.json new file mode 100644 index 0000000000..10f68b8c8b --- /dev/null +++ b/examples/AspNetGrains/Node1/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/examples/AspNetGrains/Node2/HelloGrain.cs b/examples/AspNetGrains/Node2/HelloGrain.cs new file mode 100644 index 0000000000..da19b7d7c6 --- /dev/null +++ b/examples/AspNetGrains/Node2/HelloGrain.cs @@ -0,0 +1,26 @@ +using AspNetGrains.Messages; +using Proto; + +namespace Node2; + +public class HelloGrain : HelloGrainBase +{ + private readonly string _identity; + + public HelloGrain(IContext ctx, string identity) : base(ctx) + { + _identity = identity; + } + + public override Task SayHello(HelloRequest request) + { + Console.WriteLine("Got request!!"); + + var res = new HelloResponse + { + Message = $"Hello from typed grain {_identity}" + }; + + return Task.FromResult(res); + } +} \ No newline at end of file diff --git a/examples/AspNetGrains/Node2/Node2.csproj b/examples/AspNetGrains/Node2/Node2.csproj new file mode 100644 index 0000000000..1df2030a4b --- /dev/null +++ b/examples/AspNetGrains/Node2/Node2.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/examples/AspNetGrains/Node2/Program.cs b/examples/AspNetGrains/Node2/Program.cs new file mode 100644 index 0000000000..b548e6e471 --- /dev/null +++ b/examples/AspNetGrains/Node2/Program.cs @@ -0,0 +1,20 @@ +using AspNetGrains.Messages; +using Proto.Cluster; +using Proto.Cluster.Seed; +using Proto.Remote; +using Proto.Remote.Healthchecks; + +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddLogging(x => x.AddConsole()); + +builder.Services.AddProtoCluster("MyCluster", port: 8090, + configureRemote: r => r.WithProtoMessages(AspNetGrains.Messages.ProtosReflection.Descriptor), + configureCluster: c => c.WithClusterKind(HelloGrainActor.GetClusterKind((ctx,ci) => new Node2.HelloGrain(ctx,ci.Identity))), clusterProvider:SeedNodeClusterProvider.StartSeedNode()); + +builder.Services.AddHealthChecks().AddCheck("proto", null, new[] { "ready", "live" }); + + +var app = builder.Build(); + +app.Run(); \ No newline at end of file diff --git a/examples/AspNetGrains/Node2/Properties/launchSettings.json b/examples/AspNetGrains/Node2/Properties/launchSettings.json new file mode 100644 index 0000000000..fd4af9f6fa --- /dev/null +++ b/examples/AspNetGrains/Node2/Properties/launchSettings.json @@ -0,0 +1,28 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:33313", + "sslPort": 44394 + } + }, + "profiles": { + "Node2": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:7110;http://localhost:5220", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/examples/AspNetGrains/Node2/appsettings.Development.json b/examples/AspNetGrains/Node2/appsettings.Development.json new file mode 100644 index 0000000000..0c208ae918 --- /dev/null +++ b/examples/AspNetGrains/Node2/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/examples/AspNetGrains/Node2/appsettings.json b/examples/AspNetGrains/Node2/appsettings.json new file mode 100644 index 0000000000..10f68b8c8b --- /dev/null +++ b/examples/AspNetGrains/Node2/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/examples/ClusterGrainHelloWorld/Messages/Protos.proto b/examples/ClusterGrainHelloWorld/Messages/Protos.proto index 21a17e35e8..9d2f115490 100644 --- a/examples/ClusterGrainHelloWorld/Messages/Protos.proto +++ b/examples/ClusterGrainHelloWorld/Messages/Protos.proto @@ -2,8 +2,6 @@ package HelloHelloWorld; option csharp_namespace = "ClusterHelloWorld.Messages"; -//dotnet run -p ../../../protobuf/ProtoGrainGenerator/ProtoGrainGenerator.csproj --framework net5.0 many *.proto - message HelloRequest {} message HelloResponse { string Message=1; diff --git a/examples/ClusterGrainHelloWorld/Node1/Program.cs b/examples/ClusterGrainHelloWorld/Node1/Program.cs index 3f2d294da5..10fc5ce4e1 100644 --- a/examples/ClusterGrainHelloWorld/Node1/Program.cs +++ b/examples/ClusterGrainHelloWorld/Node1/Program.cs @@ -17,44 +17,38 @@ using static Proto.CancellationTokens; using ProtosReflection = ClusterHelloWorld.Messages.ProtosReflection; -internal class Program -{ - private static async Task Main() - { - Log.SetLoggerFactory( - LoggerFactory.Create(l => l.AddConsole().SetMinimumLevel(LogLevel.Information))); - - // Required to allow unencrypted GrpcNet connections - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); - - var system = new ActorSystem() - .WithRemote(GrpcNetRemoteConfig.BindToLocalhost().WithProtoMessages(ProtosReflection.Descriptor)) - .WithCluster(ClusterConfig - .Setup("MyCluster", - new SeedNodeClusterProvider(new SeedNodeClusterProviderOptions(("127.0.0.1", 8090))), - new PartitionIdentityLookup())); - - system.EventStream.Subscribe( - e => { Console.WriteLine($"{DateTime.Now:O} My members {e.TopologyHash}"); } - ); - - await system - .Cluster() - .StartMemberAsync(); - - Console.WriteLine("Started"); - - var helloGrain = system.Cluster().GetHelloGrain("MyGrain"); - - var res = await helloGrain.SayHello(new HelloRequest(), FromSeconds(5)); - Console.WriteLine(res.Message); - - res = await helloGrain.SayHello(new HelloRequest(), FromSeconds(5)); - Console.WriteLine(res.Message); - - Console.WriteLine("Press enter to exit"); - Console.ReadLine(); - Console.WriteLine("Shutting Down..."); - await system.Cluster().ShutdownAsync(); - } -} \ No newline at end of file +Log.SetLoggerFactory( + LoggerFactory.Create(l => l.AddConsole().SetMinimumLevel(LogLevel.Information))); + +// Required to allow unencrypted GrpcNet connections +AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); + +var system = new ActorSystem() + .WithRemote(GrpcNetRemoteConfig.BindToLocalhost().WithProtoMessages(ProtosReflection.Descriptor)) + .WithCluster(ClusterConfig + .Setup("MyCluster", + new SeedNodeClusterProvider(new SeedNodeClusterProviderOptions(("127.0.0.1", 8090))), + new PartitionIdentityLookup())); + +system.EventStream.Subscribe( + e => { Console.WriteLine($"{DateTime.Now:O} My members {e.TopologyHash}"); } +); + +await system + .Cluster() + .StartMemberAsync(); + +Console.WriteLine("Started"); + +var helloGrain = system.Cluster().GetHelloGrain("MyGrain"); + +var res = await helloGrain.SayHello(new HelloRequest(), FromSeconds(5)); +Console.WriteLine(res.Message); + +res = await helloGrain.SayHello(new HelloRequest(), FromSeconds(5)); +Console.WriteLine(res.Message); + +Console.WriteLine("Press enter to exit"); +Console.ReadLine(); +Console.WriteLine("Shutting Down..."); +await system.Cluster().ShutdownAsync(); \ No newline at end of file diff --git a/examples/ClusterGrainHelloWorld/Node2/Program.cs b/examples/ClusterGrainHelloWorld/Node2/Program.cs index 3f661cb3ac..b0d104a288 100644 --- a/examples/ClusterGrainHelloWorld/Node2/Program.cs +++ b/examples/ClusterGrainHelloWorld/Node2/Program.cs @@ -17,7 +17,40 @@ using static System.Threading.Tasks.Task; using ProtosReflection = ClusterHelloWorld.Messages.ProtosReflection; -namespace Node2; +Log.SetLoggerFactory( + LoggerFactory.Create(l => l.AddConsole().SetMinimumLevel(LogLevel.Information))); + +// Required to allow unencrypted GrpcNet connections +AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); + +var system = new ActorSystem(new ActorSystemConfig().WithDeveloperSupervisionLogging(true)) + .WithRemote(GrpcNetRemoteConfig.BindToLocalhost(8090).WithProtoMessages(ProtosReflection.Descriptor)) + .WithCluster(ClusterConfig + .Setup("MyCluster", new SeedNodeClusterProvider(), new PartitionIdentityLookup()) + .WithClusterKind( + HelloGrainActor.GetClusterKind((ctx, identity) => new HelloGrain(ctx, identity.Identity))) + ); + +system.EventStream.Subscribe( + e => { Console.WriteLine($"{DateTime.Now:O} My members {e.TopologyHash}"); } +); + +await system + .Cluster() + .StartMemberAsync(); + +Console.WriteLine("Started..."); + +Console.CancelKeyPress += async (e, y) => +{ + Console.WriteLine("Shutting Down..."); + + await system + .Cluster() + .ShutdownAsync(); +}; + +await Delay(-1); public class HelloGrain : HelloGrainBase { @@ -40,44 +73,3 @@ public override Task SayHello(HelloRequest request) return FromResult(res); } } - -internal class Program -{ - private static async Task Main() - { - Log.SetLoggerFactory( - LoggerFactory.Create(l => l.AddConsole().SetMinimumLevel(LogLevel.Information))); - - // Required to allow unencrypted GrpcNet connections - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); - - var system = new ActorSystem(new ActorSystemConfig().WithDeveloperSupervisionLogging(true)) - .WithRemote(GrpcNetRemoteConfig.BindToLocalhost(8090).WithProtoMessages(ProtosReflection.Descriptor)) - .WithCluster(ClusterConfig - .Setup("MyCluster", new SeedNodeClusterProvider(), new PartitionIdentityLookup()) - .WithClusterKind( - HelloGrainActor.GetClusterKind((ctx, identity) => new HelloGrain(ctx, identity.Identity))) - ); - - system.EventStream.Subscribe( - e => { Console.WriteLine($"{DateTime.Now:O} My members {e.TopologyHash}"); } - ); - - await system - .Cluster() - .StartMemberAsync(); - - Console.WriteLine("Started..."); - - Console.CancelKeyPress += async (e, y) => - { - Console.WriteLine("Shutting Down..."); - - await system - .Cluster() - .ShutdownAsync(); - }; - - await Delay(-1); - } -} \ No newline at end of file diff --git a/examples/Proto.Cluster.Dashboard.Host/ActorSystemHostedService.cs b/examples/Proto.Cluster.Dashboard.Host/ActorSystemHostedService.cs deleted file mode 100644 index 2cc10d18e6..0000000000 --- a/examples/Proto.Cluster.Dashboard.Host/ActorSystemHostedService.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace Proto.Cluster.Dashboard; - -public class ActorSystemHostedService : IHostedService -{ - private readonly ActorSystem _actorSystem; - - public ActorSystemHostedService(ActorSystem actorSystem) - { - _actorSystem = actorSystem; - } - - public async Task StartAsync(CancellationToken cancellationToken) => - await _actorSystem.Cluster().StartMemberAsync(); - - public async Task StopAsync(CancellationToken cancellationToken) => await _actorSystem.Cluster().ShutdownAsync(); -} \ No newline at end of file diff --git a/examples/Proto.Cluster.Dashboard.Host/Program.cs b/examples/Proto.Cluster.Dashboard.Host/Program.cs index 913430a560..f085f3e898 100644 --- a/examples/Proto.Cluster.Dashboard.Host/Program.cs +++ b/examples/Proto.Cluster.Dashboard.Host/Program.cs @@ -7,17 +7,25 @@ using Proto.Cluster.Seed; using Proto.Remote; using Proto.Remote.GrpcNet; +using Proto.Remote.Healthchecks; var builder = WebApplication.CreateBuilder(args); -var system = GetSystem(); -builder.Services.AddProtoActorDashboard(system, new DashboardSettings + +builder.Services.AddLogging(x => x.AddConsole()); +builder.Services.AddProtoActorDashboard(new DashboardSettings { LogSearchPattern = "", TraceSearchPattern = "" }); -builder.Services.AddHostedService(); +builder.Services.AddProtoCluster("MyCluster", port: 8090, + configureRemote: r => r.WithRemoteDiagnostics(true), + configureCluster: c => c); + +builder.Services.AddHealthChecks().AddCheck("proto", null, new[] { "ready", "live" }); + + // Add services to the container. builder.Services.AddRazorPages(); builder.Services.AddServerSideBlazor(); @@ -39,24 +47,3 @@ app.MapFallbackToPage("/_Host"); app.Run(); - -ActorSystem GetSystem() -{ - Log.SetLoggerFactory( - LoggerFactory.Create(l => l.AddConsole().SetMinimumLevel(LogLevel.Information))); - - var port = 0; - var advertisedHost = "localhost"; - var provider = new SeedNodeClusterProvider(); - - var actorSystem = - new ActorSystem(ActorSystemConfig.Setup().WithDeveloperSupervisionLogging(true)) - .WithRemote(GrpcNetRemoteConfig - .BindToAllInterfaces(advertisedHost, port) - .WithProtoMessages(SeedContractsReflection.Descriptor) - .WithProtoMessages(Empty.Descriptor.File) - .WithRemoteDiagnostics(true)) - .WithCluster(ClusterConfig.Setup("MyCluster", provider, new PartitionIdentityLookup())); - - return actorSystem; -} \ No newline at end of file diff --git a/examples/Proto.Cluster.Dashboard.Host/Proto.Cluster.Dashboard.Host.csproj b/examples/Proto.Cluster.Dashboard.Host/Proto.Cluster.Dashboard.Host.csproj index 85b76f31ee..f8ab856575 100644 --- a/examples/Proto.Cluster.Dashboard.Host/Proto.Cluster.Dashboard.Host.csproj +++ b/examples/Proto.Cluster.Dashboard.Host/Proto.Cluster.Dashboard.Host.csproj @@ -12,8 +12,8 @@ - - + + diff --git a/src/Proto.Cluster/Seed/SeedNodeClusterProvider.cs b/src/Proto.Cluster/Seed/SeedNodeClusterProvider.cs index 6d5ec0d025..f9efb0e2f3 100644 --- a/src/Proto.Cluster/Seed/SeedNodeClusterProvider.cs +++ b/src/Proto.Cluster/Seed/SeedNodeClusterProvider.cs @@ -14,6 +14,16 @@ namespace Proto.Cluster.Seed; public class SeedNodeClusterProvider : IClusterProvider { + public static IClusterProvider JoinSeedNode(string address, int port) + { + return new SeedNodeClusterProvider(new SeedNodeClusterProviderOptions((address, port))); + } + + public static IClusterProvider StartSeedNode() + { + return new SeedNodeClusterProvider(); + } + private static readonly ILogger Logger = Log.CreateLogger(); private readonly CancellationTokenSource _cts = new();