Exemplo n.º 1
0
        private static void ConfigureServices(HostBuilderContext context, IServiceCollection services)
        {
            var configuration = context.Configuration;

            //Buss

            var rabbitMqUri = configuration.GetSection($"{nameof(RabbitMqConfig)}:{nameof(RabbitMqConfig.Uri)}")
                              .Value;
            var userName = configuration.GetSection($"{nameof(RabbitMqConfig)}:{nameof(RabbitMqAuthConfig.UserName)}")
                           .Value;
            var password = configuration.GetSection($"{nameof(RabbitMqConfig)}:{nameof(RabbitMqAuthConfig.Password)}")
                           .Value;
            var config = (rabbitMqUri, userName, password);

            services.AddMassTransit(configurator =>
            {
                configurator.AddBus(provider => Configurator.ConfigureBus(config, (factoryConfigurator, host) =>
                {
                    var submitQueue = configuration
                                      .GetSection($"{nameof(RabbitMqConfig)}:{nameof(RabbitMqConfig.MessageQueue)}").Value;
                    factoryConfigurator.ReceiveEndpoint(host, submitQueue, e =>
                    {
                        e.UseRetry(Retry.Except <ArgumentException>().Intervals(400));
                        e.UseRateLimit(100, TimeSpan.FromSeconds(1));
                        e.Consumer <SubmitMessageHandler>();
                    });
                }));
            });

            services.AddHostedService <MassTransitHostedService>();
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddOptions();
            services.Configure <RabbitMqConfig>(Configuration.GetSection(nameof(RabbitMqConfig)));


            var rabbitMqUri = Configuration.GetSection($"{nameof(RabbitMqConfig)}:{nameof(RabbitMqConfig.Uri)}")
                              .Value;
            var userName = Configuration.GetSection($"{nameof(RabbitMqConfig)}:{nameof(RabbitMqAuthConfig.UserName)}")
                           .Value;
            var password = Configuration.GetSection($"{nameof(RabbitMqConfig)}:{nameof(RabbitMqAuthConfig.Password)}")
                           .Value;
            var config = (rabbitMqUri, userName, password);

            services.AddMassTransit(configurator =>
            {
                configurator.AddBus(provider => Configurator.ConfigureBus(config, (factoryConfigurator, host) =>
                {
                    //Manualy
                    //factoryConfigurator.Message<ISubmitMessage>(topologyConfigurator => topologyConfigurator.SetEntityName("SubmitMessageExchange"));
                }));
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "My API", Version = "v1"
                });
            });

            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });
        }