Exemplo n.º 1
0
        /// <summary>
        /// Add Mass Transit rabitMq message broker
        /// </summary>
        /// <param name="services"></param>
        private static void AddMassTransitRabbitMq(IServiceCollection services, AppConfig config, AppTypeSearcher typeSearcher)
        {
            if (!config.RabbitEnabled)
            {
                return;
            }
            services.AddMassTransit(x =>
            {
                x.AddConsumers(q => !q.Equals(typeof(CacheMessageEventConsumer)), typeSearcher.GetAssemblies().ToArray());

                // reddits have more priority
                if (!config.RedisPubSubEnabled && config.RabbitCachePubSubEnabled)
                {
                    x.AddConsumer <CacheMessageEventConsumer>().Endpoint(t => t.Name = config.RabbitCacheReceiveEndpoint);
                }

                x.UsingRabbitMq((context, cfg) =>
                {
                    cfg.Host(config.RabbitHostName, config.RabbitVirtualHost, h =>
                    {
                        h.Password(config.RabbitPassword);
                        h.Username(config.RabbitUsername);
                    });
                    cfg.ConfigureEndpoints(context);
                });
            });
            //for automaticly start/stop bus
            services.AddMassTransitHostedService();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds services for mediatR
        /// </summary>
        /// <param name="services">Collection of service descriptors</param>
        private static void AddMediator(this IServiceCollection services, AppTypeSearcher typeSearcher)
        {
            var assemblies = typeSearcher.GetAssemblies().ToArray();

            services.AddMediatR(assemblies);
        }