public Task Dispatch(TransportOperations outgoingMessages, TransportTransaction transaction, ContextBag context) { var channel = channelProvider.GetPublishChannel(); try { var unicastTransportOperations = outgoingMessages.UnicastTransportOperations; var multicastTransportOperations = outgoingMessages.MulticastTransportOperations; var tasks = new List <Task>(unicastTransportOperations.Count + multicastTransportOperations.Count); foreach (var operation in unicastTransportOperations) { tasks.Add(SendMessage(operation, channel)); } foreach (var operation in multicastTransportOperations) { tasks.Add(PublishMessage(operation, channel)); } return(tasks.Count == 1 ? tasks[0] : Task.WhenAll(tasks)); } finally { channelProvider.ReturnPublishChannel(channel); } }
async Task MovePoisonMessage(BasicDeliverEventArgs message, string queue) { try { var channel = channelProvider.GetPublishChannel(); try { await channel.RawSendInCaseOfFailure(queue, message.Body, message.BasicProperties).ConfigureAwait(false); } finally { channelProvider.ReturnPublishChannel(channel); } } catch (Exception ex) { Logger.Error($"Failed to move poison message to queue '{queue}'. Returning message to original queue...", ex); await consumer.Model.BasicRejectAndRequeueIfOpen(message.DeliveryTag, exclusiveScheduler).ConfigureAwait(false); return; } try { await consumer.Model.BasicAckSingle(message.DeliveryTag, exclusiveScheduler).ConfigureAwait(false); } catch (AlreadyClosedException ex) { Logger.Warn($"Failed to acknowledge poison message because the channel was closed. The message was sent to queue '{queue}' but also returned to the original queue.", ex); } }
async Task MovePoisonMessage(BasicDeliverEventArgs message, string queue, string messageId = null) { try { var channel = channelProvider.GetPublishChannel(); try { await channel.RawSendInCaseOfFailure(queue, message.Body, message.BasicProperties).ConfigureAwait(false); } finally { channelProvider.ReturnPublishChannel(channel); } } catch (Exception ex) { Logger.Error($"Failed to move poison message{(messageId == null ? "" : $" '{messageId}'")} to queue '{queue}'. Returning message to original queue...", ex);