Transaction support in Azure WebJobs async functions

By : Nick
Source: Stackoverflow.com
Question!

.NET Framework 4.5.1 introduced transaction support in async methods, for example:

using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
    var result = await DoWorkAsync(cancellationToken)
        .ConfigureAwait(false);

    await DoMoreWorkAsync(result, cancellationToken)
        .ConfigureAwait(false);

    scope.Complete(); // commit to perform all operations above
}

Ref: https://msdn.microsoft.com/en-us/library/dn261473(v=vs.110).aspx

Can this be used in Azure WebJobs async functions as well, to tighten the unit of work and provide better idempotent operations in case of host shutdown? And if so, will it have any impact on the performance?

Update:

It looks like Transactions (single-level) are supported with Service Bus queues (Standard tier) but not with Storage Queues. Ref: 'Foundational Capabilities' section at https://msdn.microsoft.com/en-us/library/azure/hh767287.aspx

By : Nick


Answers

Database access works the same way no matter who calls your code. Be it ASP.NET or WCF or some Azure framework.

You can indeed use transactions to make the work that you are performing atomic. This is basically a good thing. You can, for example, atomically check whether a given queue message or whatever already has been processed or not. If yet you simply bail out and you are idempotent that way.

The performance impact is not influenced by WebJobs. Transactions are exrtemely cheap except if you use distributed transaction which are to be avoided.

By : usr


This video can help you solving your question :)
By: admin