【问题标题】:How to trigger C++ code with event grid in Azure?如何在 Azure 中使用事件网格触发 C++ 代码?
【发布时间】:2019-10-19 02:19:13
【问题描述】:

我正在尝试在 Azure 存储中上传一个 blob,并且上传成功。现在下一步是使用 C++ 代码处理 blob。 由于 Azure 函数不支持 C++,我该如何处理 blob?

【问题讨论】:

  • 您必须首先构建您的二进制文件并确保您能够从 .net/python/javascript 代码运行它们。一旦你能够做到这一点,现在你可以将这些二进制文件一起上传到你发布你的天蓝色函数的任何地方。

标签: azure azure-functions azure-blob-storage azure-eventgrid


【解决方案1】:

Azure Function 支持运行.exe 可执行文件。所以我建议生成你的 cpp 程序 exe 文件,然后将它上传到 Azure Function 并运行下面的示例代码。

using System;

public static void Run(TimerInfo myTimer, TraceWriter log)
{
    System.Diagnostics.Process process = new System.Diagnostics.Process();
    process.StartInfo.FileName = @"D:\home\site\wwwroot\TimerTriggerCSharp1\testfunc.exe";
    process.StartInfo.Arguments = "";
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.RedirectStandardOutput = true;
    process.StartInfo.RedirectStandardError = true;
    process.Start();
    string output = process.StandardOutput.ReadToEnd();
    string err = process.StandardError.ReadToEnd();
    process.WaitForExit();

    log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
}

【讨论】:

    【解决方案2】:

    正如评论所说,到目前为止,在 Azure Functions 上,有 .NET、Python、Node.js,支持 Java,没有 C++。

    但是,如果您在 Linux 上工作,您可以考虑在 Python 或 Node.js 中调用 C++,例如使用 Extending Python with C or C++ 或 Node.js 使用 C++ Addons 的 Python 文档。我认为您可以更简单地使用带有 Azure Function 的事件网格。

    还有一个关于 Calling C/C++ from Python? 的现有 SO 线程,您可以参考。

    否则,对于在 Windows 上工作,另一种解决方案是将 C++ 代码编译为 Visual Studio 中的动态库,然后您可以从 C# 代码调用 C++ 中的 dll 库。请参考MSDN文档Calling Native Functions from Managed Code了解,或参考SO线程Possible to call C++ code from C#?

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2018-03-17
      • 1970-01-01
      • 2020-07-19
      • 2021-10-21
      • 1970-01-01
      • 2021-06-01
      • 1970-01-01
      • 2021-06-18
      • 2011-05-13
      相关资源
      最近更新 更多