Example #1
0
        private IConnection GetConnection(RabbitMqConnectionSettings connectionSettings)
        {
            var factory = new ConnectionFactory()
            {
                VirtualHost            = connectionSettings.VirtualHost,
                HostName               = connectionSettings.HostName,
                UserName               = connectionSettings.UserName,
                Password               = connectionSettings.Password,
                Port                   = connectionSettings.Port,
                DispatchConsumersAsync = true
            };

            return(factory.CreateConnection());
        }
        public static IServiceCollection AddRabbitMq(this IServiceCollection services, IConfiguration configuration)
        {
            var rabbitMqConnection = new RabbitMqConnectionSettings();

            configuration.GetSection("RabbitMq:Connection").Bind(rabbitMqConnection);
            services.AddSingleton(rabbitMqConnection);

            var rabbitMqRouting = new RabbitMqPubSubSettings();

            configuration.GetSection("RabbitMq:Routing").Bind(rabbitMqRouting);
            services.AddSingleton(rabbitMqRouting);

            services.AddSingleton <ObjectPoolProvider, DefaultObjectPoolProvider>();
            services.AddSingleton <IPooledObjectPolicy <IModel>, RabbitMqModelPooledObjectPolicyAsync>();

            return(services);
        }
Example #3
0
 public RabbitMqModelPooledObjectPolicyAsync(RabbitMqConnectionSettings options)
 {
     _connection = GetConnection(options);
 }