简体   繁体   中英

Failed messages are not moved to DLQ from Azure Servicebus triggerfunction

First post, be nice.

I have a Servicebus trigger in Azure. The function is working as expected, triggering when a message enters the queue. The main function of the trigger is to handle the data in the messages and put them into another external system. However, there are no guarantee the external system will accept the data, and thus the handling of the message fails. If that happens, an exception is thrown and the message is moved to the Dead-Letter queue (DLQ). A timertrigger is set up to read the DLQ and move the failed messages back to the main queue, where the Servicebus trigger again retires to handle the message.

My problem right now is that failed messages is not moved to the DLQ, it just vanishes. However, this is not consistent. Sometimes it is moved to the DLQ, but most of the time not.

This has been working, and this started to happen this week.

I've tested posting the same message several times to the queue, and the inconsistency is still there. So I can't see it has something to do with the data in the queue.

I've stripped the code down to the code below and the experience the same.

Does anyone have an idea what might be happening? I can't see it is something in the code, and I haven't done anything with the Servicebus in Azure, but I suspect it might be some setting I've overlooked.

public static void Run([ServiceBusTrigger("xxx", Connection = "xxx")] string myQueueItem, ILogger log)
{
    log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");

    if (myQueueItem == "0")
    {
        log.LogError($"Message failed {myQueueItem}");
        throw new Exception("DLQ test");
    }

}

Looks like it was in my code after all, and it now looks to be working as expected.

During testing I've been reading from the main queue, reading from the DLQ and resubmitting DLQ messages back to the main queue. The SDK objects I've been using to receive and send messages seems to have been preventing the handling of messages if they are not disposed properly in the code:

await sender.DisposeAsync();
await receiver.DisposeAsync();
await client.DisposeAsync();

After implementing this, things seems more stable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM