MrDeveloper
MrDeveloper

Reputation: 1041

Adding exception details to dead letters

When using a brokered service bus (in Azure) with a topic with multiple subscriptions, some subscriptions throw exceptions when processing messages. Those messages then get placed into the dead letter queue for that subscription.

How can I see what the problem was, and why the message was dead lettered ?

I'm thinking I can amend the dead letter, but is it common practise to amend the message with the thrown exception ? If so, how is this done using a BrokeredMessage object ? Messages can be abandoned using BrokeredMessage.Abandon(IDictionary[String, Object]) but is using this to record exceptions a known practise or is there a better way ?

Upvotes: 1

Views: 2175

Answers (1)

Slava Asipenko
Slava Asipenko

Reputation: 390

I don't think there is a way for ASB to automatically persist the error somewhere along with the dead lettered message. You can do one of the 2 things though:

  • When you call SubscriptionClient.OnMessage, use the overload with OnMessageOptions onMessageOptions parameter, and provide your error handler in onMessageOptionsExceptionReceived. ASB will call that every time an unhandled exception happens on message arrival. Then you can record the exception in your logs, along with message ID, etc, for later troubleshooting.
  • Or rather than having ASB see your unhandled exceptions, use try / catch inside your message call back (first argument in SubscriptionClient.OnMessage), and do the same error logging there.

Upvotes: 1

Related Questions