protected override async Task <ResponseMessage> OnReceiveAsync(Guid correlationId, CancellationToken cancellationToken) { if (_receiver == null) { throw new NullReferenceException("There is not receiver queue."); } var message = await _receiver.DequeueAsync(correlationId, _receiverOptionsTimeout * 1000, cancellationToken).ConfigureAwait(false); if (message == null) { throw new MessageQueueTimeoutException(TimeSpan.FromSeconds(_receiverOptionsTimeout), correlationId.ToString()); } if (message.Value == null) { throw new MessageQueueNotFoundException("The Message can't be retrieved, null body on CorrelationId = " + correlationId); } var response = message.Value as ResponseMessage; if (response?.Body != null && _cloneObject) { response.Body = response.Body.DeepClone(); } return(response); }
protected override async Task OnListenerTaskStartAsync(CancellationToken token) { _token = token; _receiver = MemoryQueueManager.GetQueue(Connection.Route, Connection.Name); while (!_token.IsCancellationRequested) { var rcvValue = await _receiver.DequeueAsync(_token).ConfigureAwait(false); if (_token.IsCancellationRequested) { break; } _ = Task.Run(() => EnqueueMessageToProcessAsync(ProcessingTaskAsync, rcvValue)); } }