question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to get some Service Bus message's data inside ProcessErrorAsync method using ServiceBusProcessor?

See original GitHub issue

Library 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:closed
  • Created 6 months ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jsquirecommented, Mar 10, 2023

Am I correct if I say that the general pattern is to view to the data provided by ProcessErrorEventArgs and depends on it we may do something with ServiceBusProcessor instance itself?

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.

1reaction
jsquirecommented, Mar 9, 2023

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found