/// <summary> /// This method uses an IReliableQueue to store completed RestockRequests which are later sent to the client using batch processing. /// We could send the request immediately but we prefer to minimize traffic back to the Inventory Service by batching multiple requests /// in one trip. /// </summary> /// <param name="actorId"></param> /// <param name="request"></param> public async void RestockRequestCompleted(ActorId actorId, RestockRequest request) { IReliableQueue <RestockRequest> completedRequests = await this.StateManager.GetOrAddAsync <IReliableQueue <RestockRequest> >(CompletedRequestsQueueName); using (ITransaction tx = this.StateManager.CreateTransaction()) { await completedRequests.EnqueueAsync(tx, request); await tx.CommitAsync(); } IRestockRequestActor restockRequestActor = ActorProxy.Create <IRestockRequestActor>(actorId, this.ApplicationName); await restockRequestActor.UnsubscribeAsync <IRestockRequestEvents>(this); //QUESTION:What does this method do? }
/// <summary> /// This method activates an actor to fulfill the RestockRequest. /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task AddRestockRequestAsync(RestockRequest request) { try { //Get dictionary of Restock Requests IReliableDictionary <InventoryItemId, ActorId> requestDictionary = await this.StateManager.GetOrAddAsync <IReliableDictionary <InventoryItemId, ActorId> >(ItemIdToActorIdMapName); ActorId actorId = ActorId.CreateRandom(); try { using (ITransaction tx = this.StateManager.CreateTransaction()) { await requestDictionary.AddAsync(tx, request.ItemId, actorId); await tx.CommitAsync(); } } catch (ArgumentException) { // restock request already exists return; } // Create actor proxy and send the request IRestockRequestActor restockRequestActor = ActorProxy.Create <IRestockRequestActor>(actorId, this.ApplicationName); await restockRequestActor.AddRestockRequestAsync(request); // Successfully added, register for event notifications for completion await restockRequestActor.SubscribeAsync <IRestockRequestEvents>(this); ServiceEventSource.Current.ServiceMessage(this, "Created restock request. Item ID: {0}. Actor ID: {1}", request.ItemId, actorId); } catch (InvalidOperationException ex) { ServiceEventSource.Current.Message(string.Format("RestockRequestManagerService: Actor rejected {0}: {1}", request, ex)); throw; } catch (Exception ex) { ServiceEventSource.Current.Message(string.Format("RestockRequestManagerService: Exception {0}: {1}", request, ex)); throw; } }