peanar
Version:
A job queue for Node.js based on RabbitMQ
50 lines (49 loc) • 1.66 kB
TypeScript
import amqplib, { Replies } from 'amqplib';
import { ChannelPool } from './pool';
import { IMessage } from 'ts-amqp/dist/interfaces/Basic';
import { IQueue, IBinding } from 'ts-amqp/dist/interfaces/Queue';
import { IExchange } from 'ts-amqp/dist/interfaces/Exchange';
import Consumer from './consumer';
import { IConnectionParams } from 'ts-amqp/dist/interfaces/Connection';
interface IBrokerOptions {
connection?: IConnectionParams;
poolSize: number;
prefetch?: number;
}
/**
* Peanar's broker adapter
*/
export default class NodeAmqpBroker {
private config;
private conn?;
private _connectPromise?;
private _channelConsumers;
pool?: ChannelPool;
constructor(config: IBrokerOptions);
private _connectAmqp;
/**
* Initializes adapter connection and channel
*/
connect: () => Promise<amqplib.ChannelModel>;
ready(): Promise<amqplib.ChannelModel>;
shutdown(): Promise<void>;
queues(queues: IQueue[]): Promise<Replies.AssertQueue[]>;
exchanges(exchanges: IExchange[]): Promise<Replies.AssertExchange[]>;
bindings(bindings: IBinding[]): Promise<Replies.Empty[]>;
private resurrectAllConsumers;
private pauseConsumersOnChannel;
private rewireConsumersOnChannel;
private _startConsumer;
consume(queue: string): PromiseLike<Consumer>;
consumeOver(queues: string[]): Promise<{
queue: string;
channel: amqplib.Channel;
consumer: Consumer;
}>[];
/**
* This method will always try to make a connection
* unless `this.pool` is empty. Call with care.
*/
publish(message: IMessage<unknown>): Promise<boolean>;
}
export {};