我可以使用 java 应用程序或 spring rest api 触发或调用 azure webjobs

问题描述

我想使用我的 java 应用程序触发或调用 azure webjob,该应用程序是一个简单的 Spring Boot 应用程序。

我有一些问题,例如我们可以使用 Spring Rest API 调用调用或触发 azure webjob 吗?

如果是,那么如何。 webjob 还需要用户名密码

我尝试了类似的东西:

@GetMapping
public String methodCall(@RequestHeader String username,@RequestHeader String password) {
    String ApiUrl = "https://myapp.scm.azurewebsites.net/api/triggeredwebjobs/webjob";
    RestTemplate resetTemplate = new RestTemplate();

    StringBuilder sb = new StringBuilder().append(ApiUrl).append(username).append(password);

    String response = resetTemplate.getForObject(sb.toString(),String.class);

    System.out.println("response:----------" + response);

    return response;
}

解决方法

如果您想运行触发式 azure 网络作业,可以使用 Azure REST API

char                *new_str(char const *s,unsigned int start,size_t len)
{
    char            new[len];
    size_t          i;

    i = 0;
    if (!s || len <= 0 || start >= strlen(s))
        return ("");
    while (i < len)
    {
        new[i] = s[start];
        i++;
        start++;
    }
    new[i] = '\0';
    return (new);
}

int main(void)
{
    char const a[] = "bonjour les amis,ca va ?";
    printf("%s",new_str(a,7));
    return (0);
}

例如

  1. Create a service principal and assign Contributor Role to the sp

  2. 代码

POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/triggeredwebjobs/{webJobName}/run?api-version=2019-08-01

Authorization: Bearer <access token>