@kaushverse/rabbitmq-core 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # @kaushverse/rabbitmq-core
2
+
3
+ Production-ready RabbitMQ SDK for Node.js microservices.
4
+
5
+ This package provides a clean and opinionated way to **connect**, **publish**, **consume**, and **monitor RabbitMQ**, while handling **TLS**, **logging**, **health checks**, and **graceful shutdown** automatically.
6
+
7
+ ---
8
+
9
+ ## Features
10
+
11
+ - Single RabbitMQ connection per service
12
+ - Supports `amqp://` and `amqps://`
13
+ - Message publishing and consuming helpers
14
+ - Built-in bootstrap for service lifecycle
15
+ - Structured logger (pretty logs in dev, JSON in prod)
16
+ - Health check helper for monitoring
17
+ - Graceful shutdown (SIGINT / SIGTERM)
18
+ - Framework agnostic (Express, Fastify, NestJS)
19
+
20
+ ---
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ npm install @kaushverse/rabbitmq-core
26
+ ```
27
+
28
+ ## Full Express Service Example
29
+
30
+ Below is a complete example showing how to use `@kaushverse/rabbitmq-core`
31
+ inside an Express-based microservice with health checks and publishing routes.
32
+
33
+ ### Example: `order-service`
34
+
35
+ ```ts
36
+ import "dotenv/config";
37
+ import express from "express";
38
+ import { bootstrap, rabbitHealth } from "@kaushverse/rabbitmq-core";
39
+
40
+ const app = express();
41
+ app.use(express.json());
42
+
43
+ // Health check endpoint
44
+ app.get("/health", (_, res) => {
45
+ res.json({
46
+ status: "ok",
47
+ ...rabbitHealth(),
48
+ });
49
+ });
50
+
51
+ // Bootstrap the service
52
+ bootstrap({
53
+ serviceName: "order-service",
54
+ rabbit: {
55
+ url: process.env.RABBITMQ_URL!,
56
+ tls: {
57
+ caPath: process.env.RABBITMQ_CA_PATH,
58
+ servername: process.env.RABBITMQ_SERVERNAME,
59
+ rejectUnauthorized: false, // set true in production
60
+ },
61
+ },
62
+ start: () => {
63
+ app.listen(3000, () => {
64
+ console.log("🚀 API running on port 3000");
65
+ });
66
+ },
67
+ });
68
+ ```
69
+
70
+ ```js
71
+ RABBITMQ_URL=amqps://user:password@mq.example.com:5671/vhost
72
+ RABBITMQ_CA_PATH=./certs/ca.pem
73
+ RABBITMQ_SERVERNAME=mq.example.com
74
+ ```
75
+
76
+ ## Publishing Messages
77
+
78
+ Use `publishMessage` to publish events to RabbitMQ.
79
+ The SDK automatically handles channels, serialization, and persistence.
80
+
81
+ ### Import
82
+
83
+ ```js
84
+ import { publishMessage } from "@kaushverse/rabbitmq-core";
85
+
86
+ await publishMessage({
87
+ exchange: "order.events",
88
+ type: "topic",
89
+ routingKey: "order.created",
90
+ message: {
91
+ orderId: "ORD-123",
92
+ amount: 499,
93
+ },
94
+ headers: {
95
+ source: "order-service",
96
+ },
97
+ });
98
+ ```
package/dist/index.js CHANGED
@@ -219,7 +219,7 @@ async function bootstrap({
219
219
  await connectRabbitMQ(rabbit);
220
220
  logger.info("\u{1F407} RabbitMQ connected");
221
221
  await start();
222
- logger.info("\u{1F680} Service started successfully");
222
+ logger.info(`\u{1F680} ${serviceName2} started successfully`);
223
223
  const shutdown = async (signal) => {
224
224
  logger.warn("\u{1F6D1} Shutdown signal received", { signal });
225
225
  await closeRabbitMQ();
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@kaushverse/rabbitmq-core",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Reusable RabbitMQ (AMQP / AMQPS) core for Node.js & microservices",
5
5
  "author": "Kaushik (KaushVerse)",
6
6
  "license": "MIT",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
9
9
  "files": [
10
- "dist"
10
+ "dist",
11
+ "README.md"
11
12
  ],
12
13
  "scripts": {
13
14
  "build": "tsup src/index.ts --dts",