public void PutMessage(string content, int priority, int characterSet, string correlationId, string groupId, int?lsn) { var ep = BuildExtendedProperties(correlationId, groupId, lsn); var msg = QueueSource.NewMessage(content, priority, characterSet, ep); QueueSource.PutMessages(new[] { msg }, CancellationToken.None); }
public void A_QueueSource_should_fail_when_an_error_occurs() { Queue.DeleteIfExists(); var probe = QueueSource.Create(Queue, pollInterval: TimeSpan.FromSeconds(1)) .Take(3) .Select(x => x.AsString) .RunWith(this.SinkProbe <string>(), Materializer); probe.Request(1).ExpectError(); }
public async Task A_QueueSource_should_fail_when_an_error_occurs() { await Queue.DeleteIfExistsAsync(); var probe = QueueSource.Create(Queue, pollInterval: TimeSpan.FromSeconds(1)) .Take(3) .Select(x => x.MessageText) .RunWith(this.SinkProbe <string>(), Materializer); Output.WriteLine(probe.Request(1).ExpectError().Message); }
public void PutMessages(IEnumerable <string> contents, int priority, int characterSet, string correlationId, string groupId, int?lsn, CancellationToken ct, IProgress <int> progress) { var msgs = contents.Select(s => { var ep = BuildExtendedProperties(correlationId, groupId, lsn); if (lsn.HasValue) { lsn++; } return(QueueSource.NewMessage(s, priority, characterSet, ep)); }).ToList(); QueueSource.PutMessages(msgs, ct, progress); }
public void A_QueueSource_should_push_available_messages() { Queue.AddMessage(new CloudQueueMessage("Test1")); Queue.AddMessage(new CloudQueueMessage("Test2")); Queue.AddMessage(new CloudQueueMessage("Test3")); QueueSource.Create(Queue) .Take(3) .Select(x => x.AsString) .RunWith(this.SinkProbe <string>(), Materializer) .Request(3) .ExpectNext("Test1", "Test2", "Test3") .ExpectComplete(); }
public IEnumerable <MessageInfo> Browse(int numberOfMessages, BrowseFilter filter, CancellationToken ct, IProgress <int> progress, MessageInfo lastMessage, IByteCharConverter converter) { int indexOffset = 0; if (lastMessage != null && lastMessage.Index.HasValue) { indexOffset = lastMessage.Index.Value; } foreach (var msg in QueueSource.BrowseMessages(numberOfMessages, ct, lastMessage?.MessageId, filter, progress)) { var mi = new MessageInfo(msg, converter, indexOffset); yield return(mi); } }
public async Task A_QueueSource_should_push_available_messages() { await Queue.SendMessageAsync("Test1"); await Queue.SendMessageAsync("Test2"); await Queue.SendMessageAsync("Test3"); var probe = QueueSource.Create(Queue) .Take(3) .Select(x => x.MessageText) .RunWith(this.SinkProbe <string>(), Materializer); probe.Request(3) .ExpectNext("Test1", "Test2", "Test3") .ExpectComplete(); }
public void A_QueueSource_should_poll_for_messages_if_the_queue_is_empty() { Queue.AddMessage(new CloudQueueMessage("Test1")); var probe = QueueSource.Create(Queue, pollInterval: TimeSpan.FromSeconds(1)) .Take(3) .Select(x => x.AsString) .RunWith(this.SinkProbe <string>(), Materializer); probe.Request(2) .ExpectNext("Test1") .ExpectNoMsg(TimeSpan.FromSeconds(3)); Queue.AddMessage(new CloudQueueMessage("Test2")); Queue.AddMessage(new CloudQueueMessage("Test3")); probe.ExpectNext("Test2", TimeSpan.FromSeconds(2)); probe.Request(1).ExpectNext("Test3").ExpectComplete(); }
public async Task A_QueueSource_should_poll_for_messages_if_the_queue_is_empty() { await Queue.SendMessageAsync("Test1"); var probe = QueueSource.Create(Queue, pollInterval: TimeSpan.FromSeconds(1)) .Take(3) .Select(x => x.MessageText) .RunWith(this.SinkProbe <string>(), Materializer); probe.Request(2) .ExpectNext("Test1") .ExpectNoMsg(TimeSpan.FromSeconds(3)); await Queue.SendMessageAsync("Test2"); await Queue.SendMessageAsync("Test3"); probe.ExpectNext("Test2", TimeSpan.FromSeconds(2)); probe.Request(1).ExpectNext("Test3").ExpectComplete(); }
public void A_QueueSource_should_not_fail_if_the_supervision_strategy_is_not_stop_when_an_error_occurs() { Queue.DeleteIfExists(); var probe = QueueSource.Create(Queue, pollInterval: TimeSpan.FromSeconds(1)) .Take(3) .Select(x => x.AsString) .WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.ResumingDecider)) .RunWith(this.SinkProbe <string>(), Materializer); probe.Request(3).ExpectNoMsg(); Queue.CreateIfNotExists(); Queue.AddMessage(new CloudQueueMessage("Test1")); Queue.AddMessage(new CloudQueueMessage("Test2")); Queue.AddMessage(new CloudQueueMessage("Test3")); probe.ExpectNext("Test1", "Test2", "Test3") .ExpectComplete(); }
public void A_QueueSource_should_only_poll_if_demand_is_available() { Queue.AddMessage(new CloudQueueMessage("Test1")); var probe = QueueSource.Create(Queue, pollInterval: TimeSpan.FromSeconds(1)) .Select(x => { Queue.DeleteMessage(x); return(x.AsString); }) .RunWith(this.SinkProbe <string>(), Materializer); probe.Request(1).ExpectNext("Test1"); Queue.AddMessage(new CloudQueueMessage("Test2")); probe.ExpectNoMsg(TimeSpan.FromSeconds(3)); //Message wouldn't be visible if the source has called GetMessages even if the message wasn't pushed to the stream Queue.PeekMessage().AsString.Should().Be("Test2"); probe.Request(1).ExpectNext("Test2"); }
public async Task A_QueueSource_should_only_poll_if_demand_is_available() { await Queue.SendMessageAsync("Test1"); var probe = QueueSource.Create(Queue, pollInterval: TimeSpan.FromSeconds(1)) .Select(x => { Queue.DeleteMessage(x.MessageId, x.PopReceipt); return(x.MessageText); }) .RunWith(this.SinkProbe <string>(), Materializer); probe.Request(1).ExpectNext("Test1"); await Queue.SendMessageAsync("Test2"); probe.ExpectNoMsg(TimeSpan.FromSeconds(3)); //Message wouldn't be visible if the source has called GetMessages even if the message wasn't pushed to the stream (await Queue.PeekMessagesAsync(1)).Value[0].MessageText.Should().Be("Test2"); probe.Request(1).ExpectNext("Test2"); }
public async Task A_QueueSource_should_not_fail_if_the_supervision_strategy_is_not_stop_when_an_error_occurs() { await Queue.DeleteIfExistsAsync(); var probe = QueueSource.Create(Queue, pollInterval: TimeSpan.FromSeconds(1)) .Take(3) .Select(x => x.MessageText) .WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.ResumingDecider)) .RunWith(this.SinkProbe <string>(), Materializer); probe.Request(3).ExpectNoMsg(); await Queue.CreateIfNotExistsAsync(); await Queue.SendMessageAsync("Test1", TimeSpan.Zero); await Queue.SendMessageAsync("Test2", TimeSpan.Zero); await Queue.SendMessageAsync("Test3", TimeSpan.Zero); probe.ExpectNext("Test1", "Test2", "Test3") .ExpectComplete(); }
public void StartSyncronizing() { enable = true; Task.Factory.StartNew(() => { IDbManager dbManager = ObjectPool.Instance.Resolve <IDbManager>(); IDataCommand db = dbManager.GetDatabase(DatabaseNames.SMSGW); List <Inbox> newInbox; List <Outbox> newOutbox; List <Trash> newTrash; List <Spam> newSpam; while (enable) { newInbox = db.Query <Inbox>("GetInbox"); newOutbox = db.Query <Outbox>("GetOutbox"); newTrash = db.Query <Trash>("GetTrash"); newSpam = db.Query <Spam>("GetSpam"); // save current view source InboxMaster.Source = newInbox.Convert <Inbox>(); OutboxMaster.Source = newOutbox.Convert <Outbox>(); SpamMaster.Source = newSpam.Convert <Spam>(); TrashMaster.Source = newTrash.Convert <Trash>(); DraftSource.Refresh(); QueueSource.Refresh(); // refresh all view source when search text box is empty if (string.IsNullOrEmpty(searchText)) { IEnumerable <Inbox> inboxAdded; MutableObservableCollection <Inbox> inboxRemoved; IEnumerable <Outbox> outboxAdded; IEnumerable <Outbox> outboxRemoved; IEnumerable <Spam> spamAdded; IEnumerable <Spam> spamRemoved; IEnumerable <Trash> trashAdded; IEnumerable <Trash> trashRemoved; if (firstLoaded) { firstLoaded = false; InboxSource.Source = newInbox.Convert <Inbox>(); OutboxSource.Source = newOutbox.Convert <Outbox>(); SpamSource.Source = newSpam.Convert <Spam>(); TrashSource.Source = newTrash.Convert <Trash>(); } else { if (newInbox.Count > InboxSource.Source.Count) { inboxAdded = newInbox.Except(InboxSource.Source, new InboxComparer()); if (inboxAdded.Any()) { foreach (Inbox message in inboxAdded) { InboxSource.Source.Insert(0, message); } InboxSource.Unread = inboxAdded.Count(); InboxHeader = "inbox"; ApplicationSettings settings = ObjectPool.Instance.Resolve <ApplicationSettings>(); if (settings.General.Sounds) { IAudioService audio = ObjectPool.Instance.Resolve <IAudioService>(); audio.PlayAsync(AudioEnum.ReceiveMessage); } } } else if (newInbox.Count < InboxSource.Source.Count) { inboxRemoved = InboxSource.Source.Except(newInbox, new InboxComparer()).Convert <Inbox>(); foreach (Inbox removed in inboxRemoved.ToList()) { InboxSource.Source.Remove(removed); } } if (newOutbox.Count > OutboxSource.Source.Count) { outboxAdded = newOutbox.Except(OutboxSource.Source, new OutboxComparer()); if (outboxAdded.Any()) { foreach (Outbox message in outboxAdded) { OutboxSource.Source.Insert(0, message); } } OutboxSource.Unread = outboxAdded.Count(); } else if (newOutbox.Count < OutboxSource.Source.Count) { outboxRemoved = OutboxSource.Source.Except(newOutbox, new OutboxComparer()); foreach (Outbox removed in outboxRemoved.ToList()) { OutboxSource.Source.Remove(removed); } } if (newTrash.Count > TrashSource.Source.Count) { trashAdded = newTrash.Except(TrashSource.Source, new TrashComparer()); if (trashAdded.Any()) { foreach (Trash message in trashAdded) { TrashSource.Source.Insert(0, message); } } TrashSource.Unread = trashAdded.Count(); } else if (newTrash.Count < TrashSource.Source.Count) { trashRemoved = TrashSource.Source.Except(newTrash, new TrashComparer()); foreach (Trash removed in trashRemoved.ToList()) { TrashSource.Source.Remove(removed); } } if (newSpam.Count > SpamSource.Source.Count) { spamAdded = newSpam.Except(SpamSource.Source, new SpamComparer()); if (spamAdded.Any()) { foreach (Spam message in spamAdded) { SpamSource.Source.Insert(0, message); } } SpamSource.Unread = spamAdded.Count(); } else if (newSpam.Count < SpamSource.Source.Count) { spamRemoved = SpamSource.Source.Except(newSpam, new SpamComparer()); foreach (Spam removed in spamRemoved.ToList()) { SpamSource.Source.Remove(removed); } } } } wait.WaitOne(3000); } db.Close(); }); }
public void RefreshInfo() { QueueSource.RefreshInfo(); }
internal void Empty(bool withTruncate) { QueueSource.ClearQueue(withTruncate); }
public void ForwardMessages(IEnumerable <MessageInfo> list, IQueue destinationQ, CancellationToken ct, IProgress <int> progress) { QueueSource.ForwardMessages(list.Select(m => m.MessageSource).ToList(), destinationQ, ct, progress); }
public void DeleteMessages(IEnumerable <MessageInfo> list, CancellationToken ct, IProgress <int> progress) { QueueSource.DeleteMessages(list.Select(m => m.MessageSource).ToList(), ct, progress); }
protected override void Queue() { QueueSource.AddAllTracks(Music); }
public void SetPutStatus(GetPutStatus newStatus) { QueueSource.SetPutStatus(newStatus); }
public void Setup() { _firstPage = new ListMetricsResponse { NextToken = "token-1", Metrics = new List <Metric> { new Metric { MetricName = "ApproximateAgeOfOldestMessage", Dimensions = new List <Dimension> { new Dimension { Name = "QueueName", Value = "Queue-1" } } } } }; _secondPage = new ListMetricsResponse { NextToken = "token-2", Metrics = new List <Metric> { new Metric { MetricName = "ApproximateAgeOfOldestMessage", Dimensions = new List <Dimension> { new Dimension { Name = "QueueName", Value = "Queue-2" } } } } }; _thirdPage = new ListMetricsResponse { NextToken = "token-3", Metrics = new List <Metric> { new Metric { MetricName = "ApproximateAgeOfOldestMessage", Dimensions = new List <Dimension> { new Dimension { Name = "QueueName", Value = "Queue-3" } } } } }; _attributes = new Dictionary <string, string> { { "AttrName", "AttrValue" } }; var cloudWatchMock = new Mock <IAmazonCloudWatch>(); cloudWatchMock.Setup(s => s.ListMetricsAsync( It.Is <ListMetricsRequest>(r => r.MetricName == "ApproximateAgeOfOldestMessage" && r.NextToken == null), It.IsAny <CancellationToken>())) .ReturnsAsync(_firstPage); cloudWatchMock.Setup(s => s.ListMetricsAsync( It.Is <ListMetricsRequest>(r => r.MetricName == "ApproximateAgeOfOldestMessage" && r.NextToken == "token-1"), It.IsAny <CancellationToken>())) .ReturnsAsync(_secondPage); cloudWatchMock.Setup(s => s.ListMetricsAsync( It.Is <ListMetricsRequest>(r => r.MetricName == "ApproximateAgeOfOldestMessage" && r.NextToken == "token-2"), It.IsAny <CancellationToken>())) .ReturnsAsync(_thirdPage); _queueSource = new QueueSource(cloudWatchMock.Object); }
public void EmptyQueue(bool truncate) { QueueSource.ClearQueue(truncate); }