public override async Task Invoke(IIncomingPhysicalMessageContext context, Func <Task> next) { var headers = context.Message.Headers; if (!HeaderConverter.ContainsSafeStandardHeaders(headers)) { await next(); } var incomingContentType = context.Message.Headers[SafeStandardHeaders.ContentType]; var messageType = context.Message.Headers[SafeStandardHeaders.MessageType]; var incomingBody = context.Message.Body; if (incomingContentType != ContentTypes.Xml && BodyConverter.TryConvert(incomingBody, incomingContentType, messageType, out var convertedBody)) { headers[SafeStandardHeaders.ContentType] = ContentTypes.Xml; context.UpdateMessage(convertedBody); } HeaderConverter.AppendNServiceBusHeaders(headers); try { await next(); } catch (Exception e) { headers[SafeStandardHeaders.ContentType] = incomingContentType; headers[Headers.ContentType] = incomingContentType; // throw; // Something is wrong with NServiceBus, but i really don't care as long as the message is processed, including that this project does not focus on NServiceBus. } }
public override Task Invoke(IOutgoingPhysicalMessageContext context, Func <Task> next) { HeaderConverter.AppendSafeStandardHeaders(context.Headers); return(next()); }