/// <summary /> private static async Task ReceiveMessageAsync <T>( CorrelationMessage <T> message, Func <T, Task> onRecievedMessage, Action <string> onRecievedCorrelationId, ILogger logger) { onRecievedCorrelationId(message.CorrelationId); // Put correlation identifier into a log context. using (logger.BeginScope("{CorrelationId}", message.CorrelationId)) { await onRecievedMessage(message.Body).ConfigureAwait(false); } }
/// <summary> /// Send message to a message bus with a correlation identifier. /// </summary> public static Task SendAsync <T>(this IBus messageBus, string queue, string correlationId, T body) { if (string.IsNullOrEmpty(correlationId)) { throw new ArgumentException($"{nameof(correlationId)} cannot be null or empty."); } var message = new CorrelationMessage <T> { CorrelationId = correlationId, Body = body }; return(messageBus.SendAsync(queue, message)); }