简体   繁体   English

Azure Function无法与QueueTrigger和非无效返回值一起使用?

[英]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.

相关问题 HttpClient GetAsync在Windows 8上没有完成非void返回类型 - HttpClient GetAsync doesn't complete with a non-void return type on Windows 8 在不使用其返回值的情况下调用非void函数。究竟发生了什么? - Calling a non-void function without using its return value. What actually happens? 如何创建一个可以返回非空值的异步方法? - How to create an async method that can return the non-void value? 是否可以编译具有非无效返回类型但不返回值的C#方法? - Is it possible to compile a C# method that has non-void return type, but does not return a value? 如何描述返回值(非空)的Action <T>委托? - How do I describe an Action<T> delegate that returns a value (non-void)? QueueTrigger 中的异常 Azure Function - Exception in QueueTrigger Azure Function 在非void方法中缺少return语句编译 - Missing return statement in a non-void method compiles 如何在窗口线程上调用非 void 函数 - How to invoke non-void function on window thread Azure Function QueueTrigger 和 int 消息 - Azure Function QueueTrigger and int message 分配给void委托的lambda会丢弃C#中的非void返回类型吗? - Do lambdas assigned to void delegate discard non-void return type in C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM