public void Send(byte[] data, IHeaders headers)
 {
     var payload = new MessagePayload {Data = data, Headers = headers.ToNameValues()};
     var scope = _queueManager.BeginTransactionalScope();
     scope.Send(Address, payload);
     scope.Commit();
 }
 public void empty_when_headers_arent_present()
 {
     var message = new MessagePayload();
     message.TranslateHeaders();
     message.MaxAttempts.ShouldBeNull();
     message.DeliverBy.ShouldBeNull();
 }
        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 translates_max_attempts()
 {
     var message = new MessagePayload();
     message.Headers.Add(LightningQueuesChannel.MaxAttemptsHeader, 1.ToString());
     message.TranslateHeaders();
     message.MaxAttempts.ShouldBe(1);
 }
 public void translates_deliver_by()
 {
     var now = DateTime.Now;
     var message = new MessagePayload();
     message.Headers.Add(LightningQueuesChannel.DeliverByHeader, now.ToString("o"));
     message.TranslateHeaders();
     message.DeliverBy.ShouldBe(now);
 }
Exemplo n.º 6
0
        public MessageId Send(Uri uri, MessagePayload payload)
        {
            if (_waitingForAllMessagesToBeSent)
            {
                throw new CannotSendWhileWaitingForAllMessagesToBeSentException("Currently waiting for all messages to be sent, so we cannot send. You probably have a race condition in your application.");
            }

            EnsureEnlistment();

            return(Send(_enlistment, uri, payload));
        }
        public void MoveToErrors(ErrorReport report)
        {
            var messagePayload = new MessagePayload
            {
                Data = report.Serialize(),
                Headers = report.Headers
            };

            messagePayload.Headers.Add("ExceptionType", report.ExceptionType);

            _transaction.EnqueueDirectlyTo(LightningQueuesTransport.ErrorQueueName, messagePayload, _message.Id);
            MarkSuccessful();
        }
Exemplo n.º 8
0
        public MessageId Send(ITransaction transaction, Uri uri, MessagePayload payload)
        {
            if (_waitingForAllMessagesToBeSent)
            {
                throw new CannotSendWhileWaitingForAllMessagesToBeSentException("Currently waiting for all messages to be sent, so we cannot send. You probably have a race condition in your application.");
            }

            var    parts    = uri.AbsolutePath.Substring(1).Split('/');
            var    queue    = parts[0];
            string subqueue = null;

            if (parts.Length > 1)
            {
                subqueue = string.Join("/", parts.Skip(1).ToArray());
            }

            Guid msgId = Guid.Empty;

            var port = uri.Port;

            if (port == -1)
            {
                port = 2200;
            }
            var destination = new Endpoint(uri.Host, port);

            _queueStorage.Global(actions =>
            {
                msgId = actions.RegisterToSend(destination, queue,
                                               subqueue, payload, transaction.Id);
            });

            var messageId = new MessageId
            {
                SourceInstanceId  = _queueStorage.Id,
                MessageIdentifier = msgId
            };
            var message = new Message
            {
                Id       = messageId,
                Data     = payload.Data,
                Headers  = payload.Headers,
                Queue    = queue,
                SubQueue = subqueue
            };

            _logger.QueuedForSend(message, destination);

            return(messageId);
        }
        public void Send(byte[] data, IHeaders headers)
        {
            var messagePayload = new MessagePayload
            {
                Data = data,
                Headers = headers.ToNameValues()
            };

            var sendingScope = _queueManager.BeginTransactionalScope();
            var id = sendingScope.Send(_address, messagePayload);

            // TODO -- do we grab this?

            //data.CorrelationId = id.MessageIdentifier;
            sendingScope.Commit();
        }
        public void Send(byte[] data, IHeaders headers)
        {
            var messagePayload = new MessagePayload
            {
                Data = data,
                Headers = headers.ToNameValues()
            };
            //TODO Maybe expose something to modify transport specific payloads?
            messagePayload.TranslateHeaders();

            var sendingScope = _queueManager.BeginTransactionalScope();
            var id = sendingScope.Send(_address, messagePayload);

            // TODO -- do we grab this?

            //data.CorrelationId = id.MessageIdentifier;
            sendingScope.Commit();
        }
Exemplo n.º 11
0
 public void EnqueueDirectlyTo(string subqueue, MessagePayload payload)
 {
     queueManager.EnqueueDirectlyTo(queueName, subqueue, payload);
 }
Exemplo n.º 12
0
        public void EnqueueDirectlyTo(ITransaction transaction, string queue, string subqueue, MessagePayload payload, MessageId id = null)
        {
            var message = new PersistentMessage
            {
                Data    = payload.Data,
                Headers = payload.Headers,
                Id      = id ?? new MessageId
                {
                    SourceInstanceId  = _queueStorage.Id,
                    MessageIdentifier = GuidCombGenerator.Generate()
                },
                Queue    = queue,
                SentAt   = DateTime.Now,
                SubQueue = subqueue,
                Status   = MessageStatus.EnqueueWait
            };

            _queueStorage.Global(actions =>
            {
                var queueActions = actions.GetQueue(queue);

                var bookmark = queueActions.Enqueue(message);
                actions.RegisterUpdateToReverse(transaction.Id, bookmark, MessageStatus.EnqueueWait, subqueue);
            });

            _logger.QueuedForReceive(message);

            lock (_newMessageArrivedLock)
            {
                Monitor.PulseAll(_newMessageArrivedLock);
            }
        }
