2017-06-21 13 views
0

それはI​Reliable​Dictionaryの、あったように私は、アズールのService Fabric Reliable Collection最も簡単な使用方法、Hello Worldを実装しようとしています。最も簡単なサービスファブリック信頼性の高いコレクション(辞書)の例

this link例では、この例でもStateManagerオブジェクトが必要ですが、作成方法やその作成方法がわかりません。 Actorが必要なようで、今は俳優を避けるために探しています。

誰でもこの例を挙げることができますか?

多くのありがとうございました

答えて

1

心配しないで、私は答えを見つけました。我々は信頼性の高いコレクションを利用したい場合は

重要なポイントは、1 はステートレスサービスで信頼性の高いコレクションを作成することができないということです、我々は必ずしもステートフルサービスを作成する必要があります。

Here信頼できるディクショナリの実装例が見つかりました。次にコードを貼り付けます。これは、クラスにあります。

protected override async Task RunAsync(CancellationToken cancellationToken) 
{ 

var myDictionary = await this.StateManager.GetOrAddAsync<IReliableDictionary<string, long>>("myDictionary"); 

while (true) 
{ 
    cancellationToken.ThrowIfCancellationRequested(); 

    using (var tx = this.StateManager.CreateTransaction()) 
    { 
     var result = await myDictionary.TryGetValueAsync(tx, "Counter"); 

     ServiceEventSource.Current.ServiceMessage(this, "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); 
} 
関連する問題