[英]Azure Function doesn't work with QueueTrigger and non-void return value?
I published my 3 different versions of a function and the last one is where things start to go wrong. 我发布了函数的3个不同版本,最后一个版本是问题开始出现的地方。 I think it's the combination of async, queue trigger and a return value, but I don't know for sure (and I can't find any documentation that helps me out).
我认为这是异步,队列触发器和返回值的组合,但我不确定(而且找不到任何可以帮助我的文档)。
V1: Out-of-box Visual Studio template V1:现成的Visual Studio模板
[FunctionName("Function1")]
public static void Run([QueueTrigger("myqueue-items", Connection = "")]string myQueueItem, TraceWriter log)
{
log.Info($"C# Queue trigger function processed: {myQueueItem}");
}
Works as expected when I deploy & test. 在部署和测试时按预期工作。
V2: Change to async Task
V2:更改为
async Task
[FunctionName("Function1")]
public static async Task([QueueTrigger("myqueue-items", Connection = "")]string myQueueItem, TraceWriter log)
{
await Task.Delay(1000);
log.Info($"C# Queue trigger function processed: {myQueueItem}");
}
Still good. 还好。
V3: Use Task<string>
V3:使用
Task<string>
[FunctionName("Function1")]
public static async Task<string> Run([QueueTrigger("myqueue-items", Connection = "")]string myQueueItem, TraceWriter log)
{
await Task.Delay(1000);
log.Info($"C# Queue trigger function processed: {myQueueItem}");
return new string(myQueueItem.Reverse().ToArray());
}
}
Now when I test in the portal all I see is Status: 202 Accepted
, no output, nothing logged, no error in log streaming, etc. Practically impossible to figure out what's going wrong other than this incremental guess-and-check that I did. 现在,当我在门户网站中进行测试时,我看到的是
Status: 202 Accepted
,未输出,未记录任何内容,日志流中没有错误等。实际上,除了进行此增量猜测和检查外,几乎无法找出问题所在。
Any ideas what the issue is? 任何想法是什么问题?
Queue trigger can't return any data to the caller: it's a queue after all. 队列触发器无法将任何数据返回给调用者:毕竟是队列。
You could use Output Binding feature, for instance to send the output to another queue. 您可以使用输出绑定功能,例如,将输出发送到另一个队列。 But then you need to annotate this binding with an extra attribute:
但是然后您需要使用一个额外的属性来注释此绑定:
[FunctionName("Function1")]
[return: Queue("myqueue-output", Connection = "")]
public static async Task<string> Run([QueueTrigger("myqueue-items", Connection = "")]string myQueueItem, TraceWriter log)
{
await Task.Delay(1000);
log.Info($"C# Queue trigger function processed: {myQueueItem}");
return new string(myQueueItem.Reverse().ToArray());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.