mqrpc
Version:
💫 Easy RPC over RabbitMQ
40 lines (39 loc) • 2.07 kB
TypeScript
import AmqpClient, { AmqpClientOptions } from './AmqpClient';
import { StandardLogger } from './common';
export interface RpcOptions {
rpcExchangeName?: string;
logger?: StandardLogger;
}
export interface RpcServerOptions {
amqpClient: AmqpClientOptions;
rpcServer?: RpcOptions;
}
export default class RpcServer {
procedures: Map<string, (...args: any[]) => any>;
amqpClient: AmqpClient;
rpcExchangeName: string;
log: StandardLogger;
protected consumerTag?: string;
/**
* Instances a new RPC Server with the given config
*
* @param {RpcClientOptions} opts Config for this client, required.
* @param {AmqpClientOptions} opts.amqpClient Config for the underlying AMQP connection, required.
* @param {string} [opts.amqpClient.amqpUrl] URL for the AMQP broker.
* @param {object} [opts.amqpClient.socketOptions] Config for the AMQP connection.
* @param {object} [opts.amqpClient.connection] An open AMQP connection, for re-use.
* @param {object} [opts.amqpClient.channel] An open AMQP channel, for re-use.
* @param {number} [opts.amqpClient.prefetchCount] Global prefetch count when consuming messages. Default
* is 100.
* @param {RpcOptions} [opts.rpcServer] Config for the client itself.
* @param {string} [opts.rpcServer.rpcExchangeName] Exchange where calls are published. Default 'mqrpc'.
* Must match client.
* @param {StandardLogger} [opts.rpcServer.logger] Custom logger for client use.
*/
constructor(opts: RpcServerOptions);
init(): Promise<void>;
term(): Promise<void>;
register(procedure: string, handler: (...args: any[]) => any): void;
registerDebugProcedures(): void;
protected call(procedure: string, args: any[]): Promise<any>;
}