gpt4 book ai didi

azure - 使用 azure-kusto-ingest nodejs 客户端将数据提取到 azure data explorer 时出现 KustoAuthenticationError

转载 作者:行者123 更新时间:2023-12-03 07:03:14 30 4
gpt4 key购买 nike

当我运行此代码时,它显示 KustoAuthenticationError: 无法获取云集群信息 https://clusterName.kusto.windows.net

appId 是应用程序(客户端)ID,appKey 是客户端 key 的值AuthorityId 是目录(租户)ID

我从以下位置获得此代码:https://github.com/Azure/azure-kusto-node/blob/master/packages/azure-kusto-ingest/example.js

代码:

    const IngestClient = require("azure-kusto-ingest").IngestClient;
const IngestStatusQueues = require("azure-kusto-ingest").IngestStatusQueues;
const IngestionProps = require("azure-kusto-ingest").IngestionProperties;
const KustoConnectionStringBuilder = require("azure-kusto-data").KustoConnectionStringBuilder;
const { DataFormat, JsonColumnMapping, IngestionMappingKind, CompressionType, ReportLevel, ReportMethod } = require("azure-kusto-ingest");
const { BlobDescriptor, StreamDescriptor } = require("azure-kusto-ingest").IngestionDescriptors;
const StreamingIngestClient = require("azure-kusto-ingest").StreamingIngestClient;
// const fs = require("fs");

const clusterName = "clusterName";
const authorityId = "authorityId";
const appId = "appId"
const appKey = "appKey"


var d = new Date();
var dateTimeNow = d.toJSON().slice(0,19).replace('T',':');

var data = {"Id" : "1314444525", "Temperature" : 32, "Battery" : 89, "Humidity" : 94, "Time" : dateTimeNow};

var s = require('stream');

var stream = new s.Readable();
stream.push(JSON.stringify(data));
stream.push(null);



// Streaming ingest client
const props2 = new IngestionProps({
database: "DBname",
table: "Tablename",
format: DataFormat.JSON,
ingestionMappingReference: "Pre-defined mapping name",
});

const streamingIngestClient = new StreamingIngestClient(
KustoConnectionStringBuilder.withAadApplicationKeyAuthentication(`https://${clusterName}.kusto.windows.net`, appId, appKey, authorityId),
props2
);

startStreamingIngestion();


async function startStreamingIngestion() {
try {
await streamingIngestClient.ingestFromStream(stream, props2);
console.log("Ingestion done");
await waitForStatus();
} catch (err) {
console.log(err);
}

}


async function waitForStatus(numberOFIngestions = 1) {
while ((await statusQueues.failure.isEmpty()) && (await statusQueues.success.isEmpty())) {
console.log("Waiting for status...");
await sleep(1000);
}

const failures = await statusQueues.failure.pop(numberOFIngestions);
for (let failure of failures) {
console.log('Failed: ${JSON.stringify(failure)}');
}
const successes = await statusQueues.success.pop(numberOFIngestions);
for (let success of successes) {
console.log('Succeeded: ${JSON.stringify(success)}');
}
}

function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}

最佳答案

这通常意味着您无权访问 ADX 集群的端点。验证您的 ADX 群集是否允许通过公共(public)网络发出请求,并且您的 Azure AD 应用程序没有任何传出网络限制。此外,请确保grant 'ingestor' permission on your ADX database to your Azure AD App .

关于azure - 使用 azure-kusto-ingest nodejs 客户端将数据提取到 azure data explorer 时出现 KustoAuthenticationError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71942392/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com