Exemplo n.º 13
0
        public void EnqueueDirectlyTo(string queue, string subqueue, MessagePayload payload, MessageId id = null)
        {
            EnsureEnlistment();

            EnqueueDirectlyTo(_enlistment, queue, subqueue, payload);
        }
Exemplo n.º 14
0
        public MessageId Send(ITransaction transaction, Uri uri, MessagePayload payload)
        {
            if (_waitingForAllMessagesToBeSent)
                throw new CannotSendWhileWaitingForAllMessagesToBeSentException("Currently waiting for all messages to be sent, so we cannot send. You probably have a race condition in your application.");

            var parts = uri.AbsolutePath.Substring(1).Split('/');
            var queue = parts[0];
            string subqueue = null;
            if (parts.Length > 1)
            {
                subqueue = string.Join("/", parts.Skip(1).ToArray());
            }

            Guid msgId = Guid.Empty;

            var port = uri.Port;
            if (port == -1)
                port = 2200;
            var destination = new Endpoint(uri.Host, port);

            _queueStorage.Global(actions =>
            {
                msgId = actions.RegisterToSend(destination, queue,
                                               subqueue, payload, transaction.Id);

            });

            var messageId = new MessageId
            {
                SourceInstanceId = _queueStorage.Id,
                MessageIdentifier = msgId
            };
            var message = new Message
            {
                Id = messageId,
                Data = payload.Data,
                Headers = payload.Headers,
                Queue = queue,
                SubQueue = subqueue
            };

            _logger.QueuedForSend(message, destination);

            return messageId;
        }
Exemplo n.º 15
0
        public void EnqueueDirectlyTo(ITransaction transaction, string queue, string subqueue, MessagePayload payload, MessageId id = null)
        {
            var message = new PersistentMessage
            {
                Data = payload.Data,
                Headers = payload.Headers,
                Id = id ?? new MessageId
                {
                    SourceInstanceId = _queueStorage.Id,
                    MessageIdentifier = GuidCombGenerator.Generate()
                },
                Queue = queue,
                SentAt = DateTime.Now,
                SubQueue = subqueue,
                Status = MessageStatus.EnqueueWait
            };

            _queueStorage.Global(actions =>
            {
                var queueActions = actions.GetQueue(queue);

                var bookmark = queueActions.Enqueue(message);
                actions.RegisterUpdateToReverse(transaction.Id, bookmark, MessageStatus.EnqueueWait, subqueue);

            });

            _logger.QueuedForReceive(message);

            lock (_newMessageArrivedLock)
            {
                Monitor.PulseAll(_newMessageArrivedLock);
            }
        }
Exemplo n.º 16
0
        public void EnqueueDirectlyTo(string queue, string subqueue, MessagePayload payload, MessageId id = null)
        {
            EnsureEnlistment();

            EnqueueDirectlyTo(_enlistment, queue, subqueue, payload);
        }
Exemplo n.º 17
0
        public MessageId Send(Uri uri, MessagePayload payload)
        {
            if (_waitingForAllMessagesToBeSent)
                throw new CannotSendWhileWaitingForAllMessagesToBeSentException("Currently waiting for all messages to be sent, so we cannot send. You probably have a race condition in your application.");

            EnsureEnlistment();

            return Send(_enlistment, uri, payload);
        }
Exemplo n.º 18
0
 public static MessageId Send(this ITransactionalScope scope, Uri uri, MessagePayload payload)
 {
     return scope.QueueManager.Send(scope.Transaction, uri, payload);
 }
Exemplo n.º 19
0
 public void EnqueueDirectlyTo(string subqueue, MessagePayload payload)
 {
     queueManager.EnqueueDirectlyTo(queueName, subqueue, payload);
 }
Exemplo n.º 20
0
        public static MessagePayload ToPayload(this Message message)
        {
            var payload = new MessagePayload
            {
                Data = message.Data,
                Headers = message.Headers,
            };

            return payload;
        }
Exemplo n.º 21
0
 public static void EnqueueDirectlyTo(this ITransactionalScope scope, string queue, MessagePayload payload, MessageId id = null)
 {
     scope.QueueManager.EnqueueDirectlyTo(scope.Transaction, queue, null, payload, id);
 }
Exemplo n.º 22
0
 public static MessageId Send(this ITransactionalScope scope, Uri uri, MessagePayload payload)
 {
     return(scope.QueueManager.Send(scope.Transaction, uri, payload));
 }
Exemplo n.º 23
0
 public static void EnqueueDirectlyTo(this ITransactionalScope scope, string queue, MessagePayload payload, MessageId id = null)
 {
     scope.QueueManager.EnqueueDirectlyTo(scope.Transaction, queue, null, payload, id);
 }