【问题标题】:Error in referencing EventHub assembly in Azure Functions在 Azure Functions 中引用 EventHub 程序集时出错
【发布时间】:2018-03-05 23:52:54
【问题描述】:

我们在尝试将消息从 Azure HTTP 触发器函数发布到事件中心时收到以下错误。我没有包含完整的代码,因为当我包含命名空间本身时出现错误。

>  2018-03-05T12:49:47.912 [Info] Function started
> (Id=da357e2a-3604-4dd1-b199-646ffcc91469)
>     2018-03-05T12:49:47.912 [Error] Function compilation error
>     2018-03-05T12:49:47.912 [Error] run.csx(2,23): error CS0234: The type or namespace name 'EventHubs' does not exist in the namespace
> 'Microsoft.Azure' (are you missing an assembly reference?)
>     2018-03-05T12:49:47.928 [Error] Exception while executing function: Functions.EventsHandler. Microsoft.Azure.WebJobs.Script:
> Script compilation failed.
>     2018-03-05T12:49:47.944 [Error] Function completed (Failure, Id=da357e2a-3604-4dd1-b199-646ffcc91469, Duration=29ms)

这是我的功能代码

using System.Net;
using Microsoft.Azure.EventHubs;
using System.Text;
using System.Threading.Tasks;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{// variable declarations
    private static EventHubClient eventHubClient;
    private const string EhConnectionString = "{Event Hubs connection string}";
    private const string EhEntityPath = "{Event Hub path/name}";

   }

我的项目.json

{"frameworks":
    {"net461":
        {"dependencies":
            {"Microsoft.Azure.EventHubs":"1.1.0"
            }
        }
    }
}

这个错误可能是什么原因。

请帮忙。

【问题讨论】:

    标签: azure azure-eventhub


    【解决方案1】:

    Azure Functions(当前版本 v1)正在将 Microsoft.ServiceBus 客户端用于事件中心。您不需要从 project.json 引用任何额外的 NuGet 包,只需这样做

    #r "Microsoft.ServiceBus"
    using Microsoft.ServiceBus.Messaging;
    

    在您的函数脚本之上。

    此外,我建议不要手动使用EventHubClient。您应该尝试改用Output binding

    【讨论】:

    • 成功了。我手动尝试的原因是我需要在将 xml 推送到事件中心之前将其转换为 JSON。其次,我需要对通过 HTTP 触发器调用我的函数的客户端做出响应。我可以在我的 functions.json 中提及两个输出绑定变量吗
    • 您可以转换成 JSON,然后将其推送到输出绑定。您可以有两个(或更多)输出绑定:事件中心之一将使用 IAsyncCollector
    猜你喜欢
    • 2022-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-25
    • 2019-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多