public Task <object> Send(object request, string urlPrefix, string urlSuffix) { if (queues.TryGetValue(urlPrefix + "-" + urlSuffix, out var queue)) { var source = new TaskCompletionSource <object>(); var envelope = new HttpEnvelope(request, urlSuffix, source); queue.Add(envelope); return(source.Task); } throw new Exception("Unknown URL: " + urlPrefix + "-" + urlSuffix); }
public Task <object> Send(object request, string urlSuffix) { var matchingQueues = queues.Where(q => q.Key.EndsWith("-" + urlSuffix)).ToArray(); if (matchingQueues.Length == 0) { throw new Exception("Unknown URL: " + urlSuffix); } var randomQueue = matchingQueues[r.Next(matchingQueues.Length)]; Console.WriteLine($"Sending request {request.GetType().Name} to {randomQueue.Key}"); var source = new TaskCompletionSource <object>(); var envelope = new HttpEnvelope(request, urlSuffix, source); randomQueue.Value.Add(envelope); return(source.Task); }