Пример #1
0
 private static void RegisterQueue(IServiceCollection container, QueueOptions options, bool runMaintenanceTasks)
 {
     if (String.Equals(options.Provider, "azurestorage"))
     {
         container.ReplaceSingleton(s => CreateAzureStorageQueue <EventPost>(s, options, retries: 1));
         container.ReplaceSingleton(s => CreateAzureStorageQueue <EventUserDescription>(s, options));
         container.ReplaceSingleton(s => CreateAzureStorageQueue <EventNotificationWorkItem>(s, options));
         container.ReplaceSingleton(s => CreateAzureStorageQueue <WebHookNotification>(s, options));
         container.ReplaceSingleton(s => CreateAzureStorageQueue <MailMessage>(s, options));
         container.ReplaceSingleton(s => CreateAzureStorageQueue <WorkItemData>(s, options, workItemTimeout: TimeSpan.FromHours(1)));
     }
     else if (String.Equals(options.Provider, "redis"))
     {
         container.ReplaceSingleton(s => CreateRedisQueue <EventPost>(s, options, runMaintenanceTasks, retries: 1));
         container.ReplaceSingleton(s => CreateRedisQueue <EventUserDescription>(s, options, runMaintenanceTasks));
         container.ReplaceSingleton(s => CreateRedisQueue <EventNotificationWorkItem>(s, options, runMaintenanceTasks));
         container.ReplaceSingleton(s => CreateRedisQueue <WebHookNotification>(s, options, runMaintenanceTasks));
         container.ReplaceSingleton(s => CreateRedisQueue <MailMessage>(s, options, runMaintenanceTasks));
         container.ReplaceSingleton(s => CreateRedisQueue <WorkItemData>(s, options, runMaintenanceTasks, workItemTimeout: TimeSpan.FromHours(1)));
     }
     else if (String.Equals(options.Provider, "sqs"))
     {
         container.ReplaceSingleton(s => CreateSQSQueue <EventPost>(s, options, retries: 1));
         container.ReplaceSingleton(s => CreateSQSQueue <EventUserDescription>(s, options));
         container.ReplaceSingleton(s => CreateSQSQueue <EventNotificationWorkItem>(s, options));
         container.ReplaceSingleton(s => CreateSQSQueue <WebHookNotification>(s, options));
         container.ReplaceSingleton(s => CreateSQSQueue <MailMessage>(s, options));
         container.ReplaceSingleton(s => CreateSQSQueue <WorkItemData>(s, options, workItemTimeout: TimeSpan.FromHours(1)));
     }
 }
Пример #2
0
        public static QueueOptions ReadFromConfiguration(IConfiguration config, AppOptions appOptions)
        {
            var options = new QueueOptions();

            options.Scope       = appOptions.AppScope;
            options.ScopePrefix = !String.IsNullOrEmpty(options.Scope) ? options.Scope + "-" : String.Empty;

            string cs = config.GetConnectionString("Queue");

            options.Data     = cs.ParseConnectionString();
            options.Provider = options.Data.GetString(nameof(options.Provider));

            var providerConnectionString = !String.IsNullOrEmpty(options.Provider) ? config.GetConnectionString(options.Provider) : null;

            if (!String.IsNullOrEmpty(providerConnectionString))
            {
                options.Data.AddRange(providerConnectionString.ParseConnectionString());
            }

            options.ConnectionString = options.Data.BuildConnectionString(new HashSet <string> {
                nameof(options.Provider)
            });

            return(options);
        }
Пример #3
0
 private static IQueue<T> CreateRedisQueue<T>(IServiceProvider container, QueueOptions options, bool runMaintenanceTasks, int retries = 2, TimeSpan? workItemTimeout = null) where T : class {
     return new RedisQueue<T>(new RedisQueueOptions<T> {
         ConnectionMultiplexer = container.GetRequiredService<ConnectionMultiplexer>(),
         Name = GetQueueName<T>(options),
         Retries = retries,
         Behaviors = container.GetServices<IQueueBehavior<T>>().ToList(),
         WorkItemTimeout = workItemTimeout.GetValueOrDefault(TimeSpan.FromMinutes(5.0)),
         RunMaintenanceTasks = runMaintenanceTasks,
         Serializer = container.GetRequiredService<ISerializer>(),
         LoggerFactory = container.GetRequiredService<ILoggerFactory>()
     });
 }
