Пример #1
0
        private async Task StartSilo()
        {
            var siloBuilder = new SiloHostBuilder()
                              .UseLocalhostClustering()
                              .UseDashboard(options => { })
                              .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "dev";
                options.ServiceId = "OrleansService";
            })
                              .ConfigureEndpoints(IPAddress.Loopback, 11111, 30000, listenOnAnyHostAddress: true)
                              .ConfigureLogging(logging => logging.AddConsole())
                              .ConfigureApplicationParts(manager =>
            {
                manager?.AddApplicationPart(typeof(CoinTrader).Assembly);
            });
            var invariant        = "System.Data.SqlClient"; // for Microsoft SQL Server
            var connectionString = Configuration["connectionString"].ToString();

            siloBuilder.UseAdoNetClustering(options =>
            {
                options.Invariant        = invariant;
                options.ConnectionString = connectionString;
            });
            //use AdoNet for reminder service
            siloBuilder.UseAdoNetReminderService(options =>
            {
                options.Invariant        = invariant;
                options.ConnectionString = connectionString;
            });
            //use AdoNet for Persistence
            siloBuilder.AddAdoNetGrainStorage("OrleansSqlStore", options =>
            {
                options.Invariant        = invariant;
                options.ConnectionString = connectionString;
                options.UseJsonFormat    = false;
            });

            _siloHost = siloBuilder.Build();
            await _siloHost.StartAsync();
        }
Пример #2
0
        private static async Task <ISiloHost> StartSilo()
        {
            var baseDir = Path.Combine(AppContext.BaseDirectory);

            Configuration = AppConfiguration.GetIConfigurationRoot(baseDir);

            var appOptions       = AppConfiguration.GetApplicationConfiguration(baseDir);
            var dashboardOptions = AppConfiguration.GetConfiguration <DashboardOptions>(baseDir, "Dashboard");
            // define the cluster configuration
            var builder = new SiloHostBuilder();

            switch (appOptions.StorageType)
            {
            case StorageType.AzureTable:
                builder.AddAzureTableGrainStorage(Constants.StorageName, options =>
                {
                    options.ConnectionString = appOptions.OrleansConnectionString;
                    options.TableName        = appOptions.AzureTableName;
                    options.UseJson          = appOptions.UseJson;
                });
                builder.UseAzureTableReminderService(options => {
                    options.ConnectionString = appOptions.OrleansConnectionString;
                });
                break;

            default:
                builder.AddAdoNetGrainStorage(Constants.StorageName, options =>
                {
                    options.Invariant        = appOptions.AdoInvariant;
                    options.ConnectionString = appOptions.OrleansConnectionString;
                    options.UseJsonFormat    = appOptions.UseJson;
                });
                builder.UseAdoNetReminderService(options => {
                    options.ConnectionString = appOptions.OrleansConnectionString;
                });
                break;
            }
            builder.UseLocalhostClustering()
            .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = appOptions.ClusterId;
                options.ServiceId = appOptions.ServiceId;
            })
            .Configure <EndpointOptions>(options => options.AdvertisedIPAddress = IPAddress.Loopback)
            .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IGrainMarker).Assembly).WithReferences())
            .AddSimpleMessageStreamProvider(Constants.StreamProvider)
            .AddMemoryGrainStorage(Constants.StreamStorage)
            .ConfigureServices((service) => {
                service.Configure <ApplicationOptions>(Configuration);
                service.AddOptions();
                service.AddSingleton <ApplicationOptions>(appOptions);
                DependencyInjectionHelper.IocContainerRegistration(service);
            })
            .ConfigureLogging(logging => logging.AddConsole())
            .UseDashboard(options => {
                options.Host     = dashboardOptions.Host;
                options.Port     = dashboardOptions.Port;
                options.HostSelf = dashboardOptions.HostSelf;
                options.CounterUpdateIntervalMs = dashboardOptions.CounterUpdateIntervalMs;
            });
            var host = builder.Build();
            await host.StartAsync();

            return(host);
        }