@micro.ts/core
Version:
Microservice framework with Typescript
66 lines (65 loc) • 2.02 kB
TypeScript
import { Channel, Options } from 'amqplib';
import { IAmqpConnectionHooks } from '.';
export interface AmqpClientOptions {
/**
* RPC message receiving queue name
*/
rpcQueue: string;
/**
* Recommended true, if a message is not handled by the rpc consumer, it will be requeued,
* so you risk keeping the messages forever in the queue if timed out
*/
unique: boolean;
/**
* Create new channel for this client or use the broker's channel, *recommended
*/
newChannel: boolean;
/**
* Options when asserting the RPC queue
*/
rpcQueueOptions?: Options.AssertQueue;
}
export declare class AmqpClient {
private existingHooks;
private clientOptions;
channel: Channel;
private uniqueId?;
private rpcCallbacks;
private getPayload;
private convertPayload;
/**
* Return full rpcQueue name
*/
get baseRpcQueue(): string;
constructor(existingHooks: IAmqpConnectionHooks, clientOptions: Partial<AmqpClientOptions>);
init(): Promise<void>;
/**
* Handle if received a message on the default RPC queue
* @param msg
*/
private consumeRpcMessage;
/**
* RPC requests, publishes message on the given queue and waits for a response on the default RPC queue
* @param exchange
* @param routingKey
* @param payload
* @param timeout
* @param options
*/
rpc(exchange: string, routingKey: string, payload: any, options?: Options.Publish): Promise<any>;
/**
* Send message directly to the specified queue
* @param queue
* @param payload
* @param options
*/
sendToQueue(queue: string, payload: any, options?: Options.Publish): Promise<void>;
/**
* Publish message to an exchange
* @param exchange
* @param payload
* @param routingKey
* @param options
*/
publish(exchange: string, routingKey: string | undefined, payload: any, options?: Options.Publish | undefined): Promise<void>;
}