用于 JavaScript 的 Azure SynapseClient SDK
这个软件包包含了SynapseClient的同位素SDK.
目前得到支持的环境
- 节点.js 6.x.x 或更高版本
- 浏览器 JavaScript
如何安装
npm install @azure/synapse
如何使用
nodejs - 认证,客户端创建并获得HistoryServerData监测,作为TypeScript所写的示例.
安装 @ azure/ ms- rest- nodeaut
- 请安装最小版本
"@azure/ms-rest-nodeauth": "^3.0.0"。 。 。 .
npm install @azure/ms-rest-nodeauth@"^3.0.0"
样本代码
import * as msRest from "@azure/ms-rest-js";
import * as msRestAzure from "@azure/ms-rest-azure-js";
import * as msRestNodeAuth from "@azure/ms-rest-nodeauth";
import { SynapseClient, SynapseModels, SynapseMappers } from "@azure/synapse";
const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"];
msRestNodeAuth.interactiveLogin().then((creds) => {
const client = new SynapseClient(creds, subscriptionId);
const workspaceName = "testworkspaceName";
const poolName = "testpoolName";
const livyId = "testlivyId";
const appId = "testappId";
const attemptId = "testattemptId";
client.monitoring.getHistoryServerData(workspaceName, poolName, livyId, appId, attemptId).then((result) => {
console.log("The result is:");
console.log(result);
});
}).catch((err) => {
console.error(err);
});
浏览器 - 认证,客户端创建和获取HistoryServerData 监视器,作为JavaScript所写的示例.
安装 @azure/ ms- rest- browseauth
npm install @azure/ms-rest-browserauth
样本代码
见 https://github.com/Azure/ms-rest-browserauth 页面存档备份,存于互联网档案馆 在浏览器中学习如何认证给Azure.
- 索引.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>@azure/synapse sample</title>
<script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script>
<script src="node_modules/@azure/ms-rest-azure-js/dist/msRestAzure.js"></script>
<script src="node_modules/@azure/ms-rest-browserauth/dist/msAuth.js"></script>
<script src="node_modules/@azure/synapse/dist/synapse.js"></script>
<script type="text/javascript">
const subscriptionId = "<Subscription_Id>";
const authManager = new msAuth.AuthManager({
clientId: "<client id for your Azure AD app>",
tenant: "<optional tenant for your organization>"
});
authManager.finalizeLogin().then((res) => {
if (!res.isLoggedIn) {
// may cause redirects
authManager.login();
}
const client = new Azure.Synapse.SynapseClient(res.creds, subscriptionId);
const workspaceName = "testworkspaceName";
const poolName = "testpoolName";
const livyId = "testlivyId";
const appId = "testappId";
const attemptId = "testattemptId";
client.monitoring.getHistoryServerData(workspaceName, poolName, livyId, appId, attemptId).then((result) => {
console.log("The result is:");
console.log(result);
}).catch((err) => {
console.log("An error occurred:");
console.error(err);
});
});
</script>
</head>
<body></body>
</html>
相关项目
