How to get some Service Bus message's data inside ProcessErrorAsync method using ServiceBusProcessor?
See original GitHub issueLibrary name and version
Azure.Messaging.ServiceBus, version 7.12.0
Query/Question
I have such code:
var processor = client.CreateProcessor();
processor.ProcessMessageAsync += async (ProcessMessageEventArgs args) =>
{
object tenantId = null;
args.Message.ApplicationProperties.TryGetValue("tenantId", out var tenantId);
// ...
};
processor.ProcessErrorAsync += async (ProcessErrorEventArgs args) =>
{
// ...
_logger.LogError(...);
};
I write log if something goes wrong. I want to add into the log item tenantId from the message’s application properties. But I’ve not found a way how to get a message inside ProcessErrorAsync handler or how to set some data inside ProcessMessageAsync to make it available inside ProcessErrorAsync.
Environment
No response
Issue Analytics
- State:
- Created 6 months ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How to use ServiceBusProcessor.ProcessErrorAsync
ProcessMessageAsync is a handler that will be called each time a message is read from your Service Bus instance and needs to be...
Read more >Quickstart - Use Azure Service Bus queues from .NET app
This quickstart shows you how to send messages to and receive messages from Azure Service Bus queues using the .NET programming language.
Read more >Receiving Azure Service Bus Messages Using Queues
We will take a walkthrough of how to receive messages using queues. The messages are received and sent using these three protocols: AMQP...
Read more >Class ServiceBusProcessor | Azure SDK for Net
It is constructed by calling CreateProcessor(String, ServiceBusProcessorOptions). The event handler is specified with the ProcessMessageAsync property. The ...
Read more >Lab 10: Asynchronously process messages by using Azure ...
On the Service Bus namespace blade, in the Entities section, select Queues, and then select + Queue. On the Create queue blade, review...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

This is correct. Though, I will mention that the scenarios for this are rare. Unless you know for sure that the errors are unrecoverable (such as the Service Bus queue having been deleted), you generally want to let the processor recover on its own.
Sure. Examples would be any failure in the processor infrastructure itself, such as a transient network issue that persists after being retried. Generally speaking, any action that you need to take in response to a failure with message processing should be handled in the processing handler.
The error handler is intended to allow your application to have awareness of patterns of errors that may be occurring. The processor itself is highly resilient and can recover from most error conditions, but it views each exception as an individual event. Because it does not have insight into the host environment, application, and messaging workload, the processor cannot react to patterns of errors.
For example, if the host network is unavailable, the processor cannot know whether it is appropriate to keep retrying until it returns or whether it should stop processing because the network is not expected to recover. As a result, it will always attempt to make forward progress and relies on the application to understand patterns of events that should be interpreted as “we should stop processing” - and take the appropriate action.