@message-queue-toolkit/core
Version:
Useful utilities, interfaces and base classes for message queue handling. Supports AMQP and SQS with a common abstraction on top currently
33 lines • 1.14 kB
JavaScript
import { randomUUID } from 'node:crypto';
export class CommonMetadataFiller {
serviceId;
produceId;
produceTimestamp;
defaultVersion;
constructor(options) {
this.serviceId = options.serviceId;
this.defaultVersion = options.defaultVersion ?? '1.0.0';
this.produceId =
options.idGenerator ??
(() => {
return randomUUID();
});
this.produceTimestamp =
options.timestampGenerator ??
(() => {
return new Date().toISOString();
});
}
produceCurrentServiceId() {
return this.serviceId;
}
produceMetadata(_currentMessage, eventDefinition, precedingMessageMetadata) {
return {
producedBy: this.serviceId,
originatedFrom: precedingMessageMetadata?.originatedFrom ?? this.serviceId,
schemaVersion: eventDefinition.schemaVersion ?? this.defaultVersion,
correlationId: precedingMessageMetadata?.correlationId ?? this.produceId(),
};
}
}
//# sourceMappingURL=MetadataFiller.js.map