コード例 #1
0
        public static IServiceCollection AddRabbitMq(this IServiceCollection services, IConfiguration configuration)
        {
            //ToDo: the options must be in appsettings.json
            var defaultOptions = BrokerUtil.GetRabbitMqDefaultOptions();

            services.Configure <RabbitMqOptions>(opt =>
            {
                opt.HostName = defaultOptions.HostName;
                opt.Password = defaultOptions.Password;
                opt.Port     = defaultOptions.Port;
                opt.UserName = defaultOptions.UserName;
                opt.VHost    = defaultOptions.VHost;
            });

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

            services.AddSingleton <IRabbitMqManager, RabbitMqManager>();

            return(services);
        }
コード例 #2
0
        public MessageHanlder()
        {
            var options = Options.Create(BrokerUtil.GetRabbitMqDefaultOptions());

            rabbitMqManager = new RabbitMqManager(new RabbitMqModelPooledObjectPolicy(options));
        }