dotnet / orleans

Cloud Native application framework for .NET
https://docs.microsoft.com/dotnet/orleans
MIT License
10.03k stars 2.02k forks source link

Connect to Orleans cluster in Azure Container Apps #8580

Closed SoucianceEqdamRashti closed 1 year ago

SoucianceEqdamRashti commented 1 year ago

Hello,

I have an Orleans cluster setup with this Silo config in an ASP.NET Core app. It is deployed to an azure container app.

silo.AddAzureTableGrainStorage(
                name: "apppersistence",
                configureOptions: options =>
                {
                    options.ConfigureTableServiceClient("DefaultEndpointsProtocol==");
                    options.DeleteStateOnClear = true;
                });
        silo.Configure<SiloOptions>(options =>
        {
            options.SiloName = "OrleansContainerAppSilo";

        })
        .ConfigureEndpoints(siloPort: 11_111, gatewayPort: 30_000, listenOnAnyHostAddress: true)
        .UseAzureStorageClustering(options => options.ConfigureTableServiceClient("="));
        silo.Configure<ClusterOptions>(options =>
        {
            options.ClusterId = "OrleansClusterAppDev";
            options.ServiceId = "Automation Center Orleans App";
        });

If I call the web api controller that exist inside the container which calls a grain, then that works fine since orleans and the asp.net core app reside on the same host.

Now if I have a completely separate asp.net core app residing locally on my machine and I want to connect to the orleans cluster in the container app. Here is the client setup:

 using IHost host = Host.CreateDefaultBuilder(args)
         .UseOrleansClient((context, client) =>
         {
             client.Configure<ClusterOptions>(options =>
             {
                 options.ClusterId = "OrleansClusterAppDev";
                 options.ServiceId = "Automation Center Orleans App";
             })
             .UseAzureStorageClustering(
                 options =>
                 options.ConfigureTableServiceClient(
                     "DefaultEndpointsProtocol=https;AccountName=="));
         })
         .UseConsoleLifetime()
         .Build();

    await host.StartAsync();

    IGrainFactory client = host.Services.GetRequiredService<IGrainFactory>();

If I now run the local app, I now get this error:

{"Unable to connect to any of the 1 available gateways."}
{System.Collections.ListDictionaryInternal}
-2146233088
null
{"Connection attempt to endpoint S100.100.0.13:30000:0 timed out after 00:00:05"}
"Unable to connect to any of the 1 available gateways."
"Orleans.Core"
"   at Orleans.Messaging.ClientMessageCenter.<EstablishInitialConnection>d__29.MoveNext()\r\n   at Orleans.Messaging.ClientMessageCenter.<StartAsync>d__28.MoveNext()\r\n   at Orleans.OutsideRuntimeClient.<>c__DisplayClass46_0.<<StartInternal>b__1>d.MoveNext()\r\n   at Orleans.OutsideRuntimeClient.<<StartInternal>g__ExecuteWithRetries|46_3>d.MoveNext()\r\n   at Orleans.OutsideRuntimeClient.<StartInternal>d__46.MoveNext()\r\n   at Orleans.OutsideRuntimeClient.<Start>d__45.MoveNext()\r\n   at Orleans.ClusterClient.<StartAsync>d__6.MoveNext()\r\n   at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>d__12.MoveNext()\r\n   at Program.<<Main>$>d__0.MoveNext() in C:\\OrleansClientContainerApp\\OrleansClientContainerApp\\Program.cs:line 31"

Is there something missing in the client or server side?

christiansparre commented 1 year ago

If the asp.net core app you are running locally was running as a container app in the same container app environment that would work. But the endpoint S100.100.0.13:30000 is not exposed outside your container app/environment so you cannot connect from you local machine to an Orleans cluster running in Azure Container Apps.

Container apps does support exposing TCP as far as I know, have not tried it. But it would be without any security or authentication so that is a BAD idea - I'm not sure how you would approach it if you needed to.

Best approach would be to also deploy your "client" app to the same aca environment.