private Task HandleResponseMessage(AzureServiceBusMessage message, CancellationToken cancellationToken) { if (message.UserProperties.TryGetValue(RequestMessageIdentifierUserPropertyKey, out var requestMessageIdentifier)) { var responseMessageKey = requestMessageIdentifier?.ToString(); if (responseMessageKey.IsNullOrEmpty()) { throw new InvalidOperationException("The response message did not contain a request identifier."); } if (OutstandingResponseKeys.Contains(responseMessageKey)) { OutstandingResponseKeys.Remove(responseMessageKey); if (ResponseMessageDictionary.TryAdd(responseMessageKey, message)) { return(Task.CompletedTask); } } else { // The response is intended for another client manager. return(Task.CompletedTask); } } throw new InvalidOperationException("The response subscriber received multiple responses or the system state is corrupt."); }
internal void AddOutstandingRequest(Guid requestMessageIdentifier) => OutstandingResponseKeys.Add(requestMessageIdentifier.ToSerializedString());