我在 nodejs 中使用 azure/event-hubs 1.0.8 版本將資料發送到特定的磁區 ID。下面是示例代碼

請有人幫助我如何使用 nodejs 中的 azure/event-hubs 5.6.0 版本將資料發送到特定磁區 ID?我研究了很多,但找不到任何來源。任何幫助,將不勝感激!
以下是 EventHub 5.6.0 的代碼
const insertOneInPartition = (data, partition, eventsHub) => {
const dataToInsert = { body: { ...data } };
return new Promise((resolve, reject) => {
eventsHub.createBatch({ partitionId : partition }).then(async eventDataBatch => {
if (data) {
eventDataBatch.tryAdd(dataToInsert);
await eventsHub.sendBatch(eventDataBatch);
resolve(eventsHub);
} else {
// eslint-disable-next-line prefer-promise-reject-errors
reject('error');
}
}).catch(error => {
reject(error);
});
});
};
uj5u.com熱心網友回復:
對于nodejs客戶端,請參閱createBatch()帶有選項引數的選項,該引數可以包含 partitionId 或磁區鍵,請參閱github 上的 sendEvents 示例代碼,請參閱第 41 行。您可以使用此瀏覽器應用程式將測驗訊息發送到您的特定磁區。
對于Javascript客戶端,您應該partition ID在創建批處理時傳遞。使用磁區 id 構建 batchOptions 并將其發送到create_batch(batchOptions),請參閱第 35 行以在https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/eventhub/ 的代碼示例中設定 partitionId事件中心/samples/v5/javascript/sendEvents.js
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/408215.html
標籤:
