npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cargolift-cdi/lib-rabbitmq

v0.2.80

Published

Funções utilitárias para trabalhar com RabbitMQ

Readme

@cargolift-cdi/lib-rabbitmq

Utilitários para publicação de mensagens RabbitMQ com confirmação (publisher confirms), enriquecimento de envelope e convenções de integração.

Principais Componentes

  • RabbitMQPublisherService: camada de baixo nível (confirmação, timeout, backpressure, headers contextuais).
  • IntegrationEventPublisher: fachada de alto nível para eventos de integração HTTP → RabbitMQ.
  • publishToDlqAndAck: envia mensagem original (enriquecida) para DLQ e faz ack.
  • RabbitMQConnectionManager: reutiliza conexão evitando overhead de conexão por mensagem.
  • RabbitTopologyManager: criação padronizada de exchanges (AE, DLX, retries) e filas dinâmicas por sistema.

Exemplo Rápido (NestJS)

Módulo

import { Module } from '@nestjs/common';
import { RabbitmqModule } from '@cargolift-cdi/lib-rabbitmq';
import { DemoService } from './demo.service';

@Module({
	imports: [RabbitmqModule],
	providers: [DemoService],
	exports: [DemoService]
})
export class DemoModule {}

Uso em service/controller

@Injectable()
export class DemoService {
	constructor(private readonly integration: IntegrationEventPublisher) {}

	async send(data: any) {
		const meta = await this.integration.publish({
			routingKey: 'integration.erp.demo',
			payload: data,
			raw: { returnMeta: true }
		});
		return meta; // opcional
	}
}

Publicação em Controller

@Post('demo')
async demo(@Req() req: Request) {
	await this.integration.publish({
		routingKey: 'integration.erp.demo',
		req,
		envelope: { event: 'demo', action: 'CREATE' }
	});
	return { ok: true };
}

Metadados de Publicação

RabbitMQPublisherService.publish aceita returnMeta: true em opts retornando:

{
	correlationId: string;
	exchange: string;
	routingKey: string;
	pattern: string;
	sizeBytes: number;
	durationMs: number;
	confirmedAt: string;
}

DLQ Enriquecida

publishToDlqAndAck tenta embutir JSON com:

{
	"failedAt": "2025-09-30T12:34:56.000Z",
	"error": { "name": "Error", "message": "...", "stack": "..." },
	"originalHeaders": { ... },
	"originalPayload": { ... }
}

Header x-dlq-enriched indica 1 (sucesso) ou 0 (fallback raw).

Variáveis de Ambiente

| Nome | Descrição | Default | |------|-----------|---------| | RABBITMQ_URL | URL de conexão | (obrigatório) | | RABBITMQ_EXCHANGE | Exchange default integração | integration.inbound | | RABBITMQ_ALTERNATE_EXCHANGE | Alternate exchange | integration.inbound.ae | | RABBITMQ_EXCHANGE_TYPE | Tipo do exchange | topic | | RABBITMQ_PUBLISH_TIMEOUT_MS | Timeout confirmação | 5000 |

Topologia (opcional)

| Nome | Descrição | Default | |------|-----------|---------| | RABBITMQ_EXCHANGE_INBOUND | Exchange inbound (preferencial) | integration.inbound | | RABBITMQ_EXCHANGE_OUTBOUND | Exchange outbound (preferencial) | integration.outbound | | RABBITMQ_EXCHANGE_AE | Sufixo da AE (compat) | ae | | RABBITMQ_EXCHANGE_AE | Sufixo da AE (preferencial) | ae | | RABBITMQ_EXCHANGE_DLX | Sufixo da DLX (preferencial) | dlx | | RABBITMQ_EXCHANGE_DLX | Sufixo da DLX (compat) | dlx | | RABBITMQ_UNROUTABLE_QUEUE | Nome da fila de unroutable (sem prefixo) | unroutable | | RABBITMQ_RETRY_POLICY_SHORT_MS | TTL retry curto | 120000 | | RABBITMQ_RETRY_POLICY_LONG_MS | TTL retry longo | 3600000 | | RABBITMQ_QUEUE_TYPE | Tipo das filas principais (classic ou quorum) | quorum | | RABBITMQ_RETRY_QUEUE_TYPE | Tipo das filas de retry (herda o principal se vazio) | quorum | | RABBITMQ_DELIVERY_LIMIT | Máximo de entregas antes de enviar para a DLX (quorum) | 0 (desativado) | | RABBITMQ_QUORUM_INITIAL_GROUP_SIZE | Tamanho inicial do grupo quorum | 0 (valor padrão do cluster) |

Notas:

  • As variáveis com sufixo “preferencial” são a convenção nova. As chaves “compat” continuam funcionais para serviços existentes.
  • RabbitTopologyManager usa estas variáveis para criar: AE (fanout), DLX (topic), retries (topic) e filas integration.<system>.* com DLQ e binds.
  • Filas agora são criadas como quorum por padrão (inclusive DLQ e retries). Ajuste as variáveis acima caso precise manter filas clássicas em ambientes limitados.

Boas Práticas

  • Reutilize a instância injetada (não crie manualmente o publisher baixo nível).
  • Evite payloads muito grandes (considerar compressão se sizeBytes > ~256KB).
  • Log de debug seletivo (considere flag futura DEBUG_RABBIT_PUBLISH).

Licença

MIT