/// <summary> /// This is the main entry point for your service replica. /// This method executes when this replica of your service becomes primary and has write status. /// </summary> /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service replica.</param> protected override async Task RunAsync(CancellationToken cancellationToken) { try { //IEnumerable<QueueMessage> qm = await _receiver.ReceiveMessagesAsync(100); await _publisher.PutMessagesAsync(new[] { QueueMessage.FromText("content at " + DateTime.UtcNow) }); //qm = await _receiver.ReceiveMessagesAsync(100); //separate writes await _blobs.WriteTextAsync("one", "test text 1"); await _blobs.WriteTextAsync("two", "test text 2"); //with transaction object using (ITransaction tx = await _blobs.OpenTransactionAsync()) { await _blobs.WriteTextAsync("three", "test text 1"); await _blobs.WriteTextAsync("four", "test text 2"); await tx.CommitAsync(); } IEnumerable <BlobId> keys = await _blobs.ListAsync(null); string textBack = await _blobs.ReadTextAsync("one"); textBack = await _blobs.ReadTextAsync("two"); } catch (Exception ex) { throw; } IReliableDictionary <string, long> myDictionary = await StateManager.GetOrAddAsync <IReliableDictionary <string, long> >("myDictionary"); while (true) { cancellationToken.ThrowIfCancellationRequested(); using (SFT tx = this.StateManager.CreateTransaction()) { Microsoft.ServiceFabric.Data.ConditionalValue <long> result = await myDictionary.TryGetValueAsync(tx, "Counter"); ServiceEventSource.Current.ServiceMessage(this.Context, "Current Counter Value: {0}", result.HasValue ? result.Value.ToString() : "Value does not exist."); await myDictionary.AddOrUpdateAsync(tx, "Counter", 0, (key, value) => ++ value); // If an exception is thrown before calling CommitAsync, the transaction aborts, all changes are // discarded, and nothing is saved to the secondary replicas. await tx.CommitAsync(); } await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken); } }
public void Binary_NullId_Handled() { QueueMessage qm1 = QueueMessage.FromText("content2"); QueueMessage qm2 = QueueMessage.FromByteArray(qm1.ToByteArray()); Assert.Null(qm2.Id); Assert.Equal("content2", qm2.StringContent); }
public async Task Peek_SendTwoMessages_Peeked() { await _fixture.PutMessageAsync(QueueMessage.FromText("test peeek")); IReadOnlyCollection <QueueMessage> messages = await _fixture.Receiver.PeekMessagesAsync(10); Assert.True(messages.Count > 0); }
public async Task MessageCount_IsGreaterThanZero() { await _publisher.PutMessageAsync(QueueMessage.FromText("test for count")); int count = await _receiver.GetMessageCountAsync(); Assert.True(count > 0); }
private async Task SubmitChunkAsync(IEnumerable <int> indexes) { await _messenger.SendAsync(_channelName, indexes.Select(i => QueueMessage.FromText($"text message {i}"))); UpdateProgress(++_batchesSent, _batchesTotal); Message = $"{_batchesSent * BatchSize}/{_noOfMesssages}"; }
private async Task <string> SendAsync() { string tag = Guid.NewGuid().ToString(); var msg = QueueMessage.FromText("hm"); msg.Properties["tag"] = tag; await _msg.SendAsync(_qn, msg); return(tag); }
public async Task MessageCount_IsGreaterThanZero() { await _publisher.PutMessageAsync(QueueMessage.FromText("test for count")); try { int count = await _receiver.GetMessageCountAsync(); Assert.True(count > 0); } catch (NotSupportedException) { //not all providers support this } }
public async Task MessageCount_IsGreaterThanZero() { //put quite a few messages await _publisher.PutMessagesAsync(Enumerable.Range(0, 100).Select(i => QueueMessage.FromText("message #" + i)).ToList()); try { int count = await _receiver.GetMessageCountAsync(); Assert.True(count > 0); } catch (NotSupportedException) { //not all providers support this } }
public async Task MessageCount_Send_One_Count_Changes() { long count1; try { count1 = await _msg.GetMessageCountAsync(_qn + _receiveChannelSuffix); } catch (NotSupportedException) { return; } await _msg.SendAsync(_qn, QueueMessage.FromText("bla bla")); long count2 = await _msg.GetMessageCountAsync(_qn + _receiveChannelSuffix); Assert.NotEqual(count1, count2); }
public async Task SendMessages_SomeNull_ThrowsArgumentNull() { await Assert.ThrowsAsync <ArgumentNullException>(() => _publisher.PutMessagesAsync(new[] { QueueMessage.FromText("test"), null })); }
public async Task SendMessages_LargeAmount_Succeeds() { await _publisher.PutMessagesAsync(Enumerable.Range(0, 100).Select(i => QueueMessage.FromText("message #" + i)).ToList()); }
public async Task SendMessage_OneMessage_DoesntCrash() { var qm = QueueMessage.FromText("test"); await _publisher.PutMessagesAsync(new[] { qm }); }
public async Task SendMessage_NullChannel_ArgumentException() { await Assert.ThrowsAsync <ArgumentNullException>(() => _msg.SendAsync(null, QueueMessage.FromText("test"))); }
public async Task SendMessage_OneMessage_DoesntCrash() { var qm = QueueMessage.FromText("test"); await _msg.SendAsync(_qn, qm); }