azure-functions - Azure Functions 项目中的 "Startup Code"在哪里?

标签 azure-functions azureservicebus

我正在尝试编写一个使用 ServiceBus 绑定(bind)作为触发器的 Azure 函数。我已将所有内容升级到 netstandard 2.0 和 WebJobs 包的预发布 v3.0 版本,因此我可以正确构建所有内容并生成元数据等。

当我尝试运行该项目时,Azure Functions 主机启动,但提示我没有定义函数,并建议我可能必须在启动代码中手动配置自定义绑定(bind)。我还收到与我尝试部署的函数相关的空引用错误,我怀疑这也可能是由未知的触发器绑定(bind)属性引起的。

我知道服务总线绑定(bind)不再内置,需要注册,但我不知道应该在哪里执行此操作。我的项目只是一个类库,它没有“启动代码”。

这是我启动项目时得到的结果:

[1/5/2018 4:15:46 PM] A function whitelist has been specified, excluding all but the following functions: [ProcessCheckRecognition, ImageConversion]
[1/5/2018 4:15:47 PM] Generating 0 job function(s)
[1/5/2018 4:15:47 PM] Starting Host (HostId=9f4ea53c5136457d883d685e57164f08, Version=2.0.11353.0, ProcessId=12424, Debug=False, Attempt=0, FunctionsExtensionVersion=)
Listening on http://localhost:7071/
Hit CTRL-C to exit...
[1/5/2018 4:15:47 PM] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).
[1/5/2018 4:15:47 PM] Job host started
[1/5/2018 4:15:47 PM] The following 1 functions are in error:
[1/5/2018 4:15:47 PM] ProcessCheckRecognition: Object reference not set to an instance of an object.

这是我的函数类:

public static class JobResponse
{
    [FunctionName("ProcessJobResponse")]
    public static void Run([ServiceBusTrigger("ktl-jobresponse")]ResponseMessage message, TraceWriter log)
    {
    }
}

以及构建时生成的 function.json:

{
  "generatedBy": "Microsoft.NET.Sdk.Functions.Generator-1.0.7",
  "configurationSource": "attributes",
  "bindings": [
    {
      "type": "serviceBusTrigger",
      "queueName": "ktl-jobresponse",
      "name": "message"
    }
  ],
  "disabled": false,
  "scriptFile": "../bin/KutuluWare.Functions.dll",
  "entryPoint": "KutuluWare.Functions.JobResponse.Run"
}

我应该在某个地方调用 config.UseServiceBus() 吗?如果是这样,该代码应该存放在哪里?

最佳答案

运行 func 命令并确保您使用的是 v2 工具(当前处于测试版):

enter image description here

您可以通过运行npm install -g azure-functions-core-tools@core来安装它们

另请参阅this answer类似的问题。

关于azure-functions - Azure Functions 项目中的 "Startup Code"在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48117491/

相关文章:

azure - Microsoft Azure ServiceBus - 如何进行请求/响应?

c# - 带有 CosmosDBTrigger 的 Azure 函数似乎不是由 upsert 触发的

c# - 如何从本地调用另一个函数应用程序?

azure - 限制Azure函数自动缩放

java - 如何使用Spring Boot Java应用程序不断从服务总线队列中拉取消息

c# - 实现 Azure 服务总线监听器应用程序

c# - Azure Functions 环境变量始终为 null

azure - 如何删除所有函数,然后从 AZURE DEVOPS PIPELINE 部署函数应用?

azure - 使用 Silverlight 中的 Windows Azure 服务总线

azure - 在异步方法中使用 QueueClient.OnMessage 是否有意义?