【发布时间】:2020-02-13 10:14:44
【问题描述】:
目前,为了重新启动 Mule 应用程序,我需要:
- 通过浏览器登录 Mule
- 导航到运行时管理器
- 选择我的环境
- 找到我的应用程序
- 导航到设置
- 然后重启
我知道 MuleSoft 有一个管理 API (CloudHub API),但我找不到如何通过 REST 调用重新启动应用程序的示例。
如果有人有一个可行的例子或者可以指出我正确的方向,我将不胜感激。
谢谢
【问题讨论】:
目前,为了重新启动 Mule 应用程序,我需要:
我知道 MuleSoft 有一个管理 API (CloudHub API),但我找不到如何通过 REST 调用重新启动应用程序的示例。
如果有人有一个可行的例子或者可以指出我正确的方向,我将不胜感激。
谢谢
【问题讨论】:
以防万一有人想知道如何通过 REST API 重新启动托管在 CloudHub 上的 Mule 应用程序。
调用此 API
https://anypoint.mulesoft.com/cloudhub/api/applications/{domain}/status 带有有效载荷“RESTART”
请求正文中的示例负载:
{
"status": " 'RESTART' or 'stop' or 'start' ",
"staticIpAddress": "10.4.6.22"
}
邮递员代码sn-p:更新承载令牌、域和环境id
curl --request POST \
--url https://anypoint.mulesoft.com/cloudhub/api/applications/{cloudhub-app-
domain}/status \
--header 'Authorization: Bearer token' \
--header 'Content-Type: application/json' \
--header 'Postman-Token: 42539dcd-1d33-4b66-80d9-6cfcc4ed8f77' \
--header 'X-ANYPNT-ENV-ID: environment ID' \
--header 'cache-control: no-cache' \
--data '{\n "status":"RESTART"\n}'
【讨论】:
首先,您需要安装运行时管理器代理
https://docs.mulesoft.com/runtime-manager/installing-and-configuring-runtime-manager-agent
其次,您可以在下面的链接中找到一个示例:
https://docs.mulesoft.com/runtime-manager/managing-applications-and-domains
操作:重启应用程序
PUT http://localhost:9999/mule/applications/myapp/restart HTTP/1.1
Content-Type: application/json
【讨论】:
除了developer9的回答,下面是获取Bearer令牌的方法: https://anypoint.mulesoft.com/exchange/portals/anypoint-platform/f1e97bc6-315a-4490-82a7-23abe036327a.anypoint-platform/access-management-api/version/v1/pages/Authentication/
要访问平台 API,您必须从登录中获取令牌 端点或使用 OAuth 授权过程。 要使用用户名和密码进行身份验证,您必须调用 /login API。
POST /accounts/login HTTP/1.1
Content-Type: application/json
{
"username" : "joe",
"password" : "password"
}
这将返回以下响应和令牌:
{
"access_token": "d127e2ec-a703-4e2a-8629-e9158804748b",
"token_type": "bearer"
}
然后您可以在重新启动(或其他 API 请求)中使用它。例如(注意,更新承载令牌、域和环境 id)
curl --request POST \
--url https://anypoint.mulesoft.com/cloudhub/api/applications/{cloudhub-app-
domain}/status \
--header 'Authorization: Bearer d127e2ec-a703-4e2a-8629-e9158804748b' \
--header 'Content-Type: application/json' \
--header 'Postman-Token: 42539dcd-1d33-4b66-80d9-6cfcc4ed8f77' \
--header 'X-ANYPNT-ENV-ID: environment ID' \
--header 'cache-control: no-cache' \
--data '{\n "status":"RESTART"\n}'
【讨论】: