2

I have a topic and a subscription that are handled in an azure web job, but some messages should be moved to a dead letter (queue or topic?) after a certain amount of retries. I have no idea what it takes to handle dead letter messages. Does somebody has a code example? Is this possible with azure web jobs?

I'm almost giving up and doing it manually using a retry counter. For the time being, this what I'm doing, but I do not really like the idea to add the message back to the same queue:


public void SynchronizeConsumer( 
    [ServiceBusTrigger("topic")] Consumer consumer, 
    [ServiceBus("topic")] ICollector withError) 
{ 
    try 
    { 
          this.consumerSync.SyncConsumer(consumer); 
    } 
    catch (Exception ex) 
    { 
          consumer.NbOfRetries++; consumersWithError.Add(consumer); 
    } 
}
Thomas
  • 24,234
  • 6
  • 81
  • 125
user1075679
  • 287
  • 1
  • 2
  • 13
  • Possible duplicate of [How do you access the dead letter sub-queue on an Azure subscription?](http://stackoverflow.com/questions/22681954/how-do-you-access-the-dead-letter-sub-queue-on-an-azure-subscription) – Thomas Jul 26 '16 at 20:35

1 Answers1

5

Your messages are going to be moved to a deadletter subscription (= sub-queue). You can access messages from the deadletter subscription in the same way you access message from the normal subscription.

The path of your deadletter subscription is :

topicPath/Subscriptions/subscriptionName/$DeadLetterQueue

If you use ServiceBusTrigger, you function should looks like that:

public void ProcessMessage(
    [ServiceBusTrigger("topicName", "subscriptionName")] BrokeredMessage message)
{
    try
    {
        // Process you message
        ...

        // Complete the message
        message.Complete();
    }
    catch
    {
        message.Abandon();
    }
}

So the function to access the deadletter subscription should be something like that:

public void ProcessDeadletterMessage(
    [ServiceBusTrigger("topicName", "subscriptionName/$DeadLetterQueue")] BrokeredMessage message)
{
    ...
}
Thomas
  • 24,234
  • 6
  • 81
  • 125