/// <summary> /// Node worker to process reply messages. /// </summary> private async void ReplyLoop() { while (!_disposed) { // receieve broker message InboundMessage msg = null; try { msg = await _replyQueue.ReceiveAsync().ConfigureAwait(false); } catch (Exception) { break; } //TODO: cancel on dispose Envelope envelope = new Envelope(msg, this); // check if we have an correlation if (envelope.ID == Guid.Empty) { // trigger event OnUnroutableReply(new UnroutableReplyEventArgs(envelope)); continue; } // get completion source for this envelope ReplyWait replyWait = default(ReplyWait); bool foundReplyWait = false; lock (_replyWaits) { foundReplyWait = _replyWaits.TryGetValue(envelope.ID, out replyWait); } if (!foundReplyWait) { // log Console.WriteLine("unroutable reply: {0}", envelope.ID); // trigger event OnUnroutableReply(new UnroutableReplyEventArgs(envelope)); } else { // if it's a multi-reply add to results, if not set completion source if (replyWait.Results == null) { lock (_replyWaits) { _replyWaits.Remove(envelope.ID); } replyWait.CompletionSource.TrySetResult(envelope); } else { replyWait.Results.Add(envelope); } } } }
/// <summary> /// Node worker to process reply messages. /// </summary> /// <param name="msg">The inbound message.</param> private void ReplyProcess(InboundMessage msg) { //TODO: cancel on dispose Envelope envelope = new Envelope(msg, this); // check if we have an correlation if (envelope.ID == Guid.Empty) { // trigger event _node.OnUnroutableReply(new UnroutableReplyEventArgs(envelope)); return; } // get completion source for this envelope ReplyWait replyWait = default(ReplyWait); bool foundReplyWait = false; lock (_replyWaits) { foundReplyWait = _replyWaits.TryGetValue(envelope.ID, out replyWait); } if (!foundReplyWait) { // log Console.WriteLine("unroutable reply: {0}", envelope.ID); // trigger event _node.OnUnroutableReply(new UnroutableReplyEventArgs(envelope)); } else { // if it's a multi-reply add to results, if not set completion source if (replyWait.Results == null) { lock (_replyWaits) { _replyWaits.Remove(envelope.ID); } replyWait.CompletionSource.TrySetResult(envelope); } else { replyWait.Results.Add(envelope); } } }