Пример #1
0
        private static IConveyBuilder AddRabbitMq <TContext>(this IConveyBuilder builder, RabbitMqOptions options,
                                                             Func <IRabbitMqPluginRegister, IRabbitMqPluginRegister> plugins, Action <IConveyBuilder> registerRedis)
            where TContext : class, new()
        {
            builder.Services.AddSingleton(options);
            builder.Services.AddSingleton <RawRabbitConfiguration>(options);
            if (!builder.TryRegister(RegistryName))
            {
                return(builder);
            }

            builder.Services.AddTransient <IBusPublisher, BusPublisher>();
            if (options.MessageProcessor?.Enabled == true)
            {
                switch (options.MessageProcessor.Type?.ToLowerInvariant())
                {
                case "redis":
                    registerRedis(builder);
                    builder.Services.AddTransient <IMessageProcessor, RedisMessageProcessor>();
                    break;

                default:
                    builder.Services.AddTransient <IMessageProcessor, InMemoryMessageProcessor>();
                    break;
                }
            }
            else
            {
                builder.Services.AddSingleton <IMessageProcessor, EmptyMessageProcessor>();
            }

            builder.Services.AddSingleton <ICorrelationContextAccessor>(new CorrelationContextAccessor());

            ConfigureBus <TContext>(builder, plugins);

            return(builder);
        }
Пример #2
0
 public static IConveyBuilder AddRabbitMq <TContext>(this IConveyBuilder builder, RabbitMqOptions options,
                                                     Func <IRabbitMqPluginRegister, IRabbitMqPluginRegister> plugins = null,
                                                     RedisOptions redisOptions = null)
     where TContext : class, new()
 => builder.AddRabbitMq <TContext>(options, plugins, b => b.AddRedis(redisOptions ?? new RedisOptions()));