Reputation: 514
I wrote a durable function that works great to handle incoming JSON data and put it into a queue for processing. (I got Table storage working too.) My problem is with the Azure function that handles the queue trigger, where one of my functions isn't being recognized. My full code is currently 200 lines so here's an over-simplified example:
namespace My.Namespace
{
public static class Test
{
[FunctionName("Main")]
public static async void Run([QueueTrigger("queue", Connection = "myinfo_STORAGE")] MyItem Item, ILogger log)
{
await DoSomethingElse("Information");
}
[FunctionName("DoSomething")]
public static async Task Run(string msg, ILogger log)
{
// code to do something
return;
}
}
}
Where I try to do the await
, it's telling me The name 'DoSomething' does not exist in the current context.
I don't understand - it's in the same class & namespace, and this works fine in my durable functions orchestration project. However, I note that in my durable functions orchestration project, durable functions have a context, like so:
[OrchestrationTrigger] IDurableOrchestrationContext context,
And then we use the context to do async work like:
string res = await context.CallActivityAsync<string>("AddSomeData", data);
Where AddSomeData
is defined like:
[FunctionName("AddSomeData")]
public static async Task<Strin> Run(string data, ILogger log)
{
// do work
return "OK";
}
There doesn't seem to be a context for QueueTrigger in the same way as there is for durable function orchestration. What am I missing?
(I'm a VB.NET WinForms programmer transitioning to Azure functions with C#.)
Upvotes: 1
Views: 1456
Reputation: 4869
You can't directly call a function by it's Azure Functions FunctionName
attribute.
In your durable functions orchestration project example, you're not calling the function directly, but via a mechanism provided by the framework:
string res = await context.CallActivityAsync<string>("AddSomeData", data);
Had you tried the following:
string res = await AddSomeData(data); // no such function!
or even:
string res = await AddSomeData(data, log); // still no such function!
You'd wind up with the same exact error, unless the actual function name happens to also be AddSomeData
(in your case, it's Run
- so you'd get the error).
So, instead, you can use the actual name of the function:
[FunctionName("Main")]
public static async void Run([QueueTrigger("queue", Connection = "myinfo_STORAGE")] MyItem Item, ILogger log)
{
await Run("Information", log);
}
Note that you have to pass the log
manually - in the durable functions orchestration project example, the log
is injected via the context.CallActivityAsync
method.
Upvotes: 2