4

When using the WebJobs SDK what is the proper way to move a BrokeredMessage to the deadletter queue? Usually I would just call msg.DeadLetter(). However, the SDK takes care of managing the life cycle of the brokered message. It will call msg.Complete() if the method returns successful, and it will retry the message if an exception occurs. I need the 3rd case of telling the ServiceBus queue to move the message to the deadletter queue as it is a bad message.

Tod Cunningham
  • 3,691
  • 4
  • 30
  • 32

1 Answers1

7

You can explicitly deadletter the service bus queue and trigger a function when the message is dead lettered.

public static void ProcessSBQueueMessage(
[ServiceBusTrigger("inputqueue")] BrokeredMessage inputText)
{
    inputText.DeadLetter("Webjobs", "webjobsdescription");
    Console.WriteLine(inputText);
}

public static void ProcessSBDeadLetterQueueMessage(
[ServiceBusTrigger("inputqueue/$DeadLetterQueue")] BrokeredMessage inputText)
{
    Console.WriteLine(inputText);
}
pranav rastogi
  • 4,124
  • 23
  • 23
  • Great, thanks for the info. I wasn't sure if it was ok to directly call DeadLetter. Is it also ok to call Complete directly or is it recommend to let the SDK manage the completion? – Tod Cunningham Oct 15 '14 at 17:32
  • I always call .Complete(). I didn't know that the SDK would know how to know if a job was complete. – Ray Suelzer Oct 16 '14 at 02:13
  • On the `Microsoft.Azure.WebJobs.ServiceBus.ServiceBusConfiguration` object passed into the `jobHostConfig.UseServiceBus(..)`, set `MessageOptions = new OnMessageOptions { AutoComplete = true }` to control the AutoCompletion behavior. You can set this false and change your Trigger param to BrokeredMessage, or you can also override `ServiceBusConfiguration.MessagingProvider` if you need to get more complicated even still. (like if you are dealing with sequences with a MaxConcurrentCall > 1) This is also where you set the number of concurrent messages that can be processed by a given JobHost. – JoeBrockhaus Aug 03 '16 at 22:34