@azure/event-hubs
Version:
Azure Event Hubs SDK for JS.
151 lines (150 loc) • 5.32 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var partitionProcessor_exports = {};
__export(partitionProcessor_exports, {
PartitionProcessor: () => PartitionProcessor
});
module.exports = __toCommonJS(partitionProcessor_exports);
var import_logger = require("./logger.js");
class PartitionProcessor {
constructor(_eventHandlers, _checkpointStore, _context) {
this._eventHandlers = _eventHandlers;
this._checkpointStore = _checkpointStore;
this._context = _context;
}
_eventHandlers;
_checkpointStore;
_context;
_lastEnqueuedEventProperties;
/**
* Information on the last enqueued event in the partition that is being processed.
* This property is updated by the `EventProcessor` if the `trackLastEnqueuedEventProperties` option is set to true
* when creating an instance of EventProcessor
* @readonly
*/
get lastEnqueuedEventProperties() {
return this._lastEnqueuedEventProperties;
}
/**
* Information on the last enqueued event in the partition that is being processed.
* This property is updated by the `EventProcessor` if the `trackLastEnqueuedEventProperties` option is set to true
* when creating an instance of EventProcessor
*/
set lastEnqueuedEventProperties(properties) {
this._lastEnqueuedEventProperties = properties;
}
/**
* The fully qualified namespace from where the current partition is being processed. It is set by the `EventProcessor`
* @readonly
*/
get fullyQualifiedNamespace() {
return this._context.fullyQualifiedNamespace;
}
/**
* The name of the consumer group from where the current partition is being processed. It is set by the `EventProcessor`
* @readonly
*/
get consumerGroup() {
return this._context.consumerGroup;
}
/**
* The name of the event hub to which the current partition belongs. It is set by the `EventProcessor`
* @readonly
*/
get eventHubName() {
return this._context.eventHubName;
}
/**
* The identifier of the Event Hub partition that is being processed. It is set by the `EventProcessor`
* @readonly
*/
get partitionId() {
return this._context.partitionId;
}
/**
* The unique identifier of the `EventProcessor` that has spawned the current instance of `PartitionProcessor`. This is set by the `EventProcessor`
*/
get eventProcessorId() {
return this._context.eventProcessorId;
}
/**
* This method is called when the `EventProcessor` takes ownership of a new partition and before any
* events are received.
*/
async initialize() {
return this._eventHandlers.processInitialize?.(this);
}
/**
* This method is called before the partition processor is closed by the EventProcessor.
*
* @param reason - The reason for closing this partition processor.
*/
async close(reason) {
if (this._eventHandlers.processClose) {
await this._eventHandlers.processClose(reason, this);
}
}
/**
* This method is called when new events are received.
*
* This is also a good place to update checkpoints as appropriate.
*
* @param event - The received events to be processed.
*/
async processEvents(events) {
await this._eventHandlers.processEvents(events, this);
}
/**
* This method is called when an error occurs while receiving events from Event Hubs.
*
* @param error - The error to be processed.
*/
async processError(error) {
if (this._eventHandlers.processError) {
try {
await this._eventHandlers.processError(error, this);
} catch (err) {
import_logger.logger.verbose(`Error thrown from user's processError handler : ${err}`);
}
}
}
/**
* Updates the checkpoint using the event data.
*
* A checkpoint is meant to represent the last successfully processed event by the user from a particular
* partition of a consumer group in an Event Hub instance.
*
* @param eventData - The event that you want to update the checkpoint with.
*/
async updateCheckpoint(eventData) {
const checkpoint = {
fullyQualifiedNamespace: this._context.fullyQualifiedNamespace,
eventHubName: this._context.eventHubName,
consumerGroup: this._context.consumerGroup,
partitionId: this._context.partitionId,
sequenceNumber: eventData.sequenceNumber,
offset: eventData.offset
};
await this._checkpointStore.updateCheckpoint(checkpoint);
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
PartitionProcessor
});
//# sourceMappingURL=partitionProcessor.js.map