コード例 #1
0
        public void CanReceiveSeveralMessagesInAStreamConcurrently()
        {
            var received = new ConcurrentBag <Message>();

            for (int i = 0; i < 4; ++i)
            {
                ThreadPool.QueueUserWorkItem(_ =>
                {
                    var messages = _receiver.ReceiveStream("h", null);
                    foreach (var x in messages)
                    {
                        received.Add(x.Message);
                        x.TransactionalScope.Commit();
                    }
                });
            }
            for (int i = 0; i < 20; ++i)
            {
                var scope = _sender.BeginTransactionalScope();
                scope.Send(new Uri("rhino.queues://localhost:23457/h"),
                           new MessagePayload
                {
                    Data = new byte[] { (byte)i, 2, 4, 5 }
                });
                scope.Commit();
            }

            Wait.Until(() => received.Count == 20, timeoutInMilliseconds: 10000).ShouldBeTrue();
        }
コード例 #2
0
        public IEnumerable <EnvelopeToken> ReplayDelayed(QueueManager queueManager, DateTime currentTime)
        {
            var list = new List <EnvelopeToken>();

            var transactionalScope = queueManager.BeginTransactionalScope();

            try
            {
                var readyToSend = _delayedMessages.AllMessagesBefore(currentTime);

                readyToSend.Each(x =>
                {
                    var message = transactionalScope.ReceiveById(LightningQueuesTransport.DelayedQueueName, x);
                    var uri     = message.Headers[Envelope.ReceivedAtKey].ToLightningUri();
                    MessagePayload messagePayload = message.ToPayload();
                    transactionalScope.EnqueueDirectlyTo(uri.QueueName, messagePayload);
                    list.Add(message.ToToken());
                });
                transactionalScope.Commit();
            }

            catch (Exception e)
            {
                transactionalScope.Rollback();
                _logger.Error("Error trying to move delayed messages back to the original queue", e);
            }

            return(list);
        }
コード例 #3
0
        public void CanReceiveSeveralMessagesInAStreamConcurrently()
        {
            var received = new ConcurrentBag <Message>();

            ThreadPool.QueueUserWorkItem(_ =>
            {
                var messages = _receiver.ReceiveStream("h", null);
                Parallel.ForEach(messages, new ParallelOptions {
                    MaxDegreeOfParallelism = 4
                }, x =>
                {
                    received.Add(x.Message);
                    x.TransactionalScope.Commit();
                });
            });

            for (int i = 0; i < 20; ++i)
            {
                var scope = _sender.BeginTransactionalScope();
                scope.Send(new Uri("rhino.queues://localhost:23457/h"),
                           new MessagePayload
                {
                    Data = new byte[] { (byte)i, 2, 4, 5 }
                });
                scope.Commit();
            }

            Wait.Until(() => received.Count == 20).ShouldBeTrue();
        }
コード例 #4
0
        private void sendMessages()
        {
            var scope = _sender.BeginTransactionalScope();

            for (int i = 0; i < 50; ++i)
            {
                scope.Send(new Uri("rhino.queues://localhost:23457/h"),
                           new MessagePayload
                {
                    Data = new byte[] { 1, 2, 4, 5 }
                });
            }
            scope.Commit();
        }
コード例 #5
0
        public void ClearsQueueMessages()
        {
            _sender.Start();
            _receiver.Start();
            sendMessages();
            Wait.Until(() => _receiver.GetAllMessages("h", null).Length == 50).ShouldBeTrue();

            var scope = _receiver.BeginTransactionalScope();

            scope.Receive("h");
            scope.Commit();
            _receiver.GetAllProcessedMessages("h").ShouldHaveCount(1);
            _receiver.ClearAllMessages();
            _receiver.GetAllMessages("h", null).ShouldHaveCount(0);
            _receiver.GetAllProcessedMessages("h").ShouldHaveCount(0);
        }
コード例 #6
0
        public void can_receive_message()
        {
            var sender = ObjectMother.Sender();

            sender.Send();

            var transactionalScope = queueManager.BeginTransactionalScope();
            var message            = transactionalScope.Receive("h");

            Assert.Equal("hello", Encoding.Unicode.GetString(message.Data));
            transactionalScope.Commit();

            var transactionalScope2 = queueManager.BeginTransactionalScope();

            Assert.Throws <TimeoutException>(() => transactionalScope2.Receive("h", TimeSpan.Zero));
        }