@rabbitmq-ts/fastify-producer
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Fastify's Plugin for RabbitMQ Producer.

Install

npm install --save @rabbitmq-ts/fastify-producer

# or

yarn add @rabbitmq-ts/fastify-producer

# or

pnpm add @rabbitmq-ts/fastify-producer

Usage

import { config } from 'dotenv';
import detect from 'detect-port';
import RabbitMQProducer from '@rabbitmq-ts/fastify-producer';

config({
  path: '.env',
});

import { fastify } from 'config/fastify';

import { EXCHANGE, QUEUE, ROUTE } from './constants';

async function bootstrap(): Promise<typeof fastify> {
  fastify.register(RabbitMQProducer, {
    urls: {
      host: process.env.RABBITMQ_HOST,
      port: process.env.RABBITMQ_PORT,
      username: process.env.RABBITMQ_USERNAME,
      password: process.env.RABBITMQ_PASSWORD,
      virtualHost: process.env.RABBITMQ_VIRTUAL_HOST,
    },
    configurations: {
      exchanges: [
        {
          exchange: EXCHANGE,
          type: 'topic',
          options: {
            durable: false,
          },
        },
      ],
    },
  });

  fastify.get('/', (_request, reply) => {
    fastify.rabbitMQProducer.publish(EXCHANGE, ROUTE, {
      text: 'hello from producer',
    });

    reply.send('Ok');
  });

  const port = await detect(3_000);
  await fastify.listen({
    port,
  });

  return fastify;
}

bootstrap();

Package Sidebar

Install

npm i @rabbitmq-ts/fastify-producer

Weekly Downloads

4

Version

1.0.1

License

MIT

Unpacked Size

6.64 kB

Total Files

7

Last publish

Collaborators

  • zgid123