Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();

            var streamFlowOptions = new StreamFlowOptions
            {
                ServiceId      = "sf-tests",
                QueuePrefix    = "SFQ.",
                ExchangePrefix = "SFE."
            };

            services.AddDbContext <ApplicationDbContext>(options =>
            {
                options.UseNpgsql("Server=localhost;User Id=admin;Password=admin;Database=StreamFlow");
            });

            services.AddMediatR(typeof(Startup).Assembly);

            services.AddStreamFlow(streamFlowOptions, transport =>
            {
                transport
                .UseRabbitMq(mq => mq
                             .Connection("localhost", "guest", "guest")
                             .EnableConsumerHost(consumer => consumer.Prefetch(5))
                             .WithPrometheusMetrics()
                             .WithPublisherOptions(publisher => publisher
                                                   .EnablePublisherTransactions()
                                                   .EnablePublisherHost()
                                                   .EnablePublisherPooling()
                                                   )
                             )
                .Consumers(builder => builder
                           .Add <PingMessage, PingMessageConsumer>(options => options
                                                                   .ConsumerCount(25)
                                                                   .ConsumerGroup("gr4")
                                                                   .IncludeHeadersToLoggerScope()
                                                                   .ConfigureQueue(q => q.AutoDelete())
                                                                   )
                           .Add <TimeSheetEditedEvent, TimeSheetEditedEventConsumer>()
                           .Add <RaiseRequest, RaiseRequestConsumer>(opt => opt.Prefetch(1))
                           .AddNotification <PingNotification>(opt => opt.Prefetch(1))
                           .AddRequest <PingRequest>(opt => opt.Prefetch(1))
                           .AddRequest <PingPongRequest, PongResponse>(opt => opt.Prefetch(1))
                           .AddNotification <PongResponse>(opt => opt.Prefetch(1))
                           )
                .ConfigureConsumerPipe(builder => builder
                                       .Use <LogAppIdMiddleware>()
                                       )
                .ConfigurePublisherPipe(builder => builder
                                        .Use(_ => new SetAppIdMiddleware("Published from StreamFlow.Tests.AspNetCore", "StreamFlow Asp.Net Core Test"))
                                        );
            });

            //services.AddHostedService<HighLoadPublisherHostedService>();
        }
        public StreamFlowRabbitMq(IServiceCollection services, StreamFlowOptions options)
        {
            _services = services;
            _options  = options;

            services.TryAddSingleton <IRabbitMqConventions, RabbitMqConventions>();
            services.TryAddSingleton <IMessageSerializer, RabbitMqMessageSerializer>();
            services.TryAddSingleton <IOutboxMessageAddressProvider, RabbitMqMessageAddressProvider>();
            services.TryAddScoped <ILoggerScopeStateFactory, LoggerScopeStateFactory>();
            services.TryAddSingleton <IRabbitMqMetrics, RabbitMqNoOpMetrics>();

            services.TryAddScoped <IPublisher, RabbitMqPublisher>();
            services.TryAddSingleton <IRabbitMqPublisherChannel, RabbitMqPublisherChannel>();
            services.TryAddSingleton <IRabbitMqPublisherBus, RabbitMqPublisherBus>();

            _publisherOptions = new RabbitMqPublisherOptions();
            services.AddSingleton(_publisherOptions);

            _consumerOptions = new RabbitMqConsumerOptions();
            services.AddSingleton(_consumerOptions);
        }
 public RabbitMqConventions(StreamFlowOptions options)
 {
     _options = options;
 }
        public static IServiceCollection AddStreamFlow(this IServiceCollection services, StreamFlowOptions options, Action <IStreamFlowTransport> transport)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (transport == null)
            {
                throw new ArgumentNullException(nameof(transport));
            }

            var registrations = new ConsumerRegistrations();

            services.AddSingleton <IConsumerRegistrations>(_ => registrations);

            services.AddSingleton(options);

            var builder = new StreamFlowBuilder(services, registrations, options);

            transport(builder);

            builder.WithOutboxSupport(_ => { });

            return(services);
        }