Activity function with multiple input parameters
See original GitHub issueHi 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:
- Created 6 years ago
- Comments:5
Top Related StackOverflow Question
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:
Tuple 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.
PR into docs.microsoft.com has been approved. The official guidance will go out with the next docs refresh.