I was using azure/event-hubs 1.0.8 version in nodejs for sending the data to a specific partition id. Below is the sample code
Please could someone help me how to send data to event to a specific partition id using azure/event-hubs 5.6.0 version in nodejs?. I research a lot but couldn't find any source. Any help would be appreciated!
Below is the code for 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);
});
});
};
For nodejs
clients, see the createBatch()
that takes an options argument that can contain either the partitionId or partition Key, see the sendEvents sample code at github, see line 41. You can use this browser app to send test messages to your specific partition.
For Javascript
clients, you should pass the partition ID
when creating the batch. frame the batchOptions with partition id and send it to create_batch
(batchOptions), see line 35 for setting partitionId in code sample at https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/eventhub/event-hubs/samples/v5/javascript/sendEvents.js