trade360-nodejs-sdk
Version:
LSports Trade360 SDK for Node.js
70 lines (69 loc) • 3.66 kB
TypeScript
import { BaseEntity, Constructor, TransportMessageHeaders } from '../../../entities/core-entities/index.js';
import { IEntityHandler } from '../..';
import { ILogger } from '../../../logger';
import { IConsumptionLatency } from './interfaces';
/**
* Class that represent message consumption process
* and handle them with all the configured desired
* handlers for entities types and process them with
* the entityHandler call-back function for the
* entityConstructor class type entity type and process
* them with the entityHandler call-back function for
* the entityConstructor class type entity type and
* check message consumption latency and log warning
* if it exceeds the threshold value in seconds or log
* info if it's within the threshold value in seconds
*/
export declare class MessageConsumer {
private logger;
private bodyHandlers;
constructor(logger: ILogger);
/**
* Handle basic message consumption process and handle
* them with all the configured desired handlers for
* entities types and process them with the entityHandler
* call-back function for the entityConstructor class type
* entity type and check message consumption latency and
* log warning if it exceeds the threshold value in seconds
* or log info if it's within the threshold value in seconds
* @param messageContent message content to be consumed and
* processed by the configured entity handlers for the entity
* type and entity handler call-back function for the entity
* constructor class type entity type
* @param messageMqTimestamp message timestamp in milliseconds
* to calculate the message consumption latency in seconds
* @param consumptionLatencyThreshold consumption latency
* threshold in seconds to check if the message consumption
* latency exceeds the threshold value in seconds or not
* @returns void
*/
handleBasicMessage(messageContent: Uint8Array, { messageMqTimestamp, consumptionLatencyThreshold }: IConsumptionLatency, transportHeaders: TransportMessageHeaders): Promise<void>;
/**
* Check message consumption latency and log warning if it
* exceeds the threshold value in seconds or log info if
* it's within the threshold value in seconds. If message or
* threshold is missing, log warning message with the message
* guid provided in the input object parameter and return void
* @param messageMqTimestamp message timestamp in milliseconds
* to calculate the message consumption latency in seconds
* @param consumptionLatencyThreshold consumption latency
* threshold in seconds to check if the message consumption
* latency exceeds the threshold value in seconds or not
* @param msgGuid message guid to be logged in the warning
* message if the message or threshold is missing
* @returns void
*/
checkConsumptionLatency({ messageMqTimestamp, consumptionLatencyThreshold: thresholdInSeconds, msgGuid, }: IConsumptionLatency): void;
/**
* Register new entity handler for specific entity type
* @param entityHandler entity handler instance that implement
* IEntityHandler interface
* @param entityConstructor entity constructor that extends
* BaseEntity class and has entityKey property in its prototype
* @throws Error if entityConstructor is not a trade360 entity
* or if there is an error setting registration for new entity
* handler
* @returns void
*/
RegisterEntityHandler<TEntity extends BaseEntity>(entityHandler: IEntityHandler<TEntity>, entityConstructor: Constructor<TEntity>): void;
}