public ConsumerClient(string queueName, string exchangeName, RabbitMQOptions options)
        {
            _queueName       = queueName;
            _exchageName     = exchangeName;
            _rabbitMQOptions = options;

            InitClient();
        }
Exemplo n.º 2
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton(r =>
            {
                var messageServiceOptions = new MessageServiceOptions();

                messageServiceOptions._queueServiceMapping = Settings.GetSection("rabbitmqServiceMapping").GetChildren()
                                                             .ToDictionary(item => item["Queue"], item => item["Service"]);

                return(messageServiceOptions);
            });

            services.AddSingleton(r =>
            {
                var options = new RabbitMQOptions();

                var rabbitmqSetting = Settings.GetSection("rabbitmq");

                options.HostName                   = rabbitmqSetting["HostName"];
                options.UserName                   = rabbitmqSetting["UserName"];
                options.Password                   = rabbitmqSetting["Password"];
                options.VirtualHost                = rabbitmqSetting["VirtualHost"];
                options.TopicExchangeName          = rabbitmqSetting["TopicExchangeName"];
                options.RequestedConnectionTimeout = int.Parse(rabbitmqSetting["RequestedConnectionTimeout"]);
                options.SocketReadTimeout          = int.Parse(rabbitmqSetting["SocketReadTimeout"]);
                options.SocketWriteTimeout         = int.Parse(rabbitmqSetting["SocketWriteTimeout"]);
                options.Port = int.Parse(rabbitmqSetting["Port"]);

                return(options);
            });

            services.AddSingleton <IConsumerClientFactory, ConsumerClientFactory>(resolver =>
            {
                var rabbitmqOption = resolver.GetService <RabbitMQOptions>();

                return(new ConsumerClientFactory(rabbitmqOption));
            });

            services.AddSingleton <ConsumerHandler>();
        }