azure - 通过 Webhook url 触发 Azure Web 作业

标签 azure azure-webjobs

我在使用 Webhook url 触发 Azure Webjobs 时遇到问题。

我创建了一个简单的“NoAutomaticTriggerAttribute”Azure Web 作业,下面是代码

例如:

 class Program
{
    // Please set the following connection strings in app.config for this WebJob to run:
    // AzureWebJobsDashboard and AzureWebJobsStorage
    static void Main()
    {
        var test = ConfigurationManager.ConnectionStrings["AzureWebJobsDashboard"].ConnectionString.ToString();
        var config = new JobHostConfiguration(test);

        if (config.IsDevelopment)
        {
            config.UseDevelopmentSettings();
        }

        var host = new JobHost(config);
        host.Call(typeof(Functions).GetMethod("ProcessMethod"));
        // The following code ensures that the WebJob will be running continuously
        host.RunAndBlock();
    }
}

下面是Function类代码:

 public class Functions
{
    // This function will get triggered/executed when a new message is written 
    // on an Azure Queue called queue.

    [NoAutomaticTriggerAttribute]
    public static void ProcessMethod(TextWriter log)
    {
        log.WriteLine("This is First call from Main Method.");
    }
}

现在,当我尝试使用 webhook url 调用 webjob 时:

https://sample.scm.azurewebsites.net/api/triggeredwebjobs/SampleWebJob2/run

它给出了这样的回应:

“没有为‘/api/triggeredwebjobs/SampleWebJob2/run’注册路由”

AzureWebJobsDashboard 中没有捕获任何详细信息

请告诉我这是否是按需调用 Azure Web 作业的正确方法。我这里缺少任何设置吗?

请指导。

最佳答案

确实有一些需要注意的地方:

  1. 部署 WebJob 时,请确保 WebJob 运行模式为“按需运行”。

enter image description here

  • 删除main方法中的RunAndBlock(),否则它会不停地运行,这是为了连续的WebJob。
  • 当您请求WEBHOOK时,请确保设置正确的授权,您可以在WebJob属性页面中获取webhook以及名称、密码。这是 Postman 页面。
  • enter image description here

    enter image description here

    然后您将能够从 WEBHOOK 运行 webjob。

    enter image description here

    关于azure - 通过 Webhook url 触发 Azure Web 作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55339362/

    相关文章:

    azure - 如何获取 azure 中特定 webjobs 的进程 ID?

    azure - 从 Azure CosmosDb 加载 F# 脚本时缺少 DLL 异常

    Azure DevOps - 用户作为审批者触发发布

    Azure Blob 存储 - 将存档的 blob 复制到在线层

    azure - 无法访问 Azure VM 上的 http 页面

    azure - 是按实例还是按站点安排 Azure Web 作业?

    Azure WebJobs SDK - 在 AWS 队列上创建触发器?

    azure - 将自定义 VM 镜像从一个资源组复制到另一个资源组(在同一订阅中)

    c# - Entity Framework 简单名称会导致某些项目出现问题,但不会导致其他项目出现问题

    azure - 核心 WebJob 未观察到应用程序设置