@webda/amqp
Version:
Implements AMQP on webda
82 lines (81 loc) • 2.41 kB
TypeScript
import { CancelablePromise, PubSubService, ServiceParameters } from "@webda/core";
import * as amqplib from "amqplib";
export declare class AMQPPubSubParameters extends ServiceParameters {
url: string;
channel: string;
/**
* @default ""
* @SchemaOptional
*/
subscription: string;
exchange?: {
/**
* @default fanout
*/
type?: string;
/**
* if true, the exchange will survive broker restarts.
* @default true
*/
durable?: boolean;
/**
* if true, messages cannot be published directly to the exchange
* (i.e., it can only be the target of bindings, or possibly create messages ex-nihilo).
* @default false
*/
internal?: boolean;
/**
* if true, the exchange will be destroyed once the number of bindings for which it is the source drop to zero.
* @default false
*/
autoDelete?: boolean;
/**
* an exchange to send messages to if this exchange can’t route them to any queues.
*
* Specific to RabbitMQ
*/
alternateExchange?: string;
/**
* any additional arguments that may be needed by an exchange
*/
arguments?: any;
};
constructor(params: Partial<AMQPPubSubParameters>);
}
/**
*
* @see https://www.rabbitmq.com/tutorials/tutorial-three-python.html
* @WebdaModda AMQPPubSub
*/
export default class AMQPPubSubService<T = any, K extends AMQPPubSubParameters = AMQPPubSubParameters> extends PubSubService<T, K> {
channel: amqplib.Channel;
conn: amqplib.ChannelModel;
exchange: any;
/**
* @override
*/
loadParameters(params: any): AMQPPubSubParameters;
/**
* @override
*/
sendMessage(event: T, routingKey?: string): Promise<void>;
/**
* @override
*/
init(): Promise<this>;
/**
* Return queue size
* @returns
*/
size(): Promise<number>;
/**
* Work a queue calling the callback with every Event received
* If the callback is called without exception the `deleteMessage` is called
* @param callback
* @param eventPrototype
*/
consume(callback: (event: T) => Promise<void>, eventPrototype?: {
new (): T;
}, onBind?: () => void): CancelablePromise;
}
export { AMQPPubSubService };