Activity function with multiple input parameters

See original GitHub issue

Hi All,

Thank you very much for this excellent application!

I would like to ask some help, clarification in the case below where I have multiple parameters for the activity function called Mapper. In this case I get the error below.

What I tried so far:

  • public static async Task<Example> Mapper([ActivityTrigger] Example example, [ActivityTrigger] ExampleContract exampleContract) --> it throws the error
  • public static async Task<Example> Mapper([ActivityTrigger] Example example, ExampleContract exampleContract) --> throws error
  • public static async Task<Example> Mapper([ActivityTrigger] ExampleContract exampleContract) --> it works fine (it requries some modification in the whole code to achieve mapping)

I don’t think jumping to the conclusion an activity method can accept only a single input parameter would be right. However, I haven’t found any information about this in the documentation nor in example codes.

My questions is it possible to pass multiple parameters to an activity method? if so, then how? Would it be possible to provide an example in the documentation about this?

On the other hand, my implementation in this form is not right. Extracting json should happen only in activity method and I should not pollute starter and orchestrator with these responsibilities.

{
    "runtimeStatus": "Failed",
    "input": {
        "$type": "MasterData.Api.Api.Country.GetCountries.ExampleContract, MasterData.Api",
        "name": "incoming name...",
        "address": "incoming address..."
    },
    "output": "The function 'Mapper' doesn't exist, is disabled, or is not an activity function. The following are the active activity functions: ''",
    "createdTime": "2018-02-10T09:19:29Z",
    "lastUpdatedTime": "2018-02-10T09:19:31Z"
}
public static class GetCountriesAzureFunction
    {

        [FunctionName("GetCountries")]
        public static async Task<HttpResponseMessage> HttpStart(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post")]HttpRequestMessage req,
            [OrchestrationClient]DurableOrchestrationClient starter,
            TraceWriter log)
        {
            // Function input comes from the request content.
            string stringContent = await req.Content.ReadAsStringAsync();
            ExampleContract exampleContract = JsonConvert.DeserializeObject<ExampleContract>(stringContent);
            string instanceId = await starter.StartNewAsync("GetCountriesOrchestrator", exampleContract);

            log.Info($"Started orchestration with ID = '{instanceId}'.");

            return starter.CreateCheckStatusResponse(req, instanceId);
        }

        [FunctionName("GetCountriesOrchestrator")]
        public static async Task<Example> RunOrchestrator(
            [OrchestrationTrigger] DurableOrchestrationContext context)
        {

            ExampleContract incoming = context.GetInput<ExampleContract>();
            Example example = new Example();

            example = await context.CallActivityAsync<Example>("Mapper", example, incoming);

            return example;
        }

        [FunctionName("Mapper")]
        public static async Task<Example> Mapper([ActivityTrigger] Example example, [ActivityTrigger] ExampleContract exampleContract)
        {
            example.Name = exampleContract.Name ?? "empty";
            example.Address = exampleContract.Address ?? "empty";

            return example;
        }

    }

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

8reactions
cgillumcommented, Feb 20, 2018

It’s not possible to pass multiple parameters to an activity function directly. This is mainly a limitation of the Azure Functions binding model.

The workaround is to pass in an array of objects or to use ValueTuple objects.

Array Example:

[FunctionName("GetCountriesOrchestrator")]
public static async Task<Example> RunOrchestrator(
    [OrchestrationTrigger] DurableOrchestrationContext context)
{
    ExampleContract incoming = context.GetInput<ExampleContract>();
    Example example = new Example();

    var inputArray = new[] { incoming, example };
    example = await context.CallActivityAsync<Example>("Mapper", inputArray);
    return example;
}

[FunctionName("Mapper")]
public static async Task<Example> Mapper([ActivityTrigger] Example[] inputs)
{
    return new Example 
    {
        Name = inputs[1].Name ?? "empty",
        Address = inputs[1].Address ?? "empty",
    };
}

Tuple Example:

[FunctionName("GetCountriesOrchestrator")]
public static async Task<Example> RunOrchestrator(
    [OrchestrationTrigger] DurableOrchestrationContext context)
{
    ExampleContract incoming = context.GetInput<ExampleContract>();
    Example example = new Example();

    example = await context.CallActivityAsync<Example>("Mapper", (incoming, example));
    return example;
}

[FunctionName("Mapper")]
public static async Task<Example> Mapper([ActivityTrigger] DurableActivityContext inputs)
{
    var (example, exampleContract) = inputs.GetInput<(ExampleContract, ExampleContract)>();
    example.Name = exampleContract.Name ?? "empty";
    example.Address = exampleContract.Address ?? "empty";

    return example;
}

I’ll leave this issue open to track adding documentation for this, since it’s an ask that’s come up more than once.

1reaction
cgillumcommented, Apr 26, 2018

PR into docs.microsoft.com has been approved. The official guidance will go out with the next docs refresh.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to pass multiple parameters to Azure Durable Activity ...
@Pingpong it's just a dictionary, so in my example I would do value = payload["value_1"] and payload gets passed in to the activity...
Read more >
Bindings for Durable Functions (Azure Functions)
The activity trigger binding supports both inputs and outputs, just like the orchestration trigger. Here are some things to know about input and ......
Read more >
Function chaining in Durable Functions - Azure
DurableTask assembly. This context object lets you call other activity functions and pass input parameters using its CallActivityAsync method.
Read more >
Understanding Azure Durable Functions - Part 4: Passing ...
The second parameter in the call to the CallActivityAsync method of the DurableOrchestrationContext allows an object to be passed to an activity ......
Read more >
How to pass multiple parameters to Azure Durable Activity ...
Do I do something in my function.json ? Workaround Not ideal, but I can pass multiple parameters as a single Tuple something =...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found