예제 #1
0
        /// <summary>
        /// 启动服务
        /// </summary>
        public Task StartAsync(CancellationToken cancellationToken)
        {
            var config = RabbitmqContext.Config;

            if (config == null)
            {
                throw new TypeInitializationException("RabbitmqConfig", null);
            }

            foreach (RabbitmqServiceOptions service in config.Services)
            {
                service.QueueName = service.QueueName.ToLower();
                var channel         = ChannelDic.GetOrAdd(service.QueueName, RabbitmqContext.Connection.CreateModel());
                var constructorArgs = new object[] { channel, service };
                ConsumerFactory.GetInstance(service.QueueName, service.PatternType, constructorArgs).Start();
                _log.Info($"【业务主机】队列:{service.QueueName}启动成功!!!");
            }
            return(Task.CompletedTask);
        }