public static IFixerBuilder AddConsul(this IFixerBuilder builder, string sectionName = SectionName,
                                              string httpClientSectionName = "httpClient")
        {
            var consulOptions     = builder.GetOptions <ConsulOptions>(sectionName);
            var httpClientOptions = builder.GetOptions <HttpClientOptions>(httpClientSectionName);

            return(builder.AddConsul(consulOptions, httpClientOptions));
        }
Esempio n. 2
0
        public static IFixerBuilder AddMongo(this IFixerBuilder builder, string sectionName = SectionName,
                                             IMongoDbSeeder seeder = null)
        {
            var mongoOptions = builder.GetOptions <MongoDbOptions>(sectionName);

            return(builder.AddMongo(mongoOptions, seeder));
        }
Esempio n. 3
0
        public static IFixerBuilder AddServiceClient <T>(this IFixerBuilder builder, string serviceName,
                                                         string sectionName           = SectionName, string consulSectionName = "consul", string fabioSectionName = "fabio",
                                                         string httpClientSectionName = "httpClient")
            where T : class
        {
            var restEaseOptions = builder.GetOptions <RestEaseOptions>(sectionName);

            return(builder.AddServiceClient <T>(serviceName, restEaseOptions,
                                                b => b.AddFabio(fabioSectionName, consulSectionName, httpClientSectionName)));
        }
Esempio n. 4
0
        public static IFixerBuilder AddHttpClient(this IFixerBuilder builder, string sectionName = SectionName)
        {
            if (!builder.TryRegister(RegistryName))
            {
                return(builder);
            }

            var options = builder.GetOptions <HttpClientOptions>(sectionName);

            builder.Services.AddSingleton(options);
            builder.Services.AddHttpClient <IHttpClient, FixerHttpClient>();

            return(builder);
        }
        public static IFixerBuilder AddRedis(this IFixerBuilder builder, string sectionName = SectionName)
        {
            var options = builder.GetOptions <RedisOptions>(sectionName);

            return(builder.AddRedis(options));
        }
Esempio n. 6
0
        public static IFixerBuilder AddJaeger(this IFixerBuilder builder, string sectionName = SectionName)
        {
            var options = builder.GetOptions <JaegerOptions>(sectionName);

            return(builder.AddJaeger(options));
        }
Esempio n. 7
0
        public static IFixerBuilder AddRabbitMq(this IFixerBuilder builder, string sectionName = SectionName)
        {
            var options = builder.GetOptions <RabbitMqOptions>(sectionName);

            builder.Services.AddSingleton(options);
            if (!builder.TryRegister(RegistryName))
            {
                return(builder);
            }

            builder.Services.AddSingleton <IContextProvider, ContextProvider>();
            builder.Services.AddSingleton <ICorrelationContextAccessor>(new CorrelationContextAccessor());
            builder.Services.AddSingleton <IMessagePropertiesAccessor>(new MessagePropertiesAccessor());
            builder.Services.AddSingleton <IConventionsBuilder, ConventionsBuilder>();
            builder.Services.AddSingleton <IConventionsProvider, ConventionsProvider>();
            builder.Services.AddSingleton <IConventionsRegistry, ConventionsRegistry>();
            builder.Services.AddSingleton <IRabbitMqSerializer, NewtonsoftJsonRabbitMqSerializer>();
            builder.Services.AddSingleton <IRabbitMqClient, RabbitMqClient>();
            builder.Services.AddSingleton <IBusPublisher, RabbitMqPublisher>();
            builder.Services.AddSingleton <IBusSubscriber, RabbitMqSubscriber>();
            if (options.MessageProcessor?.Enabled == true)
            {
                builder.Services.AddSingleton <IRabbitMqMiddleware, UniqueMessagesMiddleware>();
                builder.Services.AddSingleton <IUniqueMessagesMiddleware, UniqueMessagesMiddleware>();
                switch (options.MessageProcessor.Type?.ToLowerInvariant())
                {
                default:
                    builder.Services.AddMemoryCache();
                    builder.Services.AddSingleton <IMessageProcessor, InMemoryMessageProcessor>();
                    break;
                }
            }
            else
            {
                builder.Services.AddSingleton <IMessageProcessor, EmptyMessageProcessor>();
            }

            builder.Services.AddSingleton(sp =>
            {
                var connectionFactory = new ConnectionFactory
                {
                    HostName    = options.HostNames?.FirstOrDefault(),
                    Port        = options.Port,
                    VirtualHost = options.VirtualHost,
                    UserName    = options.Username,
                    Password    = options.Password,
                    RequestedConnectionTimeout = options.RequestedConnectionTimeout,
                    SocketReadTimeout          = options.SocketReadTimeout,
                    SocketWriteTimeout         = options.SocketWriteTimeout,
                    RequestedChannelMax        = options.RequestedChannelMax,
                    RequestedFrameMax          = options.RequestedFrameMax,
                    RequestedHeartbeat         = options.RequestedHeartbeat,
                    UseBackgroundThreadsForIO  = options.UseBackgroundThreadsForIO,
                    DispatchConsumersAsync     = true,
                    Ssl = options.Ssl is null
                        ? new SslOption()
                        : new SslOption(options.Ssl.ServerName, options.Ssl.CertificatePath, options.Ssl.Enabled)
                };

                var connection = connectionFactory.CreateConnection(options.ConnectionName);
                if (options.Exchange is null || !options.Exchange.Declare)
                {
                    return(connection);
                }

                using (var channel = connection.CreateModel())
                {
                    if (options.Logger?.Enabled == true)
                    {
                        var logger = sp.GetService <ILogger <IConnection> >();
                        logger.LogInformation($"Declaring an exchange: '{options.Exchange.Name}', type: '{options.Exchange.Type}'.");
                    }

                    channel.ExchangeDeclare(options.Exchange.Name, options.Exchange.Type, options.Exchange.Durable,
                                            options.Exchange.AutoDelete);
                    channel.Close();
                }

                return(connection);
            });

            return(builder);
        }