コード例 #1
0
        private void TransportOnMessageSent(CurrentMessageInformation currentMessageInformation)
        {
            var containsNonCachableMessages = currentMessageInformation.AllMessages.Any(x => x is ICacheableRequest == false);

            var cacheableRequests = currentMessageInformation.AllMessages.OfType <ICacheableRequest>();

            if (containsNonCachableMessages)
            {
                // since we are making a non cachable request, the
                // _cachable_ requests part of this batch are likely to be
                // affected by this message, so we go ahead and expire them
                // to avoid showing incorrect data
                foreach (var cachableRequestToExpire in cacheableRequests)
                {
                    cache.Remove(cachableRequestToExpire.Key);
                }
                return;
            }

            var responses =
                from msg in cacheableRequests
                let response = cache.Get(msg.Key)
                               where response != null
                               select response.Value;

            var array = responses.ToArray();

            if (array.Length == 0)
            {
                return;
            }
            bus.ConsumeMessages(array);
        }
コード例 #2
0
        public void Disposable_Consumer_is_disposed()
        {
            this.container.Register(Component.For <DisposableConsumer>().LifeStyle.Transient);

            DisposableConsumer.ResetCounters();
            Assert.Equal(0, DisposableConsumer.ConsumedMessages);
            Assert.Equal(0, DisposableConsumer.NotDisposedInstances);

            bus.ConsumeMessages("TestMessage");

            Assert.Equal(1, DisposableConsumer.ConsumedMessages);
            Assert.Equal(0, DisposableConsumer.NotDisposedInstances);
        }