MomoCodez
MomoCodez

Reputation: 73

Trying to understand Azure Durable Function context

Is there someone who could explain the context.GetInput<>() method of Azure Durable Functions?

Im really confused, because I get different values for same methods:

//Here I get the Url        
[FunctionName(nameof(GetUrlAsync))]
    public async Task<string> GetUrlAsync([ActivityTrigger] IDurableActivityContext context)
    {
        var url = context.GetInput<string>();
        return url;
    }

// Here i get the ID
[FunctionName(nameof(GetIdAsync))]
    public async Task<string> GetIdAsync([ActivityTrigger] IDurableActivityContext context)
    {
        var id = context.GetInput<string>();
        return id;
    }

The Url Function returns Url and the ID Function returns the Id for the same method-call context.GetInput<string>() . But how does this work?

Upvotes: 1

Views: 1713

Answers (1)

Ced
Ced

Reputation: 1207

The orchestrator function which would call these activites will pass through the relevant input

var url = await context.CallActivityAsync<string>("GetUrlAsync", "http://example.com");
var id = await context.CallActivityAsync<string>("GetIdAsync", "id-123")

normally you'd do something a little more interesting with the input than just echo it, but this should give you an idea.

These docs give a good example: https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-sequence?tabs=csharp

Upvotes: 3

Related Questions