예제 #1
0
            public void ReturnsAllMessagesWhenLastMessageIdIsLessThanAllMessages()
            {
                //    id = 27
                // _, 28, 29, 32
                // ^

                var trace = new TraceManager();
                var bus = new InProcessMessageBus(trace, false);
                bus.Send("testclient", "bar", "1").Wait();
                bus.Send("testclient", "bar", "2").Wait();
                bus.Send("testclient", "foo", "3").Wait();
                bus.Send("testclient", "foo", "4").Wait();

                var result = bus.GetMessages(new[] { "foo" }, "1", CancellationToken.None).Result;
                Assert.Equal(2, result.Messages.Count);
            }
예제 #2
0
            public void ReturnsMessagesGreaterThanLastMessageIdWhenLastMessageIdNotInStore()
            {
                // id = 27
                // 24, 25, 28, 30, 45
                //     ^

                var trace = new TraceManager();
                var bus = new InProcessMessageBus(trace, false);
                bus.Send("testclient", "bar", "1").Wait();
                bus.Send("testclient", "foo", "2").Wait();
                bus.Send("testclient", "bar", "3").Wait();
                bus.Send("testclient", "foo", "4").Wait();
                bus.Send("testclient", "bar", "5").Wait();
                bus.Send("testclient", "foo", "6").Wait();

                var result = bus.GetMessages(new[] { "foo" }, "3", CancellationToken.None).Result;
                Assert.Equal(2, result.Messages.Count);
            }
예제 #3
0
        private static void ReceiveLoop(InProcessMessageBus bus, string[] eventKeys, string id)
        {
            try
            {
                bus.GetMessages(eventKeys, id, CancellationToken.None).ContinueWith(task =>
                {
                    if (task.IsFaulted)
                    {
                        Interlocked.Exchange(ref _exception, task.Exception);
                    }
                    else
                    {
                        var result = task.Result;
                        Interlocked.Increment(ref _received);
                        Interlocked.Increment(ref _avgLastReceivedCount);

                        ReceiveLoop(bus, eventKeys, result.LastMessageId);
                    }
                });
            }
            catch (Exception ex)
            {
                Interlocked.Exchange(ref _exception, ex);
            }
        }