0

I have a Azure function, which calls some API endpoint for database update/insert and then will complete the message in the Queue.In case azure functions code fails after API success, I want to rollback Db operations. How to do that? Please share any samples on this.

Azure Function Run
{
    transactionscope
    {
        callAPI();
        ..some operations
        x = y/0;
        scope,complete()
    }
}

API:

callAPI
{
    transactionscope
    {
        saveDB();
        scope.complete();
    }
}
1

1 Answer 1

0

Assuming you're using Azure Service Bus for your messaging service, you cannot have a transaction spanning two different resources. In the past, with messaging services like MSMQ, you had a distributed coordinator, and resources such as SQL Server and MSMQ could participate in the same transaction to be committed or rolled back together. This is not the case for cloud services. While ASB supports messaging transactions and Azure SQL supports data transactions, those cannot be combined.

What can you do?

Build your Functions to be idempotent. If data is stored successfully but the message fails to be completed and is retried, ensure there's a validation that the data doesn't have to be written again.

For more advanced scenarios, consider implementing the outbox pattern.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.