【发布时间】:2022-01-11 18:55:24
【问题描述】:
我在 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);
});
});
};
【问题讨论】:
标签: javascript node.js azure azure-eventhub