async Task ISendTransport.Move(ReceiveContext context, IPipe <SendContext> pipe) { IPipe <ModelContext> modelPipe = Pipe.New <ModelContext>(p => { p.UseFilter(_filter); p.UseExecuteAsync(async modelContext => { try { IBasicProperties properties; string routingKey = ""; RabbitMqBasicConsumeContext basicConsumeContext; if (context.TryGetPayload(out basicConsumeContext)) { properties = basicConsumeContext.Properties; routingKey = basicConsumeContext.RoutingKey; } else { properties = modelContext.Model.CreateBasicProperties(); properties.Headers = new Dictionary <string, object>(); } var moveContext = new RabbitMqMoveContext(context, properties, _exchange, routingKey ?? ""); await pipe.Send(moveContext).ConfigureAwait(false); byte[] body; using (var memoryStream = new MemoryStream()) { using (var bodyStream = context.GetBody()) { await bodyStream.CopyToAsync(memoryStream).ConfigureAwait(false); } body = memoryStream.ToArray(); } var task = modelContext.BasicPublishAsync(_exchange, "", true, properties, body, true); context.AddPendingTask(task); } catch (Exception ex) { if (_log.IsErrorEnabled) { _log.Error("Faulted moving message to error queue: " + _exchange, ex); } throw; } }); }); await _modelCache.Send(modelPipe, context.CancellationToken).ConfigureAwait(false); }
async Task ISendTransport.Move(ReceiveContext context, IPipe <SendContext> pipe) { IPipe <ModelContext> modelPipe = Pipe.New <ModelContext>(p => { p.UseFilter(_filter); p.UseExecuteAsync(async modelContext => { Guid?messageId = context.TransportHeaders.Get("MessageId", default(Guid?)); try { IBasicProperties properties; RabbitMqBasicConsumeContext basicConsumeContext; if (context.TryGetPayload(out basicConsumeContext)) { properties = basicConsumeContext.Properties; } else { properties = modelContext.Model.CreateBasicProperties(); properties.Headers = new Dictionary <string, object>(); } var moveContext = new RabbitMqMoveContext(context, properties); await pipe.Send(moveContext).ConfigureAwait(false); // properties.Headers["Content-Type"] = context.ContentType.MediaType; // if (messageId.HasValue) // properties.MessageId = messageId.ToString(); byte[] body; using (var memoryStream = new MemoryStream()) { using (Stream bodyStream = context.GetBody()) { bodyStream.CopyTo(memoryStream); } body = memoryStream.ToArray(); } Task task = modelContext.BasicPublishAsync(_sendSettings.ExchangeName, "", true, properties, body); context.AddPendingTask(task); if (_log.IsDebugEnabled) { context.InputAddress.LogMoved(modelContext.ConnectionContext.HostSettings.GetSendAddress(_sendSettings), messageId?.ToString() ?? "N/A", "Moved"); } } catch (Exception ex) { if (_log.IsErrorEnabled) { _log.Error("Move To Error Queue Fault: " + _sendSettings.ExchangeName, ex); } throw; } }); }); await _modelCache.Send(modelPipe, context.CancellationToken).ConfigureAwait(false); }