Exemplo n.º 1
0
        public static void test()
        {
            Producer_Consumer_Queue wt = new Producer_Consumer_Queue();

            wt.Limt          = 10;
            wt.MaxRetryCount = 3;
            wt.IsLongRunning = false;
            wt.IsIntensive   = true;
            int i = 0;

            while (true)
            {
                i++;
                Thread.Sleep(500);
                var num    = i;
                var action = new Action(() =>
                {
                    Thread.Sleep(1000);
                    Console.WriteLine("消费消息:" + num);
                });
                wt.Enqueue(action);
                if (i > 20)
                {
                    break;
                }
            }
            while (true)
            {
                var input  = Console.ReadLine();
                var action = new Action(() =>
                {
                    Thread.Sleep(2000);
                    Console.WriteLine("消费消息:" + input);
                });
                wt.Enqueue(action);
            }
        }
Exemplo n.º 2
0
        internal RedisSubscriber(Func <ISubscriber> clientFactory, string channel, Action <string, string> onMessage)
        {
            if (onMessage == null)
            {
                throw new ArgumentNullException("onMessage");
            }
            _client        = null;
            _isDisposed    = false;
            _clientFactory = clientFactory;
            OnMessage      = (redisChannel, value) =>
            {
                _queue.Enqueue(() => {
                    onMessage(redisChannel, value);
                });
            };

            _channel = channel;

            DoSubscribe(channel).ConfigureAwait(false);
        }