public void recovers_delayed_messages_when_started()
        {
            using (var queues = new PersistentQueues(new RecordingLogger(), new DelayedMessageCache<MessageId>(), new LightningQueueSettings()))
            {
                queues.ClearAll();
                queues.Start(new []{ new LightningUri("lq.tcp://localhost:2425/the_queue") });

                var envelope = new Envelope();
                envelope.Data = new byte[0];
                envelope.ExecutionTime = DateTime.UtcNow;
                var delayedMessage = new MessagePayload
                {
                    Data = envelope.Data,
                    Headers = envelope.Headers.ToNameValues()
                };

                using (var scope = new TransactionScope())
                {
                    queues.ManagerFor(2425, true)
                        .EnqueueDirectlyTo(LightningQueuesTransport.DelayedQueueName, null, delayedMessage);
                    scope.Complete();
                }
            }

            var cache = new DelayedMessageCache<MessageId>();
            using (var queues = new PersistentQueues(new RecordingLogger(), cache, new LightningQueueSettings()))
            {
                queues.Start(new []{ new LightningUri("lq.tcp://localhost:2425/the_queue") });

                cache.AllMessagesBefore(DateTime.UtcNow.AddSeconds(1)).ShouldNotBeEmpty();
            }
        }
        public void recovers_delayed_messages_when_started()
        {
            using (var queues = new PersistentQueues(new RecordingLogger(), new DelayedMessageCache <MessageId>(), new LightningQueueSettings()))
            {
                queues.ClearAll();
                queues.Start(new [] { new LightningUri("lq.tcp://localhost:2425/the_queue") });

                var envelope = new Envelope();
                envelope.Data          = new byte[0];
                envelope.ExecutionTime = DateTime.UtcNow;
                var delayedMessage = new MessagePayload
                {
                    Data    = envelope.Data,
                    Headers = envelope.Headers.ToNameValues()
                };

                using (var scope = new TransactionScope())
                {
                    queues.ManagerFor(2425, true)
                    .EnqueueDirectlyTo(LightningQueuesTransport.DelayedQueueName, null, delayedMessage);
                    scope.Complete();
                }
            }

            var cache = new DelayedMessageCache <MessageId>();

            using (var queues = new PersistentQueues(new RecordingLogger(), cache, new LightningQueueSettings()))
            {
                queues.Start(new [] { new LightningUri("lq.tcp://localhost:2425/the_queue") });

                cache.AllMessagesBefore(DateTime.UtcNow.AddSeconds(1)).ShouldNotBeEmpty();
            }
        }
        public void settings_that_are_changed_are_also_changed_in_queue_manager()
        {
            var settings = new LightningQueueSettings
            {
                EnableOutgoingMessageHistory             = false,
                EnableProcessedMessageHistory            = false,
                NumberOfMessagesToKeepInOutgoingHistory  = 1,
                NumberOfMessagesToKeepInProcessedHistory = 2,
                NumberOfReceivedMessageIdsToKeep         = 3,
                OldestMessageInOutgoingHistory           = TimeSpan.FromSeconds(1),
                OldestMessageInProcessedHistory          = TimeSpan.FromSeconds(1),
            };

            using (var queues = new PersistentQueues(new RecordingLogger(), new DelayedMessageCache <MessageId>(), settings))
            {
                queues.ClearAll();
                queues.Start(new[] { new LightningUri("lq.tcp://localhost:2424/some_queue") });
                var queueManager = queues.ManagerFor(2424, true);
                var actual       = queueManager.Configuration;
                actual.EnableOutgoingMessageHistory.ShouldEqual(settings.EnableOutgoingMessageHistory);
                actual.EnableProcessedMessageHistory.ShouldEqual(settings.EnableProcessedMessageHistory);
                actual.NumberOfMessagesToKeepInOutgoingHistory.ShouldEqual(settings.NumberOfMessagesToKeepInOutgoingHistory);
                actual.NumberOfMessagesToKeepInProcessedHistory.ShouldEqual(settings.NumberOfMessagesToKeepInProcessedHistory);
                actual.NumberOfReceivedMessageIdsToKeep.ShouldEqual(settings.NumberOfReceivedMessageIdsToKeep);
                actual.OldestMessageInOutgoingHistory.ShouldEqual(settings.OldestMessageInOutgoingHistory);
                actual.OldestMessageInProcessedHistory.ShouldEqual(settings.OldestMessageInProcessedHistory);
            }
        }
        private void SetupTransport(string uri)
        {
            graph         = new ChannelGraph();
            node          = graph.ChannelFor <ChannelSettings>(x => x.Upstream);
            node.Uri      = new Uri(uri);
            node.Incoming = true;

            var delayedCache = new DelayedMessageCache <MessageId>();

            queues = new PersistentQueues(new RecordingLogger(), delayedCache, new LightningQueueSettings());
            queues.ClearAll();
            transport = new LightningQueuesTransport(queues, new LightningQueueSettings(), delayedCache);

            transport.OpenChannels(graph);
        }
        public void creates_queues_when_started()
        {
            using (var queues = new PersistentQueues(new RecordingLogger()))
            {
                queues.ClearAll();
                queues.Start(new LightningUri[]
                {
                    new LightningUri("lq.tcp://localhost:2424/some_queue"),
                    new LightningUri("lq.tcp://localhost:2424/other_queue"),
                    new LightningUri("lq.tcp://localhost:2424/third_queue"),
                });

                queues.PersistentManagerFor(2424, true)
                    .Queues.OrderBy(x => x).ShouldHaveTheSameElementsAs(LightningQueuesTransport.ErrorQueueName, "other_queue", "some_queue", "third_queue");
            }
        }
        private void SetupTransport(string uri, ChannelMode mode)
        {
            graph = new ChannelGraph();
            node = graph.ChannelFor<ChannelSettings>(x => x.Upstream);
            node.Mode = mode;

            node.Uri = new Uri(uri);
            node.Incoming = true;

            var delayedCache = new DelayedMessageCache<MessageId>();
            queues = new PersistentQueues(new RecordingLogger());
            queues.ClearAll();
            transport = new LightningQueuesTransport(queues, new LightningQueueSettings());

            transport.OpenChannels(graph);
        }
