public QueueManager(string connectionStringName) { queueStorage = new QueueStorage(connectionStringName); queueStorage.Initialize(); purgeOldDataTimer = new Timer(PurgeOldData, null, TimeSpan.FromMinutes(3), TimeSpan.FromMinutes(3)); }
protected QueueTest(string connectionStringName) { var connectionStringBuilder = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString); var databaseName = connectionStringBuilder.InitialCatalog; connectionStringBuilder.InitialCatalog = "master"; using (var connection = new SqlConnection(connectionStringBuilder.ConnectionString)) { connection.Open(); using (var createCommand = new SqlCommand( @" IF ((SELECT DB_ID ('<databasename, sysname, queuedb>')) IS NULL) BEGIN CREATE DATABASE [<databasename, sysname, queuedb>] END" .Replace("<databasename, sysname, queuedb>", databaseName), connection)) { createCommand.CommandType = CommandType.Text; createCommand.ExecuteNonQuery(); } } try { var storage = new QueueStorage(connectionStringName); storage.Initialize(); } catch (SqlException) { new SchemaCreator().Create(connectionStringName, 2204); } StorageUtil.PurgeAll(connectionStringName); }
public WindowsAzureStorageHelper() { ContainerName = CONTAINER_NAME; // Open blob storage. StorageAccountInfo = StorageAccountInfo.GetDefaultBlobStorageAccountFromConfiguration(); BlobStorageType = BlobStorage.Create(StorageAccountInfo); BlobStorageType.RetryPolicy = RetryPolicies.RetryN(2, TimeSpan.FromMilliseconds(100)); // Open queue storage. StorageAccountInfo queueAccount = StorageAccountInfo.GetDefaultQueueStorageAccountFromConfiguration(); QueueStorageType = QueueStorage.Create(queueAccount); QueueStorageType = QueueStorage.Create(queueAccount); QueueStorageType.RetryPolicy = RetryPolicies.RetryN(2, TimeSpan.FromMilliseconds(100)); // Open table storage. StorageAccountInfo tableAccount = StorageAccountInfo.GetDefaultTableStorageAccountFromConfiguration(); TableStorageType = TableStorage.Create(tableAccount); TableStorageType = TableStorage.Create(tableAccount); TableStorageType.RetryPolicy = RetryPolicies.RetryN(2, TimeSpan.FromMilliseconds(100)); }
public WindowsAzureStorageHelper(string accountName, string accountKey, bool isLocal, string blobEndpointURI, string queueEndpointURI, string tableEndpointURI) { ContainerName = CONTAINER_NAME; StorageAccountInfo = new StorageAccountInfo(new Uri(blobEndpointURI), isLocal, accountName, accountKey); BlobStorageType = BlobStorage.Create(StorageAccountInfo); BlobStorageType.RetryPolicy = RetryPolicies.RetryN(2, TimeSpan.FromMilliseconds(100)); Container = BlobStorageType.GetBlobContainer(ContainerName); //Create the container if it does not exist. Container.CreateContainer(ContainerMetaData, ContainerAccessControl.Private); // Open queue storage. //StorageAccountInfo qaccount = StorageAccountInfo.GetDefaultQueueStorageAccountFromConfiguration(); StorageAccountInfo qaccount = new StorageAccountInfo(new Uri(queueEndpointURI), isLocal, accountName, accountKey); QueueStorageType = QueueStorage.Create(qaccount); QueueStorageType = QueueStorage.Create(qaccount); QueueStorageType.RetryPolicy = RetryPolicies.RetryN(2, TimeSpan.FromMilliseconds(100)); // Open table storage. //StorageAccountInfo taccount = StorageAccountInfo.GetDefaultTableStorageAccountFromConfiguration(); StorageAccountInfo taccount = new StorageAccountInfo(new Uri(tableEndpointURI), isLocal, accountName, accountKey); TableStorageType = TableStorage.Create(taccount); TableStorageType = TableStorage.Create(taccount); TableStorageType.RetryPolicy = RetryPolicies.RetryN(2, TimeSpan.FromMilliseconds(100)); }
public void WillGetMessagesBackInOrder() { 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); bookmark = queue.Enqueue(new Message { Queue = "h", Id = MessageId.GenerateRandom(), Data = new byte[] { 3 }, }); queue.SetMessageStatus(bookmark, MessageStatus.ReadyToDeliver); actions.Commit(); }); qf.Global(actions => { var m1 = actions.GetQueue("h").Dequeue(null); var m2 = actions.GetQueue("h").Dequeue(null); var m3 = actions.GetQueue("h").Dequeue(null); Assert.Equal(new byte[] { 1 }, m1.Data); Assert.Equal(new byte[] { 2 }, m2.Data); Assert.Equal(new byte[] { 3 }, m3.Data); actions.Commit(); }); } }
public void CanCreateNewQueueFactory() { using (var qf = new QueueStorage("test.esent")) { qf.Initialize(); } }
public void PersistRestoreOverflowing() { const string storeName = "TestStore"; // CAUTION: we are now compressing serialization output. // hence, we can't just pass an empty array, as it would be compressed at near 100%. var data = new byte[80000]; _rand.NextBytes(data); // clean up QueueStorage.DeleteQueue(QueueName); foreach (var skey in QueueStorage.ListPersisted(storeName)) { QueueStorage.DeletePersisted(storeName, skey); } // put QueueStorage.Put(QueueName, data); Assert.AreEqual( 1, BlobStorage.ListBlobNames(QueueStorageProvider.OverflowingMessagesContainerName, QueueName).Count(), "#A01"); // get var retrieved = QueueStorage.Get <byte[]>(QueueName, 1).First(); // persist QueueStorage.Persist(retrieved, storeName, "manual test"); Assert.AreEqual( 1, BlobStorage.ListBlobNames(QueueStorageProvider.OverflowingMessagesContainerName, QueueName).Count(), "#A02"); // abandon should fail (since not invisible anymore) Assert.IsFalse(QueueStorage.Abandon(retrieved), "#A03"); // list persisted message var key = QueueStorage.ListPersisted(storeName).Single(); // get persisted message var persisted = QueueStorage.GetPersisted(storeName, key); Assert.IsTrue(persisted.HasValue, "#A04"); Assert.IsTrue(persisted.Value.DataXml.HasValue, "#A05"); // delete persisted message QueueStorage.DeletePersisted(storeName, key); Assert.AreEqual( 0, BlobStorage.ListBlobNames(QueueStorageProvider.OverflowingMessagesContainerName, QueueName).Count(), "#A06"); // list no longer contains key Assert.IsFalse(QueueStorage.ListPersisted(storeName).Any(), "#A07"); }
public void SetUp() { _eventStorage = GetEventStorage(); _queueStorage = GetQueueStorage(); SetUpPerTest(_queueStorage, _eventStorage); }
public AzureQueueStorageSink(SubscriptionMetadata metadata, ILog logger = null) : base(metadata, logger) { loadQueue = new ConcurrentQueue <EventMessage>(); auditor = AuditFactory.CreateSingleton().GetAuditor(AuditType.Message); uri = new Uri(metadata.NotifyAddress); NameValueCollection nvc = HttpUtility.ParseQueryString(uri.Query); queue = nvc["queue"]; string ttlString = nvc["ttl"]; if (!string.IsNullOrEmpty(ttlString)) { ttl = TimeSpan.Parse(ttlString); } Uri.TryCreate(metadata.SymmetricKey, UriKind.Absolute, out Uri sasUri); if (sasUri == null) { storage = QueueStorage.New( $"DefaultEndpointsProtocol=https;AccountName={uri.Authority.Split(new[] { '.' })[0]};AccountKey={metadata.SymmetricKey};", 10000, 1000); } else { string connectionString = $"BlobEndpoint={queue};SharedAccessSignature={metadata.SymmetricKey}"; storage = QueueStorage.New(connectionString, 1000, 5120000); } }
public void PutGetDeleteOverflowing() { // 20k chosen so that it doesn't fit into the queue. var message = new MyMessage { MyBuffer = new byte[80000] }; // fill buffer with random content _rand.NextBytes(message.MyBuffer); QueueStorage.Clear(QueueName); QueueStorage.Put(QueueName, message); var retrieved = QueueStorage.Get <MyMessage>(QueueName, 1).First(); Assert.AreEqual(message.MyGuid, retrieved.MyGuid, "#A01"); CollectionAssert.AreEquivalent(message.MyBuffer, retrieved.MyBuffer, "#A02"); for (int i = 0; i < message.MyBuffer.Length; i++) { Assert.AreEqual(message.MyBuffer[i], retrieved.MyBuffer[i], "#A02-" + i); } QueueStorage.Delete(retrieved); }
public void ClearRemovesOverflowingBlobs() { var queueName = "test1-" + Guid.NewGuid().ToString("N"); // CAUTION: we are now compressing serialization output. // hence, we can't just pass an empty array, as it would be compressed at near 100%. var data = new byte[80000]; _rand.NextBytes(data); QueueStorage.Put(queueName, data); // HACK: implicit pattern for listing overflowing messages var overflowingCount = BlobStorage.ListBlobNames(QueueStorageProvider.OverflowingMessagesContainerName, queueName).Count(); Assert.AreEqual(1, overflowingCount, "#A00"); QueueStorage.Clear(queueName); overflowingCount = BlobStorage.ListBlobNames(QueueStorageProvider.OverflowingMessagesContainerName, queueName).Count(); Assert.AreEqual(0, overflowingCount, "#A01"); QueueStorage.DeleteQueue(queueName); }
public QueueTransaction(QueueStorage queueStorage, Action onComplete, Action assertNotDisposed) { this.queueStorage = queueStorage; this.assertNotDisposed = assertNotDisposed; this.onComplete = onComplete; Id = Guid.NewGuid(); }
protected override void SetUpPerTest(QueueStorage storage, EventStorage eventStorage) { using (var sqlConnection = new SqlConnection(ConnectionString)) { sqlConnection.Open(); using (var cmd = new SqlCommand("truncate table Events;", sqlConnection)) { cmd.ExecuteNonQuery(); } using (var cmd = new SqlCommand("truncate table Streams;", sqlConnection)) { cmd.ExecuteNonQuery(); } using (var cmd = new SqlCommand("truncate table QueueAllocations;", sqlConnection)) { cmd.ExecuteNonQuery(); } using (var cmd = new SqlCommand("truncate table Queues;", sqlConnection)) { cmd.ExecuteNonQuery(); } } }
public QueueTransaction(ILogger logger, QueueStorage queueStorage, Action onComplete, Action assertNotDisposed) { _logger = logger; _queueStorage = queueStorage; _assertNotDisposed = assertNotDisposed; _onComplete = onComplete; Id = Guid.NewGuid(); }
public void ListInMonoThread() { var fakeMessages = Enumerable.Range(0, 10).Select(i => new FakeMessage(i)).ToArray(); QueueStorage.PutRange(FirstQueueName, fakeMessages.Take(6)); var queuesName = QueueStorage.List(""); Assert.AreEqual(1, queuesName.Count(), "#A010"); }
public void Enqueue(ICommand itemToQueue) { if (itemToQueue == null) { throw new ArgumentNullException("itemToQueue"); } QueueStorage.AddToQueue((dynamic)itemToQueue); }
public MessageAcceptance(QueueManager parent, IList <MessageBookmark> bookmarks, IEnumerable <Message> messages, QueueStorage queueStorage) { _parent = parent; _bookmarks = bookmarks; _messages = messages; _queueStorage = queueStorage; Interlocked.Increment(ref parent._currentlyInCriticalReceiveStatus); }
public CanUseQueue() : base("testqueue") { qf = new QueueStorage("testqueue"); qf.Initialize(); qf.Global(actions => { actions.BeginTransaction(); actions.CreateQueue(queueUri); actions.Commit(); }); }
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 QueueLatency() { Assert.IsFalse(QueueStorage.GetApproximateLatency(QueueName).HasValue); QueueStorage.Put(QueueName, 100); var latency = QueueStorage.GetApproximateLatency(QueueName); Assert.IsTrue(latency.HasValue); Assert.IsTrue(latency.Value >= TimeSpan.Zero && latency.Value < TimeSpan.FromMinutes(10)); QueueStorage.Delete(100); }
public MessageAcceptance(QueueManager parent, IList <MessageBookmark> bookmarks, IEnumerable <MessageId> messageIds, QueueStorage queueStorage) { this.parent = parent; this.bookmarks = bookmarks; this.messageIds = messageIds; this.queueStorage = queueStorage; #pragma warning disable 420 Interlocked.Increment(ref parent.currentlyInCriticalReceiveStatus); #pragma warning restore 420 }
public void MovesMessageToOutgoingFromHistory() { 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], 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) { _queueStorage = queueStorage; _assertNotDisposed = assertNotDisposed; var transaction = Transaction.Current; if (transaction != null)// should happen only during recovery { transaction.EnlistDurable(queueStorage.Id, this, EnlistmentOptions.None); } _logger.Debug("Enlisting in the current transaction with enlistment id: {0}", Id); }
public static void Dequeue() { var path = System.Web.Hosting.HostingEnvironment.MapPath("~/app_data/queues/"); using (var queue = new QueueStorage(path)) { if (queue.Count<Message>() > 0) { var message = queue.Dequeue<Message>(); var smtpConfig = SmtpConfig.Read(); var smtpClient = new SmtpClient(smtpConfig.Host, smtpConfig.Port); var mailMsg = GetMailMessage(message, smtpConfig); smtpClient.Send(mailMsg); } } }
static void Main(string[] args) { //int j; ////int[] array = new int[10]; //for ( int i=0;i<=10;++i) //{ // j= ++i; // Console.WriteLine(i); // Console.WriteLine(j); // Console.WriteLine("=================="); // j = i++; // Console.WriteLine(i); // Console.WriteLine(j); //} //Console.ReadLine(); string Clientid = "42c76f2f-fd88-4d6f-a385-06273df9192a"; string ApplicationSecret = "zY5JuVvolq1Z/h3H9UBCPrTNxKsjRsWVBQctDUt33mw="; //string ScretIdenfier = @"https://mycdp-keyvalt.vault.azure.net/secrets/my-storage/fc22e81e4d854388a30193c064578f43"; //KeyVault keyVault =new KeyVault(Clientid, ApplicationSecret, ScretIdenfier); //var value= keyVault.GetKeyValue().Result; // Console.WriteLine($"value=> {value} "); Console.WriteLine("started......."); while (true) { QueueStorage queueStorage = new QueueStorage(); TableStorage tableStorage = new TableStorage(); FileModel fileModel = queueStorage.ReadFromQueue(); if (fileModel != null) { Console.WriteLine("Sucessfully read the data from Queue"); FileModelTable fileModelTable = new FileModelTable() { FileName = fileModel.FileName, FileSize = fileModel.FileSize, ImagePath = fileModel.ImagePath, ProjectId = fileModel.ProjectId, SectionId = fileModel.SectionId, ThumbPath = fileModel.ThumbPath }; tableStorage.SaveTableStorage(fileModelTable); Console.WriteLine("Sucessfully save data to Table"); } Thread.Sleep(5000); } Console.ReadLine(); }
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(); }); } }
public static void Dequeue() { var path = System.Web.Hosting.HostingEnvironment.MapPath("~/app_data/queues/"); using (var queue = new QueueStorage(path)) { if (queue.Count <Message>() > 0) { var message = queue.Dequeue <Message>(); var smtpConfig = SmtpConfig.Read(); var smtpClient = new SmtpClient(smtpConfig.Host, smtpConfig.Port); var mailMsg = GetMailMessage(message, smtpConfig); smtpClient.Send(mailMsg); } } }
public void ItemsGetPutInMonoThread() { var fakeMessages = Enumerable.Range(0, 3).Select(i => new FakeMessage(i)).ToArray(); QueueStorage.PutRange(FirstQueueName, fakeMessages.Take(2)); QueueStorage.PutRange(SecondQueueName, fakeMessages.Skip(2).ToArray()); Assert.AreEqual( 2, QueueStorage.GetApproximateCount(FirstQueueName), "#A04 First queue has not the right number of elements."); Assert.AreEqual( 1, QueueStorage.GetApproximateCount(SecondQueueName), "#A05 Second queue has not the right number of elements."); }
public QueueManager(IPEndPoint endpoint, string path, QueueManagerConfiguration configuration, ILogger logger = null) { Configuration = configuration; _endpoint = endpoint; _path = path; _logger = logger ?? LogManager.GetLogger(GetType()); _queueStorage = new QueueStorage(path, configuration); _queueStorage.Initialize(); _queueStorage.Global(actions => { _receivedMsgs.Add(actions.GetAlreadyReceivedMessageIds()); }); HandleRecovery(); }
public TransactionEnlistment(QueueStorage queueStorage, Action onCompelete, Action assertNotDisposed) { this.queueStorage = queueStorage; this.onCompelete = onCompelete; this.assertNotDisposed = assertNotDisposed; var transaction = Transaction.Current; if (transaction != null) // should happen only during recovery { transaction.EnlistDurable(queueStorage.Id, this, EnlistmentOptions.None); } Id = Guid.NewGuid(); logger.DebugFormat("Enlisting in the current transaction with enlistment id: {0}", Id); }
public void MovesMessageToOutgoingHistoryAfterMaxAttempts() { Directory.Delete("test.esent", true); using (var qf = new QueueStorage("test.esent", new QueueManagerConfiguration(), ObjectMother.Logger())) { qf.Initialize(); qf.Global(actions => actions.CreateQueueIfDoesNotExists("test")); 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); }); qf.Send(actions => { var msgs = actions.GetMessagesToSendAndMarkThemAsInFlight(int.MaxValue, int.MaxValue, new Endpoint("localhost", 0)); actions.MarkOutgoingMessageAsFailedTransmission(msgs.First().Bookmark, false); msgs = actions.GetMessagesToSendAndMarkThemAsInFlight(int.MaxValue, int.MaxValue, new Endpoint("localhost", 0)); msgs.ShouldHaveCount(0); }); qf.Global(actions => { PersistentMessageToSend message = actions.GetSentMessages().FirstOrDefault(x => x.Id.MessageIdentifier == messageId); message.ShouldNotBeNull(); OutgoingMessageStatus.Failed.ShouldEqual(message.OutgoingStatus); }); } }
public QueueEndpoint(QueueStorage storage, ResConfiguration config) { var ctx = NetMQContext.Create(); _ctx = ctx; var outBuffer = new OutBuffer(config.QueueEndpoint.BufferSize); var dispatcher = new TcpMessageDispatcher(); dispatcher.Register(ResCommands.SubscribeToQueue, new Queues.SubscribeHandler(storage, outBuffer)); dispatcher.Register(ResCommands.AcknowledgeQueue, new Queues.AcknowledgeHandler(storage, outBuffer)); MessageProcessor messageProcessor = new TcpIncomingMessageProcessor(dispatcher); messageProcessor = new ErrorHandlingMessageProcessor(messageProcessor); //important...the factory method parameter must "create" the gateway, threading issue otherwise. Logger.Debug("[QueueEndpoint] Initialising Transceiver. Endpoint: {0}", config.QueueEndpoint.Endpoint); _transceiver = new Transceiver(() => new TcpGateway(ctx, config.QueueEndpoint.Endpoint, messageProcessor), outBuffer); }
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(); }
protected static Boolean AddMessageToQueue(String message, String queueContainer) { Boolean queueInsertSuccessful = false; try { var queue = QueueStorage.GetQueueReference(queueContainer); var msg = new CloudQueueMessage(message); queue.AddMessage(msg); queueInsertSuccessful = true; } catch (ApplicationException aexc) { System.Diagnostics.Trace.TraceInformation("Didn't add {0} to queue -- {1}", message, aexc.Message); } return(queueInsertSuccessful); }
public void MovesMessageToOutgoingFromHistory() { using (var qf = new QueueStorage("test.esent", new QueueManagerConfiguration())) { qf.Initialize(); qf.Global(actions => actions.CreateQueueIfDoesNotExists("test")); 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); }); qf.Send(actions => { var msgs = actions.GetMessagesToSendAndMarkThemAsInFlight(int.MaxValue, int.MaxValue, new Endpoint("localhost", 0)); var bookmark = actions.MarkOutgoingMessageAsSuccessfullySent(msgs[0].Bookmark); actions.RevertBackToSend(new[] { bookmark }); msgs = actions.GetMessagesToSendAndMarkThemAsInFlight(int.MaxValue, int.MaxValue, new Endpoint("localhost", 0)); msgs.ShouldNotBeNull(); msgs.ShouldHaveCount(1); }); qf.Global(actions => { var messages = actions.GetSentMessages(); messages.ShouldHaveCount(0); }); } }
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 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 void MovesExpiredMessageToOutgoingHistory() { using (var qf = new QueueStorage("test.esent", new QueueManagerConfiguration())) { qf.Initialize(); qf.Global(actions => actions.CreateQueueIfDoesNotExists("test")); var testMessage = new MessagePayload{ Data = new byte[0], DeliverBy = DateTime.Now.AddSeconds(-1), Headers = new NameValueCollection(), MaxAttempts = null }; 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); }); qf.Send(actions => { var msgs = actions.GetMessagesToSendAndMarkThemAsInFlight(int.MaxValue, int.MaxValue, new Endpoint("localhost", 0)); msgs.ShouldHaveCount(0); }); qf.Global(actions => { var message = actions.GetSentMessages().FirstOrDefault(x => x.Id.MessageIdentifier == messageId); message.ShouldNotBeNull(); OutgoingMessageStatus.Failed.ShouldEqual(message.OutgoingStatus); }); } }
public SubscribeHandler(QueueStorage storage, OutBuffer outBuffer) { _storage = storage; _outBuffer = outBuffer; _spin = new SpinWait(); }
public QueuedMessagesSender(QueueStorage queueStorage, SendingChoke choke, ILogger logger) { _queueStorage = queueStorage; _logger = logger; _choke = choke; }
public MessageAcceptance(QueueManager parent, IList<MessageBookmark> bookmarks, IEnumerable<Message> messages, QueueStorage queueStorage) { _parent = parent; _bookmarks = bookmarks; _messages = messages; _queueStorage = queueStorage; Interlocked.Increment(ref parent._currentlyInCriticalReceiveStatus); }
protected virtual void SetUpPerTest(QueueStorage storage, EventStorage eventStorage) { }
public AcknowledgeHandler(QueueStorage storage, OutBuffer outBuffer) { _storage = storage; _outBuffer = outBuffer; _spin = new SpinWait(); }