public ConsumerHandler(IConsumerClientFactory consumerClientFactory, MessageServiceOptions messageServiceOptions) { _cts = new CancellationTokenSource(); _consumerClientFactory = consumerClientFactory; _messageServiceOptions = messageServiceOptions; _consumerExecutorDescriptor = _messageServiceOptions._queueServiceMapping.ToDescriptors(); }
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>(); }