onirii
Version:
Universal queue SDK
115 lines (114 loc) • 4.01 kB
TypeScript
import { Connection } from 'amqplib';
import { Options } from 'amqplib/properties';
import { AmqpConnectInterface } from '../../interface/amqp/amqp-connect-interface';
import { AmqpOriginalChannelWrapper } from '../../wrapper/amqp-original-channel-wrapper';
import { AmqpOriginalConfirmChannelWrapper } from '../../wrapper/amqp-original-confirm-channel-wrapper';
import { AmqpChannelService } from './amqp-channel-service';
import { AmqpConfirmChannelService } from './amqp-confirm-channel-service';
/**
* Amqp Connect Server For Create Connect
*
* @since 1.0.0
* @date 2021-06-01
* @author Luminous(BGLuminous)
*/
export declare class AmqpConnectService implements AmqpConnectInterface {
currentConnection: Connection | undefined;
readonly currentAmqpServerUrl: string | Options.Connect;
readonly instanceName: string;
readonly MAX_CHANNEL_COUNT: number;
private readonly logger;
private wrapperChannelPool;
private serviceChannelPool;
private channelPosition;
/**
* Create a amqp connection service instance
*
* @param {string} name current server identify name (this name also extend to log config).
* @param {string | Options.Connect} amqpUrl specific amqp url and it should include auth info,if is undefined will
* load from env.
*/
constructor(name: string, amqpUrl?: string | Options.Connect);
/**
* Initialize Current Connection, if got connect error throw Error
*
* @param init init callback after connect succeed
* @param retry connect retry times if set -1 this connect will not re-connect
* @param options socket custom options
*/
ready(init?: (instance: this) => void, retry?: number, options?: unknown): Promise<void>;
/**
* Add default listener for each connect service instance
*
* @private
*/
private addDefaultListener;
/**
* add close event listener
*
* @param process event emit callback
*/
addCloseListener(process: (err: any) => void): void;
/**
* add error event listener
*
* @param process event emit callback
*/
addErrorListener(process: (err: any) => void): void;
/**
* Kill current channel by name, this also will refresh pool content
*
* @param {string} channelName channel instance name
* @return {Promise<void>}
*/
killChannel(channelName: string): Promise<boolean>;
/**
* Close connection also will close all channel in this connection
*
* @return {Promise<void>}
*/
close(init?: boolean): Promise<void>;
/**
* Create Amqp Channel Service
*
* @param {'true' | 'false' | boolean} confirmChannel
* @return {Promise<AmqpConfirmChannelService | AmqpChannelService>}
*/
createChannelService(confirmChannel: true): Promise<AmqpConfirmChannelService | undefined>;
createChannelService(confirmChannel: false): Promise<AmqpChannelService | undefined>;
/**
* Create Amqp Channel Wrapper
*
* @param {'true' | 'false' | boolean} confirmChannel
* @return {Promise<AmqpOriginalConfirmChannelWrapper | undefined>}
*/
createChannelWrapper(confirmChannel: true): Promise<AmqpOriginalConfirmChannelWrapper | undefined>;
createChannelWrapper(confirmChannel: false): Promise<AmqpOriginalChannelWrapper | undefined>;
/**
* Kill current AmqpConnectService all wrapper channel
* @return {Promise<void>}
* @private
*/
private killWrapperChannel;
/**
* KIll current AmqpConnectService all service channel
*
* @return {Promise<void>}
* @private
*/
private killServiceChannel;
/**
* Check channel count
*
* @return {Promise<boolean>}
* @protected
*/
private checkChannelCountOvered;
/**
* Generate Next Channel Name
*
* @return {string} new channel name
* @private --
*/
private getNextChannelName;
}