Exemplo n.º 1
0
        private void CreateClusteredSiloHost()
        {
            var silo = new SiloHostBuilder()
                       .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = orleansConfig.ClusterId;
                options.ServiceId = orleansConfig.ServiceId;
            });
            //.EnableDirectClient();

            string storageType = GetStorageType(orleansConfig.DataConnectionString);

            if (storageType.ToLowerInvariant() == "redis")
            {
                silo.UseRedisMembership(options => options.ConnectionString            = orleansConfig.DataConnectionString);
                silo.AddRedisGrainStorage("store", options => options.ConnectionString = orleansConfig.DataConnectionString);
            }
            else if (storageType.ToLowerInvariant() == "azurestorage")
            {
                silo.UseAzureStorageClustering(options => options.ConnectionString         = orleansConfig.DataConnectionString);
                silo.AddAzureBlobGrainStorage("store", options => options.ConnectionString = orleansConfig.DataConnectionString);
            }
            else
            {
                //throw
            }

            silo.ConfigureEndpoints(siloPort: 11111, gatewayPort: 30000);

            LogLevel orleansLogLevel = GetLogLevel();
            var      loggers         = orleansConfig.GetLoggerTypes();

            silo.ConfigureLogging(builder =>
            {
                if (loggers.HasFlag(LoggerType.Console))
                {
                    builder.AddConsole();
                }
                if (loggers.HasFlag(LoggerType.Debug))
                {
                    builder.AddDebug();
                }
                builder.SetMinimumLevel(orleansLogLevel);
            });

            if (loggers.HasFlag(LoggerType.AppInsights) && !string.IsNullOrEmpty(orleansConfig.AppInsightsKey))
            {
                silo.AddApplicationInsightsTelemetryConsumer(orleansConfig.AppInsightsKey);
            }
            host = silo.Build();

            var clusterClient = (IClusterClient)host.Services.GetService(typeof(IClusterClient));

            GraphManager.Initialize(clusterClient);
        }
Exemplo n.º 2
0
        private ISiloHost AddClusteredSiloHost()
        {
            var silo = new SiloHostBuilder()
                       .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = orleansConfig.ClusterId;
                options.ServiceId = orleansConfig.ServiceId;
            });


            if (string.IsNullOrEmpty(orleansConfig.DataConnectionString))
            {
                silo.AddMemoryGrainStorage("store");
            }
            else if (orleansConfig.DataConnectionString.Contains("6379") ||
                     orleansConfig.DataConnectionString.Contains("6380"))
            {
                silo.UseRedisMembership(options => options.ConnectionString            = orleansConfig.DataConnectionString);
                silo.AddRedisGrainStorage("store", options => options.ConnectionString = orleansConfig.DataConnectionString);
            }
            else
            {
                silo.UseAzureStorageClustering(options => options.ConnectionString         = orleansConfig.DataConnectionString);
                silo.AddAzureBlobGrainStorage("store", options => options.ConnectionString = orleansConfig.DataConnectionString);
            }

            silo.ConfigureEndpoints(siloPort: 11111, gatewayPort: 30000);

            LogLevel orleansLogLevel = Enum.Parse <LogLevel>(orleansConfig.LogLevel);
            var      loggers         = orleansConfig.GetLoggerTypes();

            silo.ConfigureLogging(builder =>
            {
                if (loggers.HasFlag(LoggerType.Console))
                {
                    builder.AddConsole();
                }
                if (loggers.HasFlag(LoggerType.Debug))
                {
                    builder.AddDebug();
                }
                builder.SetMinimumLevel(orleansLogLevel);
            });

            if (!string.IsNullOrEmpty(orleansConfig.AppInsightsKey))
            {
                silo.AddApplicationInsightsTelemetryConsumer(orleansConfig.AppInsightsKey);
            }

            return(silo.Build());
        }
Exemplo n.º 3
0
        protected override Task OnInit()
        {
            var builder = new SiloHostBuilder()
                          .UseLocalhostClustering()
                          .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "dev";
                options.ServiceId = "AdventureApp";
            })
                          .Configure <EndpointOptions>(options => options.AdvertisedIPAddress = IPAddress.Loopback);

            foreach (var t in types)
            {
                builder.ConfigureApplicationParts(parts => parts.AddApplicationPart(t.Assembly).WithReferences());
            }

            builder.ConfigureLogging(logging => logging.AddConsole());
            silo = builder.Build();
            return(Task.CompletedTask);
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            var externalAssemblies = LoadExternalAssemblies().ToArray();

            var env = Environment.GetEnvironmentVariable("ORLEANS_CONFIG");

            var builder = new SiloHostBuilder();

            builder
            .ConfigureLogging((context, loggingBuilder) => loggingBuilder.AddConsole())
            .Configure <ProcessExitHandlingOptions>(options =>
            {
                options.FastKillOnProcessExit = false;
            })
            .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "serverlessorleans";
                options.ServiceId = "serverlessorleans";
            })
            .ConfigureApplicationParts(parts =>
            {
                foreach (var assembly in externalAssemblies)
                {
                    System.Console.WriteLine("Loading orleans app parts: " + assembly.FullName);
                    parts.AddApplicationPart(assembly);
                }
            })
            .UseDashboard(options =>
            {
                options.CounterUpdateIntervalMs = 5000;
                options.HostSelf = false;
            });

            if (env == "STORAGE")
            {
                builder
                .AddAzureBlobGrainStorageAsDefault(options =>
                {
                    options.ConnectionString = Environment.GetEnvironmentVariable("StorageConnectionString");
                    options.UseJson          = true;
                    options.IndentJson       = true;
                    options.ContainerName    = "actorstate";
                })
                .UseAzureStorageClustering(options =>
                {
                    options.ConnectionString = Environment.GetEnvironmentVariable("StorageConnectionString");
                    options.TableName        = "clusterstate";
                })
                .ConfigureEndpoints(11111, 30000);
            }
            else if (env == "SQL")
            {
                builder
                .AddAdoNetGrainStorageAsDefault(options =>
                {
                    options.Invariant        = "System.Data.SqlClient";
                    options.UseJsonFormat    = true;
                    options.IndentJson       = true;
                    options.ConnectionString = Environment.GetEnvironmentVariable("SqlConnectionString");
                })
                .UseAdoNetClustering(options =>
                {
                    options.Invariant        = "System.Data.SqlClient";
                    options.ConnectionString = Environment.GetEnvironmentVariable("SqlConnectionString");
                })
                .ConfigureEndpoints(11111, 30000);
            }
            else
            {
                throw new Exception("ORLEANS_CONFIG envvar not defined.");
            }

            _silo = builder.Build();

            Task.Run(StartSilo);

            AssemblyLoadContext.Default.Unloading += context =>
            {
                Task.Run(StopSilo);
                _siloStopped.WaitOne();
            };

            _siloStopped.WaitOne();
        }