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 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);

                actions.Commit();
            });

            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
            };

            OnMessageQueuedForSend(new MessageEventArgs(destination, message));

            return(messageId);
        }
Exemple #3
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.");
            }

            EnsureEnslistment();

            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;

            queueStorage.Global(actions =>
            {
                var port = uri.Port;
                if (port == -1)
                {
                    port = 2200;
                }
                msgId = actions.RegisterToSend(new Endpoint(uri.Host, port), queue,
                                               subqueue, payload, Enlistment.Id);

                actions.Commit();
            });
            return(new MessageId
            {
                SourceInstanceId = queueStorage.Id,
                MessageIdentifier = msgId
            });
        }
        public void EnqueueDirectlyTo(string queue, string subqueue, MessagePayload payload)
        {
            EnsureEnlistment();

            var message = new PersistentMessage
            {
                Data    = payload.Data,
                Headers = payload.Headers,
                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(Enlistment.Id, bookmark, MessageStatus.EnqueueWait, subqueue);

                actions.Commit();
            });

            OnMessageQueuedForReceive(message);

            lock (newMessageArrivedLock)
            {
                Monitor.PulseAll(newMessageArrivedLock);
            }
        }
        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.");

            EnsureEnslistment();
            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, Enlistment.Id);

                actions.Commit();
            });

            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
            };

            OnMessageQueuedForSend(new MessageEventArgs(destination, message));

            return messageId;
        }
        public void EnqueueDirectlyTo(string queue, string subqueue, MessagePayload payload)
        {
            EnsureEnslistment();

            var message = new PersistentMessage
            {
                Data = payload.Data,
                Headers = payload.Headers,
                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(Enlistment.Id, bookmark, MessageStatus.EnqueueWait, subqueue);

                actions.Commit();
            });

            OnMessageQueuedForReceive(message);

            lock (newMessageArrivedLock)
            {
                Monitor.PulseAll(newMessageArrivedLock);
            }
        }
        private void SendInternal(object[] msgs, Endpoint destination, Action<NameValueCollection> customizeHeaders)
        {
            var messageId = Guid.NewGuid();
            using (var memoryStream = new MemoryStream())
            {
                messageSerializer.Serialize(msgs, memoryStream);

                var payload = new MessagePayload
                {
                    Data = memoryStream.ToArray(),
                    Headers =
                        {
                            {"id", messageId.ToString()},
                            {"type", GetAppSpecificMarker(msgs).ToString()},
                            {"source", Endpoint.Uri.ToString()},
                        }
                };
                logger.DebugFormat("Sending a message with id '{0}' to '{1}'", messageId, destination.Uri);
                customizeHeaders(payload.Headers);
                var transactionOptions = GetTransactionOptions();
                using (var tx = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
                {
                    queueManager.Send(destination.Uri, payload);
                    tx.Complete();
                }
            }

            var copy = MessageSent;
            if (copy == null)
                return;

            copy(new RhinoQueueCurrentMessageInformation
            {
                AllMessages = msgs,
                Source = Endpoint.Uri,
                Destination = destination.Uri,
                MessageId = messageId,
            });
        }
Exemple #8
0
 public void EnqueueDirectlyTo(string subqueue, MessagePayload payload)
 {
     queueManager.EnqueueDirectlyTo(queueName, subqueue, payload);
 }
Exemple #9
0
 public void EnqueueDirectlyTo(string subqueue, MessagePayload payload)
 {
     queueManager.EnqueueDirectlyTo(queueName, subqueue, payload);
 }
        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);
        }
Exemple #11
0
 public MessageId Send(Uri uri, MessagePayload payload)
 {
     return(queueManager.Send(transaction, uri, payload));
 }
 public MessageId Send(Uri uri, MessagePayload payload)
 {
     return queueManager.Send(transaction, uri, payload);
 }