fastify-rabbitmq
Version:
A Fastify RabbitMQ Plugin Developed in Pure TypeScript.
60 lines (55 loc) • 2.04 kB
TypeScript
import * as fastify from 'fastify';
import { FastifyInstance } from 'fastify';
import { ConnectionOptions, Connection } from 'rabbitmq-client';
export { ConnectionOptions } from 'rabbitmq-client';
interface FastifyRabbitMQOptions {
/**
* @since 1.0.0
* @remarks Connection String or object pointing to the RabbitMQ Broker Services
*/
connection: string | ConnectionOptions;
/**
* @since 1.0.0
* @remarks To set the custom nNamespace within this plugin instance. Used to register this plugin more than one time.
*/
namespace?: string;
}
declare module "fastify" {
interface FastifyInstance {
/** Main Decorator for Fastify **/
rabbitmq: Connection & fastifyRabbitMQ.FastifyRabbitMQNO;
}
}
declare namespace fastifyRabbitMQ {
interface FastifyRabbitMQNO {
[namespace: string]: Connection;
}
}
/**
* How we talk with Fastify
* @since 1.0.0
* @param fastify
* @param options
* @param connection
*/
declare const decorateFastifyInstance: (fastify: FastifyInstance, options: FastifyRabbitMQOptions, connection: any) => void;
/**
* Main Function
* @since 1.0.0
* @example
* This is the basics on how to use this plugin:
* ```js
* app.register(fastifyRabbit, {
* connection: 'amqp://guest:guest@localhost'
* })
* ```
* This will allow you to read from your Fastify "object" and
* use this plugin at the "rabbitmq" level. From there you can execute and maintain
* the RabbitMQ Connection using the 'rabbitmq-client' package, which is wrapping around
* this plugin to execute functions it provides.
*
* @see [https://cody-greene.github.io/node-rabbitmq-client/latest/index.html](https://cody-greene.github.io/node-rabbitmq-client/latest/index.html)
*
*/
declare const fastifyRabbit: fastify.FastifyPluginCallback<FastifyRabbitMQOptions, fastify.RawServerDefault, fastify.FastifyTypeProviderDefault, fastify.FastifyBaseLogger>;
export { type FastifyRabbitMQOptions, decorateFastifyInstance, fastifyRabbit as default, fastifyRabbitMQ };