Esempio n. 7
0
        public void creates_queues_when_started()
        {
            using (var queues = new PersistentQueues(new RecordingLogger()))
            {
                queues.ClearAll();
                queues.Start(new LightningUri[]
                {
                    new LightningUri("lq.tcp://localhost:2424/some_queue"),
                    new LightningUri("lq.tcp://localhost:2424/other_queue"),
                    new LightningUri("lq.tcp://localhost:2424/third_queue"),
                });

                queues.PersistentManagerFor(2424, true)
                .Queues.OrderBy(x => x).ShouldHaveTheSameElementsAs(LightningQueuesTransport.ErrorQueueName, "other_queue", "some_queue", "third_queue");
            }
        }
 public void default_settings_match_lightning_queues_default_configuration()
 {
     var defaultConfiguration = new QueueManagerConfiguration();
     //could probably do this without constructing the queue manager, but probably safer down the road this way
     using (var queues = new PersistentQueues(new RecordingLogger(), new DelayedMessageCache<MessageId>(), new LightningQueueSettings()))
     {
         queues.ClearAll();
         queues.Start(new[] {new LightningUri("lq.tcp://localhost:2424/some_queue")});
         var queueManager = queues.ManagerFor(2424, true);
         var actual = queueManager.Configuration;
         actual.EnableOutgoingMessageHistory.ShouldEqual(defaultConfiguration.EnableOutgoingMessageHistory);
         actual.EnableProcessedMessageHistory.ShouldEqual(defaultConfiguration.EnableProcessedMessageHistory);
         actual.NumberOfMessagesToKeepInOutgoingHistory.ShouldEqual(defaultConfiguration.NumberOfMessagesToKeepInOutgoingHistory);
         actual.NumberOfMessagesToKeepInProcessedHistory.ShouldEqual(defaultConfiguration.NumberOfMessagesToKeepInProcessedHistory);
         actual.NumberOfReceivedMessageIdsToKeep.ShouldEqual(defaultConfiguration.NumberOfReceivedMessageIdsToKeep);
         actual.OldestMessageInOutgoingHistory.ShouldEqual(defaultConfiguration.OldestMessageInOutgoingHistory);
         actual.OldestMessageInProcessedHistory.ShouldEqual(defaultConfiguration.OldestMessageInProcessedHistory);
     }
 }
        public void default_settings_match_lightning_queues_default_configuration()
        {
            var defaultConfiguration = new QueueManagerConfiguration();

            //could probably do this without constructing the queue manager, but probably safer down the road this way
            using (var queues = new PersistentQueues(new RecordingLogger(), new DelayedMessageCache <MessageId>(), new LightningQueueSettings()))
            {
                queues.ClearAll();
                queues.Start(new[] { new LightningUri("lq.tcp://localhost:2424/some_queue") });
                var queueManager = queues.ManagerFor(2424, true);
                var actual       = queueManager.Configuration;
                actual.EnableOutgoingMessageHistory.ShouldEqual(defaultConfiguration.EnableOutgoingMessageHistory);
                actual.EnableProcessedMessageHistory.ShouldEqual(defaultConfiguration.EnableProcessedMessageHistory);
                actual.NumberOfMessagesToKeepInOutgoingHistory.ShouldEqual(defaultConfiguration.NumberOfMessagesToKeepInOutgoingHistory);
                actual.NumberOfMessagesToKeepInProcessedHistory.ShouldEqual(defaultConfiguration.NumberOfMessagesToKeepInProcessedHistory);
                actual.NumberOfReceivedMessageIdsToKeep.ShouldEqual(defaultConfiguration.NumberOfReceivedMessageIdsToKeep);
                actual.OldestMessageInOutgoingHistory.ShouldEqual(defaultConfiguration.OldestMessageInOutgoingHistory);
                actual.OldestMessageInProcessedHistory.ShouldEqual(defaultConfiguration.OldestMessageInProcessedHistory);
            }
        }
 public void settings_that_are_changed_are_also_changed_in_queue_manager()
 {
     var settings = new LightningQueueSettings
     {
         EnableOutgoingMessageHistory = false,
         EnableProcessedMessageHistory = false,
         NumberOfMessagesToKeepInOutgoingHistory = 1,
         NumberOfMessagesToKeepInProcessedHistory = 2,
         NumberOfReceivedMessageIdsToKeep = 3,
         OldestMessageInOutgoingHistory = TimeSpan.FromSeconds(1),
         OldestMessageInProcessedHistory = TimeSpan.FromSeconds(1),
     };
     using (var queues = new PersistentQueues(new RecordingLogger(), new DelayedMessageCache<MessageId>(), settings))
     {
         queues.ClearAll();
         queues.Start(new[] { new LightningUri("lq.tcp://localhost:2424/some_queue") });
         var queueManager = queues.ManagerFor(2424, true);
         var actual = queueManager.Configuration;
         actual.EnableOutgoingMessageHistory.ShouldEqual(settings.EnableOutgoingMessageHistory);
         actual.EnableProcessedMessageHistory.ShouldEqual(settings.EnableProcessedMessageHistory);
         actual.NumberOfMessagesToKeepInOutgoingHistory.ShouldEqual(settings.NumberOfMessagesToKeepInOutgoingHistory);
         actual.NumberOfMessagesToKeepInProcessedHistory.ShouldEqual(settings.NumberOfMessagesToKeepInProcessedHistory);
         actual.NumberOfReceivedMessageIdsToKeep.ShouldEqual(settings.NumberOfReceivedMessageIdsToKeep);
         actual.OldestMessageInOutgoingHistory.ShouldEqual(settings.OldestMessageInOutgoingHistory);
         actual.OldestMessageInProcessedHistory.ShouldEqual(settings.OldestMessageInProcessedHistory);
     }
 }
        public void Setup()
        {
            graph = new ChannelGraph();
            node = graph.ChannelFor<ChannelSettings>(x => x.Upstream);
            node.Uri = new Uri("lq.tcp://localhost:2020/upstream");
            node.Incoming = true;

            var delayedCache = new DelayedMessageCache<MessageId>();
            queues = new PersistentQueues(new RecordingLogger(), delayedCache);
            queues.ClearAll();
            transport = new LightningQueuesTransport(queues, new LightningQueueSettings(), delayedCache);

            transport.OpenChannels(graph);
        }