You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Provides a summary-logging structure during the message routing which
focuses on the functionality rather than the technicality of message
handler registration. An example of these logs:
### Error, that results in dead-lettering
```log
2025-09-08T08:38:42 Debug > [Received] message (message ID="c353d940-fb6e-4990-a8d4-3e15be9e874e") on Azure Service Bus Queue message pump
2025-09-08T08:38:42 Debug > Message "c353d940-fb6e-4990-a8d4-3e15be9e874e" [Skipped by] "PassThruOrderMessageHandler" => "✗ custom context filter failed (returns 'false')"
2025-09-08T08:38:42 Debug > Message "c353d940-fb6e-4990-a8d4-3e15be9e874e" [Skipped by] "ShipmentAzureServiceBusMessageHandler" => "✗ default JSON body parsing failed (exception thrown)": System.Text.Json.JsonException: The JSON property 'Amount' could not be mapped to any .NET member contained in type 'Arcus.Messaging.Tests.Core.Messages.v1.Shipment'.
2025-09-08T08:38:42 Debug > Message "c353d940-fb6e-4990-a8d4-3e15be9e874e" [Skipped by] "OrderBatchMessageHandler" => "
✓ custom context filter passed (against type=AzureServiceBusMessageContext)
✗ default JSON body parsing failed (exception thrown)": System.Text.Json.JsonException: The JSON property 'Id' could not be mapped to any .NET member contained in type 'Arcus.Messaging.Tests.Core.Messages.v1.OrderBatch'.
2025-09-08T08:38:42 Error > Message '"c353d940-fb6e-4990-a8d4-3e15be9e874e"' [Failed in] message pump => ✗ no matched handler handled found for message
2025-09-08T08:38:42 Debug > [Settle:DeadLetter] message (message ID="c353d940-fb6e-4990-a8d4-3e15be9e874e") on Azure Service Bus Queue message pump => "no matched handler handled found for message"
```
### Success, after skipping some handlers
```log
2025-09-08T08:40:10 Debug > [Received] message (message ID="9988e52e-030b-ea6c-9bf5-0629cb0727cf") on Azure Service Bus Queue message pump
2025-09-08T08:40:10 Debug > Message "9988e52e-030b-ea6c-9bf5-0629cb0727cf" [Skipped by] "PassThruOrderMessageHandler" => "✗ custom context filter failed (returns 'false')"
2025-09-08T08:40:10 Debug > Message "9988e52e-030b-ea6c-9bf5-0629cb0727cf" [Skipped by] "PassThruOrderMessageHandler" => "✗ custom context filter failed (returns 'false')"
2025-09-08T08:40:10 Trace > [Test] Write order v1 message to disk: "9988e52e-030b-ea6c-9bf5-0629cb0727cf"
2025-09-08T08:40:10 Debug > "Order" "9988e52e-030b-ea6c-9bf5-0629cb0727cf" [Processed by] "WriteOrderToDiskAzureServiceBusMessageHandler" => "
✓ custom context filter passed (against type=AzureServiceBusMessageContext)
✓ default JSON body parsing passed (additional members=Error)
✓ custom body filter passed (against type=Order)"
2025-09-08T08:40:10 Information > Message '"9988e52e-030b-ea6c-9bf5-0629cb0727cf"' was processed by "WriteOrderToDiskAzureServiceBusMessageHandler" | skipped by "2 other handlers"
```
The `DEBUG` is used to write the matching pre-checks, `INFO`/`ERROR` is
used as the final summary, written as a single sentence.
To accomplish this, this PR places all the logging within the non-Azure
Service Bus-related message routing functionality. This gives us the
opportunity to only focus on Azure Service Bus-related code in the
`ServiceBusMessageRouter` 👉 which it should be.
Furthermore, the integration tests have been enhanced to always add
'unrelated' message handlers, to trigger the message routing more and
not to rely on unit tests (which are not only there to test deprecated
functionality).
Closes#647
returnMessageProcessingResult.Failure(message.MessageId,MessageProcessingError.ProcessingInterrupted,"Cannot process received message as the message pump is shutting down");
167
167
}
168
168
169
-
if(string.IsNullOrEmpty(message.CorrelationId))
170
-
{
171
-
Logger.LogTrace("No operation ID was found on the message '{MessageId}' during processing in the Azure Service Bus {EntityType} message pump '{JobId}'",message.MessageId,EntityType,JobId);
172
-
}
173
-
174
169
#pragma warning disable CS0618// Type or member is obsolete
returnMessageProcessingResult.Failure(message.MessageId,CannotFindMatchedHandler,"Failed to process message in the message pump as no message handler is registered in the dependency container");
Logger.LogDebug("[Received] message (message ID={MessageId}) on Azure Service Bus {EntityType} message pump",messageContext.MessageId,messageContext.EntityType);
returnMessageProcessingResult.Failure(message.MessageId,MatchedHandlerFailed,"Failed to process Azure Service Bus message in pump as the matched handler did not successfully processed the message");
returnMessageProcessingResult.Failure(message.MessageId,CannotFindMatchedHandler,"Failed to process Azure Service Bus message in pump as no message handler was matched against the message");
returnMessageProcessingResult.Failure(message.MessageId,ProcessingInterrupted,"Failed to process message in pump as there was an unexpected critical problem during processing, please see the logs for more information",exception);
105
+
switch(result.Error)
106
+
{
107
+
caseProcessingInterrupted:
108
+
caseMatchedHandlerFailed:
109
+
Logger.LogDebug("[Settle:Abandon] message (message ID={MessageId}) on Azure Service Bus {EntityType} message pump => {ErrorMessage}",messageContext.MessageId,messageContext.EntityType,result.ErrorMessage);
Logger.LogDebug("[Settle:DeadLetter] message (message ID={MessageId}) on Azure Service Bus {EntityType} message pump => {ErrorMessage}",messageContext.MessageId,messageContext.EntityType,result.ErrorMessage);
Logger.LogTrace("Auto-complete message '{MessageId}' (if needed) after processing in Azure Service Bus in message pump '{JobId}'",messageContext.MessageId,messageContext.JobId);
Logger.LogTrace(exception,"Message '{MessageId}' on Azure Service Bus in message pump '{JobId}' does not need to be auto-completed, because it was already settled",messageContext.MessageId,messageContext.JobId);
159
+
Logger.LogTrace(exception,"[Skipped] auto-completion of message '{MessageId}' in Azure Service Bus message pump (already settled)",messageContext.MessageId);
Logger.LogError("Failed to process Azure Service Bus message '{MessageId}' in pump '{JobId}' as no message handlers were registered in the application services, dead-lettering message!",messageContext.MessageId,messageContext.JobId);
181
-
awaitmessageContext.DeadLetterMessageAsync(CannotFindMatchedHandler.ToString(),"No message handlers were registered in the application services",CancellationToken.None);
Logger.LogError("Failed to process Azure Service Bus message '{MessageId}' in pump '{JobId}' as no registered message handler was matched against the message, dead-lettering message!",messageContext.MessageId,messageContext.JobId);
187
-
awaitmessageContext.DeadLetterMessageAsync(CannotFindMatchedHandler.ToString(),"No registered message handler was matched against the message",CancellationToken.None);
Logger.LogDebug("Failed to process Azure Service Bus message '{MessageId}' in pump '{JobId}' as the matched message handler did not successfully process the message, abandoning message!",messageContext.MessageId,messageContext.JobId);
Logger.LogInformation("Azure Service Bus {EntityType} message pump '{JobId}' on entity path '{EntityPath}' in namespace '{Namespace}' started",EntityType,JobId,EntityName,Namespace);
75
+
Logger.LogTrace("Azure Service Bus {EntityType} message pump '{JobId}' on entity path '{EntityPath}' in namespace '{Namespace}' started",EntityType,JobId,EntityName,Namespace);
Logger.LogInformation("Azure Service Bus {EntityType} message pump '{JobId}' on entity path '{EntityPath}' in '{Namespace}' closed : {Time}",EntityType,JobId,EntityName,Namespace,DateTimeOffset.UtcNow);
182
+
Logger.LogTrace("Azure Service Bus {EntityType} message pump '{JobId}' on entity path '{EntityPath}' in '{Namespace}' closed : {Time}",EntityType,JobId,EntityName,Namespace,DateTimeOffset.UtcNow);
returnMessageProcessingResult.Failure("<unavailable>",MessageProcessingError.ProcessingInterrupted,"Cannot process received message as the message is was 'null'");
211
211
}
212
212
213
-
if(string.IsNullOrEmpty(message.CorrelationId))
214
-
{
215
-
Logger.LogTrace("No operation ID was found on the message '{MessageId}' during processing in the Azure Service Bus {EntityType} message pump '{JobId}'",message.MessageId,EntityType,JobId);
Logger.LogTrace("No operation ID was found on the message '{MessageId}' during processing in the Azure Service Bus {EntityType} session-aware message pump '{JobId}'",message.MessageId,EntityType,JobId);
Copy file name to clipboardExpand all lines: src/Arcus.Messaging.Tests.Core/ServiceBus/MessageHandlers/WriteOrderToDiskAzureServiceBusMessageHandler.cs
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ public async Task ProcessMessageAsync(
30
30
MessageCorrelationInfocorrelationInfo,
31
31
CancellationTokencancellationToken)
32
32
{
33
-
_logger.LogTrace("Write order v1 message to disk: {MessageId}",message.Id);
33
+
_logger.LogTrace("[Test] Write order v1 message to disk: {MessageId}",message.Id);
0 commit comments