public void CanCreateNewQueueFactory() { using (var qf = new QueueStorage("test.esent")) { qf.Initialize(); } }
public QueueTransaction(QueueStorage queueStorage, Action onComplete, Action assertNotDisposed) { this.queueStorage = queueStorage; this.assertNotDisposed = assertNotDisposed; this.onComplete = onComplete; Id = Guid.NewGuid(); }
public void MovesMessageToOutgoingHistoryAfterMaxAttempts() { Directory.Delete("test.esent", true); using (var qf = new QueueStorage("test.esent", new QueueManagerConfiguration())) { qf.Initialize(); qf.Global(actions => { actions.CreateQueueIfDoesNotExists("test"); actions.Commit(); }); var testMessage = new MessagePayload { Data = new byte[0], DeliverBy = null, Headers = new NameValueCollection(), MaxAttempts = 1 }; Guid messageId = Guid.Empty; qf.Global(actions => { Guid transactionId = Guid.NewGuid(); messageId = actions.RegisterToSend(new Endpoint("localhost", 0), "test", null, testMessage, transactionId); actions.MarkAsReadyToSend(transactionId); actions.Commit(); }); qf.Send(actions => { Endpoint endpoint; var msgs = actions.GetMessagesToSendAndMarkThemAsInFlight(int.MaxValue, int.MaxValue, out endpoint); actions.MarkOutgoingMessageAsFailedTransmission(msgs.First().Bookmark, false); msgs = actions.GetMessagesToSendAndMarkThemAsInFlight(int.MaxValue, int.MaxValue, out endpoint); Assert.Empty(msgs); actions.Commit(); }); qf.Global(actions => { PersistentMessageToSend message = actions.GetSentMessages().FirstOrDefault(x => x.Id.MessageIdentifier == messageId); Assert.NotNull(message); Assert.Equal(OutgoingMessageStatus.Failed, message.OutgoingStatus); actions.Commit(); }); } }
public void MovesMessageToOutgoingFromHistory() { using (var qf = new QueueStorage("test.esent")) { qf.Initialize(); qf.Global(actions => { actions.CreateQueueIfDoesNotExists("test"); actions.Commit(); }); var testMessage = new MessagePayload { Data = new byte[0], Headers = new NameValueCollection(), }; qf.Global(actions => { Guid transactionId = Guid.NewGuid(); actions.RegisterToSend(new Endpoint("localhost", 0), "test", null, testMessage, transactionId); actions.MarkAsReadyToSend(transactionId); actions.Commit(); }); qf.Send(actions => { Endpoint endpoint; var msgs = actions.GetMessagesToSendAndMarkThemAsInFlight(int.MaxValue, int.MaxValue, out endpoint); var bookmark = actions.MarkOutgoingMessageAsSuccessfullySent(msgs[0].Bookmark); actions.RevertBackToSend(new[] { bookmark }); msgs = actions.GetMessagesToSendAndMarkThemAsInFlight(int.MaxValue, int.MaxValue, out endpoint); Assert.NotEmpty(msgs); actions.Commit(); }); qf.Global(actions => { var messages = actions.GetSentMessages(); Assert.Empty(messages); actions.Commit(); }); } }
public TransactionEnlistment(QueueStorage queueStorage, Action onComplete, Action assertNotDisposed) : base(queueStorage, assertNotDisposed, onComplete) { this.queueStorage = queueStorage; this.assertNotDisposed = assertNotDisposed; var transaction = Transaction.Current; if (transaction != null)// should happen only during recovery { transaction.EnlistDurable(queueStorage.Id, this, EnlistmentOptions.None); } logger.DebugFormat("Enlisting in the current transaction with enlistment id: {0}", Id); }
public QueueManager(IPEndPoint endpoint, string path, QueueManagerConfiguration configuration) { Configuration = configuration; this.endpoint = endpoint; this.path = path; queueStorage = new QueueStorage(path, configuration); queueStorage.Initialize(); queueStorage.Global(actions => { receivedMsgs.Add(actions.GetAlreadyReceivedMessageIds()); actions.Commit(); }); HandleRecovery(); }
public void CanDeleteOldEntries() { using (var qf = new QueueStorage("test.esent")) { qf.Initialize(); var random = MessageId.GenerateRandom(); qf.Global(actions => { for (int i = 0; i < 5; i++) { actions.MarkReceived(MessageId.GenerateRandom()); } actions.MarkReceived(random); for (int i = 0; i < 5; i++) { actions.MarkReceived(MessageId.GenerateRandom()); } actions.Commit(); }); qf.Global(actions => { actions.DeleteOldestReceivedMessages(6).ToArray();//consume & activate actions.Commit(); }); qf.Global(actions => { var array = actions.GetAlreadyReceivedMessageIds().ToArray(); Assert.Equal(6, array.Length); Assert.Equal(random, array[0]); actions.Commit(); }); } }
public QueueManager(IPEndPoint endpoint, string path) { NumberOfMessagesToKeepInProcessedQueues = 100; NumberOfMessagesToKeepOutgoingQueues = 100; NumberOfReceivedMessagesToKeep = 100000; OldestMessageInProcessedQueues = TimeSpan.FromDays(3); OldestMessageInOutgoingQueues = TimeSpan.FromDays(3); this.endpoint = endpoint; this.path = path; queueStorage = new QueueStorage(path); queueStorage.Initialize(); queueStorage.Global(actions => { receivedMsgs.Add(actions.GetAlreadyReceivedMessageIds()); actions.Commit(); }); HandleRecovery(); }
public QueueManager(IPEndPoint endpoint, string path) { NumberOfMessagesToKeepInProcessedQueues = 100; NumberOfMessagesToKeepOutgoingQueues = 100; NumberOfReceivedMessagesToKeep = 100000; OldestMessageInProcessedQueues = TimeSpan.FromDays(3); OldestMessageInOutgoingQueues = TimeSpan.FromDays(3); this.endpoint = endpoint; this.path = path; queueStorage = new QueueStorage(path); queueStorage.Initialize(); queueStorage.Global(actions => { receivedMsgs.Add(actions.GetAlreadyReceivedMessageIds()); actions.Commit(); }); receiver = new Receiver(endpoint, AcceptMessages); receiver.Start(); HandleRecovery(); queuedMessagesSender = new QueuedMessagesSender(queueStorage, this); sendingThread = new Thread(queuedMessagesSender.Send) { IsBackground = true, Name = "Rhino Queue Sender Thread for " + path }; sendingThread.Start(); purgeOldDataTimer = new Timer(PurgeOldData, null, TimeSpan.FromMinutes(3), TimeSpan.FromMinutes(3)); }
public MessageAcceptance(QueueManager parent, IList<MessageBookmark> bookmarks, IEnumerable<Message> messages, QueueStorage queueStorage) { this.parent = parent; this.bookmarks = bookmarks; this.messages = messages; this.queueStorage = queueStorage; #pragma warning disable 420 Interlocked.Increment(ref parent.currentlyInCriticalReceiveStatus); #pragma warning restore 420 }
public QueuedMessagesSender(QueueStorage queueStorage, IQueueManager queueManager) { this.queueStorage = queueStorage; this.queueManager = queueManager; }
public void WillNotGiveMessageToTwoClient() { using (var qf = new QueueStorage("test.esent")) { qf.Initialize(); qf.Global(actions => { actions.CreateQueueIfDoesNotExists("h"); actions.Commit(); }); qf.Global(actions => { var queue = actions.GetQueue("h"); var bookmark = queue.Enqueue(new Message { Queue = "h", Id = MessageId.GenerateRandom(), Data = new byte[] { 1 }, }); queue.SetMessageStatus(bookmark, MessageStatus.ReadyToDeliver); bookmark = queue.Enqueue(new Message { Queue = "h", Id = MessageId.GenerateRandom(), Data = new byte[] { 2 }, }); queue.SetMessageStatus(bookmark, MessageStatus.ReadyToDeliver); actions.Commit(); }); qf.Global(actions => { var m1 = actions.GetQueue("h").Dequeue(null); qf.Global(queuesActions => { var m2 = queuesActions.GetQueue("h").Dequeue(null); Assert.Equal(new byte[] { 2 }, m2.Data); queuesActions.Commit(); }); Assert.Equal(new byte[] { 1 }, m1.Data); actions.Commit(); }); } }
public void WillGiveNullWhenNoItemsAreInQueue() { using (var qf = new QueueStorage("test.esent")) { qf.Initialize(); qf.Global(actions => { actions.CreateQueueIfDoesNotExists("h"); actions.Commit(); }); qf.Global(actions => { var message = actions.GetQueue("h").Dequeue(null); Assert.Null(message); actions.Commit(); }); } }
public void CanRegisterReceivedMessageIds() { using (var qf = new QueueStorage("test.esent")) { qf.Initialize(); var random = MessageId.GenerateRandom(); qf.Global(actions => { actions.MarkReceived(random); actions.Commit(); }); qf.Global(actions => { Assert.True(actions.GetAlreadyReceivedMessageIds().Contains(random)); actions.Commit(); }); } }
public void CanPutSingleMessageInQueue() { using (var qf = new QueueStorage("test.esent")) { qf.Initialize(); qf.Global(actions => { actions.CreateQueueIfDoesNotExists("h"); actions.Commit(); }); MessageBookmark bookmark = null; var guid = Guid.NewGuid(); var identifier = Guid.NewGuid(); qf.Global(actions => { bookmark = actions.GetQueue("h").Enqueue(new Message { Queue = "h", Data = new byte[] { 13, 12, 43, 5 }, SentAt = new DateTime(2004, 5, 5), Id = new MessageId { SourceInstanceId = guid, MessageIdentifier = identifier } }); actions.Commit(); }); qf.Global(actions => { actions.GetQueue("h").SetMessageStatus(bookmark, MessageStatus.ReadyToDeliver); actions.Commit(); }); qf.Global(actions => { var message = actions.GetQueue("h").Dequeue(null); Assert.Equal(new byte[] { 13, 12, 43, 5 }, message.Data); Assert.Equal(identifier, message.Id.MessageIdentifier); Assert.Equal(guid, message.Id.SourceInstanceId); Assert.Equal("h", message.Queue); Assert.Equal(new DateTime(2004, 5, 5), message.SentAt); actions.Commit(); }); } }