Example #1
0
        public async Task InitAsync()
        {
            var builder = new SiloHostBuilder()
                          .UseLocalhostClustering()
                          .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "dev";
                options.ServiceId = "HelloWorldApp";
            })
                          .ConfigureLogging(logging => { /*logging.AddConsole();*/ });

            builder.AddSimpleMessageStreamProvider("TestStream")
            .AddMemoryGrainStorage("PubSubStore");

            var host = builder.Build();
            await host.StartAsync();
        }
Example #2
0
        /// <summary>
        ///     Starts the silo host.
        /// </summary>
        /// <returns>An <see cref="ISiloHost" />.</returns>
        private ISiloHost StartSilo()
        {
            var databaseConfig     = this.configuration.GetSection("Database");
            var connectionSettings = new MqttDatabaseConnectionSettings();

            databaseConfig.Bind(connectionSettings);

            DashboardOptions dashboardOptions = null;

            if (this.configuration.GetSection("Orleans").GetSection("DashboardOptions").Exists())
            {
                dashboardOptions = new DashboardOptions();
                this.configuration.GetSection("Orleans").Bind("DashboardOptions", dashboardOptions);
            }

            // ReSharper disable ImplicitlyCapturedClosure
            var builder = new SiloHostBuilder().ConfigureServices(
                s =>
            {
                s.Configure <MqttDatabaseConnectionSettings>(databaseConfig);
                s.AddSingleton <IEventLogRepository>(r => new EventLogRepository(connectionSettings));
                s.AddSingleton <IBlacklistRepository>(u => new BlacklistRepository(connectionSettings));
                s.AddSingleton <IDatabaseVersionRepository>(u => new DatabaseVersionRepository(connectionSettings));
                s.AddSingleton <IPublishMessageRepository>(a => new PublishMessageRepository(connectionSettings));
                s.AddSingleton <IUserRepository>(u => new UserRepository(connectionSettings));
                s.AddSingleton <IWhitelistRepository>(u => new WhitelistRepository(connectionSettings));
                s.AddSingleton <IMqttValidator>(new MqttValidator());
            }).UseAdoNetClustering(
                options =>
            {
                options.Invariant        = "Npgsql";
                options.ConnectionString = connectionSettings.ToConnectionString();
            }).UseAdoNetReminderService(
                options =>
            {
                options.Invariant        = "Npgsql";
                options.ConnectionString = connectionSettings.ToConnectionString();
            }).Configure <ClusterOptions>(options => { this.configuration.GetSection("Orleans").Bind("ClusterOptions", options); }).Configure <EndpointOptions>(
                options =>
            {
                var opt = new SiloEndpointOptions();
                this.configuration.GetSection("Orleans").Bind("EndpointOptions", opt);
                opt.Bind(options);
            }).ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(MqttRepositoryGrain).Assembly).WithReferences()).ConfigureLogging(
                logging =>
            {
                logging.ClearProviders();
                logging.AddSerilog(dispose: true, logger: this.logger);
            });

            if (dashboardOptions != null)
            {
                builder.UseDashboard(
                    o =>
                {
                    o.HostSelf = true;
                    o.CounterUpdateIntervalMs = dashboardOptions.CounterUpdateIntervalMs;
                    o.Port = dashboardOptions.Port;
                });
            }

            builder.AddSimpleMessageStreamProvider("SMSProvider").AddMemoryGrainStorage("PubSubStore");

            var host = builder.Build();

            return(host);
        }