I'm using isolated azure function to receive message from the queue. I need to validate received message and if it invalid, send it to the dead-letter queue. The only way how to do it I found is to throw exception and after 10 retries the message will be moved to dead letter queue. Of course it is not good solution. Maybe anyone faced the same task? Thanks!
[Function("Example")]
public async Task ExampleAsync([ServiceBusTrigger("example", Connection = "ServiceBusConnection")] string entityId)
{
if (!int.TryParse(entityId, out var id))
{
// TODO: Move to dead-letter queue
}
}
If you're using the in-process worker, you can dead-letter by binding to ServiceBusMessageActions
in your function and then calling its DeadLetterMessageAsync
method. This would also require that you bind to ServiceBusMessage
rather than just string entityId
.
For example:
[FunctionName("BindingToMessageActions")]
public static async Task Run(
[ServiceBusTrigger("<queue_name>", Connection = "<connection_name>")]
ServiceBusReceivedMessage message,
ServiceBusMessageActions messageActions)
{
if (!int.TryParse(message.Body.ToString()), out var id))
{
await messageActions.DeadLetterMessageAsync(message);
}
}
More examples can be found in the package README.
Unfortunately, this is not yet available in the isolated process model.