Пример #4
0
 private static IQueue<T> CreateSQSQueue<T>(IServiceProvider container, QueueOptions options, int retries = 2, TimeSpan? workItemTimeout = null) where T : class {
     return new SQSQueue<T>(new SQSQueueOptions<T> {
         Name = GetQueueName<T>(options),
         Credentials = GetAWSCredentials(options.Data),
         Region = GetAWSRegionEndpoint(options.Data),
         CanCreateQueue = false,
         Retries = retries,
         Behaviors = container.GetServices<IQueueBehavior<T>>().ToList(),
         WorkItemTimeout = workItemTimeout.GetValueOrDefault(TimeSpan.FromMinutes(5.0)),
         Serializer = container.GetRequiredService<ISerializer>(),
         LoggerFactory = container.GetRequiredService<ILoggerFactory>()
     });
 }
Пример #5
0
 private static string GetQueueName <T>(QueueOptions options)
 {
     return(String.Concat(options.ScopePrefix, typeof(T).Name));
 }
Пример #6
0
 private static IQueue <T> CreateAzureStorageQueue <T>(IServiceProvider container, QueueOptions options, int retries = 2, TimeSpan?workItemTimeout = null) where T : class
 {
     return(new AzureStorageQueue <T>(new AzureStorageQueueOptions <T> {
         ConnectionString = options.ConnectionString,
         Name = GetQueueName <T>(options).ToLowerInvariant(),
         Retries = retries,
         Behaviors = container.GetServices <IQueueBehavior <T> >().ToList(),
         WorkItemTimeout = workItemTimeout.GetValueOrDefault(TimeSpan.FromMinutes(5.0)),
         Serializer = container.GetRequiredService <ISerializer>(),
         LoggerFactory = container.GetRequiredService <ILoggerFactory>()
     }));
 }
Пример #7
0
        private static IHealthChecksBuilder RegisterHealthChecks(IServiceCollection services, CacheOptions cacheOptions, MessageBusOptions messageBusOptions, MetricOptions metricOptions, StorageOptions storageOptions, QueueOptions queueOptions)
        {
            services.AddStartupActionToWaitForHealthChecks("Critical");

            return(services.AddHealthChecks()
                   .AddCheckForStartupActions("Critical")

                   .AddAutoNamedCheck <ElasticsearchHealthCheck>("Critical")
                   .AddAutoNamedCheck <CacheHealthCheck>("Critical")
                   .AddAutoNamedCheck <StorageHealthCheck>("EventPosts", "AllJobs")

                   .AddAutoNamedCheck <QueueHealthCheck <EventPost> >("EventPosts", "AllJobs")
                   .AddAutoNamedCheck <QueueHealthCheck <EventUserDescription> >("EventUserDescriptions", "AllJobs")
                   .AddAutoNamedCheck <QueueHealthCheck <EventNotificationWorkItem> >("EventNotifications", "AllJobs")
                   .AddAutoNamedCheck <QueueHealthCheck <WebHookNotification> >("WebHooks", "AllJobs")
                   .AddAutoNamedCheck <QueueHealthCheck <MailMessage> >("AllJobs")
                   .AddAutoNamedCheck <QueueHealthCheck <WorkItemData> >("WorkItem", "AllJobs")

                   .AddAutoNamedCheck <CloseInactiveSessionsJob>("AllJobs")
                   .AddAutoNamedCheck <DailySummaryJob>("AllJobs")
                   .AddAutoNamedCheck <DownloadGeoIPDatabaseJob>("AllJobs")
                   .AddAutoNamedCheck <MaintainIndexesJob>("AllJobs")
                   .AddAutoNamedCheck <RetentionLimitsJob>("AllJobs")
                   .AddAutoNamedCheck <StackEventCountJob>("AllJobs"));
        }