Exemplo n.º 1
0
        private static IBioWorldBuilder AddRabbitMq <TContext>(this IBioWorldBuilder builder, RabbitMqOptions options,
                                                               Func <IRabbitMqPluginRegister, IRabbitMqPluginRegister> plugins, Action <IBioWorldBuilder> 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);
        }
Exemplo n.º 2
0
 public static IBioWorldBuilder AddRabbitMq <TContext>(this IBioWorldBuilder 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()));