/// <summary> /// Returns a message to process. /// </summary> /// <param name="context">The message context.</param> /// <returns> /// A message to process or null if there are no messages to process /// </returns> /// <exception cref="ReceiveMessageException">An error occurred while attempting to read messages from the queue</exception> public async Task <IReceivedMessageInternal> ReceiveMessageAsync(IMessageContext context) { if (_configuration.Options().EnableHoldTransactionUntilMessageCommitted) { _commitConnection = (c, b) => _handleMessage.CommitMessage.CommitForTransaction(context); _rollbackConnection = (c, b) => _handleMessage.RollbackMessage.RollbackForTransaction(context); } try { if (_cancelWork.Tokens.Any(m => m.IsCancellationRequested)) { return(null); } if (_configuration.Options().QueueType == QueueTypes.RpcReceive) { var rpc = context.Get(_configuration.HeaderNames.StandardHeaders.RpcContext); if (rpc.MessageId == null || !rpc.MessageId.HasValue) { return(null); } } var connection = GetConnectionAndSetOnContext(context); try { return(await _receiveMessages.GetMessageAsync(context, connection, connection1 => _disposeConnection(connection)).ConfigureAwait(false)); } finally { if (!_configuration.Options().EnableHoldTransactionUntilMessageCommitted) { _disposeConnection(connection); } } } catch (PoisonMessageException exception) { if (exception.MessageId != null && exception.MessageId.HasValue) { context.MessageId = exception.MessageId; } throw; } catch (Exception exception) { throw new ReceiveMessageException("An error occurred while attempting to read messages from the queue", exception); } }
/// <summary> /// Returns a message to process. /// </summary> /// <param name="context">The message context.</param> /// <returns> /// A message to process or null if there are no messages to process /// </returns> /// <exception cref="ReceiveMessageException">An error occurred while attempting to read messages from the queue</exception> public async Task <IReceivedMessageInternal> ReceiveMessageAsync(IMessageContext context) { try { if (ReceiveSharedLogic(context)) { return(await _receiveMessages.GetMessageAsync(context).ConfigureAwait(false)); } return(null); } catch (PoisonMessageException exception) { if (exception.MessageId != null && exception.MessageId.HasValue) { context.MessageId = exception.MessageId; } throw; } catch (Exception exception) { throw new ReceiveMessageException("An error occurred while attempting to read messages from the queue", exception); } }