Esempio n. 1
0
 public bool Equals(MessageId other)
 {
     if (object.ReferenceEquals(null, other)) return false;
     return (object.ReferenceEquals(this, other) || (other.SourceInstanceId.Equals(SourceInstanceId) && other.MessageIdentifier.Equals(MessageIdentifier)));
 }
Esempio n. 2
0
 public void MarkReceived(MessageId id)
 {
     if (!Directory.Exists(_receivedPath))
         Directory.CreateDirectory(_receivedPath);
     var path = Path.Combine(_receivedPath, FileUtil.FromMessageId(id, null));
     File.WriteAllText(path, ".");
 }
Esempio n. 3
0
 public Message PeekById(MessageId id)
 {
     return _queueManager.PeekById(_queueName, id);
 }
Esempio n. 4
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();
     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());
     var msgId = Guid.Empty;
     var destination = uri.Host;
     _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;
 }
Esempio n. 5
0
 public PersistentMessage PeekById(string queueName, MessageId id)
 {
     PersistentMessage message = null;
     _queueStorage.Global(actions =>
     {
         var queue = actions.GetQueue(queueName);
         message = queue.PeekById(id);
         actions.Commit();
     });
     return message;
 }
Esempio n. 6
0
        public PersistentMessage PeekById(MessageId id)
        {
            var path = _msgsPath;
            if (!Directory.Exists(path))
                return null;
            var msgsPathLength = _msgsPath.Length;
            return Directory.EnumerateFiles(path, FileUtil.SearchMessageId(id, MessageStatus.ReadyToDeliver.ToString()), SearchOption.AllDirectories)
                .OrderBy(x => x)
                .Select(x =>
                {
                    var subQueue = Path.GetDirectoryName(x).Substring(msgsPathLength);
                    var status = FileUtil.ParseExtension<MessageStatus>(x);
                    if (status != MessageStatus.ReadyToDeliver)
                        return null;

                    var obj = JsonConvert.DeserializeObject<QueueMsg>(File.ReadAllText(x));
                    var bookmark = new MessageBookmark { Bookmark = x, QueueName = _queueName };
                    return new PersistentMessage
                    {
                        Bookmark = bookmark,
                        Headers = HttpUtility.ParseQueryString(obj.headers),
                        Queue = _queueName,
                        SentAt = File.GetCreationTime(x),
                        Data = obj.data,
                        Id = id,
                        SubQueue = (string.IsNullOrEmpty(subQueue) ? null : subQueue),
                        Status = status,
                    };
                })
                .FirstOrDefault();
        }