public static IQueueProvider CreateProvider(QueueProvider provider, bool singleton = false) { if (provider == QueueProvider.Configured) { QueueProvider outProvider; var strProvider = ConfigSource.FirstAppSetting("DQueue.Provider", "QueueProvider"); if (Enum.TryParse <QueueProvider>(strProvider, true, out outProvider)) { provider = outProvider; } else { throw new ArgumentException("Can not support queue provider: " + strProvider); } } if (provider == QueueProvider.Redis) { return(new RedisProvider()); } if (provider == QueueProvider.RabbitMQ) { return(new RabbitMQProvider()); } if (provider == QueueProvider.AspNet) { return(new AspNetProvider()); } throw new ArgumentException("Can not support queue provider: " + provider.ToString()); }
public QueueConsumer(string queueName, int maximumThreads) { MaximumThreads = maximumThreads; HostId = ConfigSource.GetAppSetting("DQueue.HostId"); QueueName = queueName ?? QueueNameGenerator.GetQueueName <TMessage>(); Timeout = ConfigSource.FirstAppSetting("DQueue.ConsumerTimeout", "ConsumerTimeout").AsNullableTimeSpan(); if (string.IsNullOrWhiteSpace(HostId)) { throw new ArgumentNullException("HostId"); } if (string.IsNullOrWhiteSpace(QueueName)) { throw new ArgumentNullException("queueName"); } if (MaximumThreads < 1) { throw new ArgumentOutOfRangeException("maximumThreads"); } _provider = Constants.DefaultProvider; _cts = new CancellationTokenSource(); _messageHandlers = new List <Action <DispatchContext <TMessage> > >(); _timeoutHandlers = new List <Action <DispatchContext <TMessage> > >(); _completeHandlers = new List <Action <DispatchContext <TMessage> > >(); }