示例#1
0
        public async Task TestConfirmed()
        {
            var queue = new SimpleQueue <SimpleDocument>(GetType().FullName);
            await queue.Clear();

            await queue.Enqueue(new SimpleDocument()
            {
                Value = "test"
            });

            var value = await queue.Dequeue(new DequeueOptions()
            {
                ConfirmTime = TimeSpan.FromMilliseconds(500)
            });

            Assert.AreEqual("test", value.Payload.Value);

            await queue.Confirm(value);


            value = await queue.Dequeue();

            Assert.IsNull(value);

            await Task.Delay(1000);

            value = await queue.Dequeue();

            Assert.IsNull(value);
        }
示例#2
0
        private async Task Consume()
        {
            var queue = new SimpleQueue <SimpleDocument>(this.GetType().FullName);

            while (_totalConsumed < 40)
            {
                var item = await queue.Dequeue();

                if (item != null)
                {
                    Console.WriteLine($"[{Thread.CurrentThread.ManagedThreadId}] Consumed: {item.Payload}");
                    Interlocked.Increment(ref _totalConsumed);
                    await queue.Confirm(item);
                }

                //Very long work
                await Task.Delay(_random.Next(500));
            }
        }