@linagora/rabbitmq-client 0.1.0 → 0.1.2
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/LICENSE +21 -0
- package/README.md +12 -1
- package/dist/index.cjs +19 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -8
- package/dist/index.d.ts +21 -8
- package/dist/index.js +19 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Linagora
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -48,6 +48,17 @@ Only `url` is required. Everything else has defaults.
|
|
|
48
48
|
|
|
49
49
|
Publishes go through a confirm channel, so you know the broker accepted the message. If something goes wrong, the client retries with exponential backoff and forces a new channel on each attempt to avoid retrying on a silently dead connection. Exchange assertions are cached per connection to avoid unnecessary AMQP round-trips on the hot path.
|
|
50
50
|
|
|
51
|
+
You can pass headers, correlation IDs, and other AMQP properties:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
await client.publish('auth', 'user.created', { userId: '123' }, {
|
|
55
|
+
headers: { 'x-trace-id': traceId },
|
|
56
|
+
correlationId: requestId,
|
|
57
|
+
messageId: uuid(),
|
|
58
|
+
expiration: '60000', // TTL in ms
|
|
59
|
+
})
|
|
60
|
+
```
|
|
61
|
+
|
|
51
62
|
### Subscribing
|
|
52
63
|
|
|
53
64
|
Each call to `subscribe` wires up the DLQ plumbing for you:
|
|
@@ -158,4 +169,4 @@ mockConnection.simulateClose()
|
|
|
158
169
|
|
|
159
170
|
## License
|
|
160
171
|
|
|
161
|
-
|
|
172
|
+
MIT
|
package/dist/index.cjs
CHANGED
|
@@ -194,7 +194,11 @@ var RabbitMQClient = class {
|
|
|
194
194
|
this.assertedExchanges.add(exchange);
|
|
195
195
|
}
|
|
196
196
|
this.channel.publish(exchange, routingKey, content, {
|
|
197
|
-
persistent: true
|
|
197
|
+
persistent: true,
|
|
198
|
+
headers: options?.headers,
|
|
199
|
+
correlationId: options?.correlationId,
|
|
200
|
+
messageId: options?.messageId,
|
|
201
|
+
expiration: options?.expiration
|
|
198
202
|
});
|
|
199
203
|
await this.channel.waitForConfirms();
|
|
200
204
|
if (attempts > 0) {
|
|
@@ -354,23 +358,28 @@ var RabbitMQClient = class {
|
|
|
354
358
|
await this.channel.assertExchange(exchange, "topic", { durable: true });
|
|
355
359
|
this.assertedExchanges.add(exchange);
|
|
356
360
|
}
|
|
361
|
+
const queueType = options?.queueArguments?.["x-queue-type"] ?? "quorum";
|
|
362
|
+
const queueArgs = {
|
|
363
|
+
"x-queue-type": queueType,
|
|
364
|
+
"x-overflow": "reject-publish"
|
|
365
|
+
};
|
|
366
|
+
if (queueType === "quorum") {
|
|
367
|
+
queueArgs["x-dead-letter-strategy"] = "at-least-once";
|
|
368
|
+
}
|
|
357
369
|
await this.channel.assertQueue(queue, {
|
|
358
370
|
durable: true,
|
|
359
371
|
deadLetterExchange: dlxExchange,
|
|
360
372
|
deadLetterRoutingKey: dlqRoutingKey,
|
|
361
|
-
arguments: {
|
|
362
|
-
"x-dead-letter-strategy": "at-least-once",
|
|
363
|
-
"x-queue-type": "quorum",
|
|
364
|
-
"x-overflow": "reject-publish",
|
|
365
|
-
...options?.queueArguments
|
|
366
|
-
}
|
|
373
|
+
arguments: { ...queueArgs, ...options?.queueArguments }
|
|
367
374
|
});
|
|
368
375
|
await this.channel.bindQueue(queue, exchange, routingKey);
|
|
369
376
|
const { consumerTag } = await this.channel.consume(
|
|
370
377
|
queue,
|
|
371
378
|
(message) => {
|
|
372
379
|
if (message) {
|
|
373
|
-
this.handleWithRetry(message, handler)
|
|
380
|
+
this.handleWithRetry(message, handler).catch((error) => {
|
|
381
|
+
this.logger.error({ error }, "Unhandled error in message handler");
|
|
382
|
+
});
|
|
374
383
|
}
|
|
375
384
|
},
|
|
376
385
|
{ noAck: false }
|
|
@@ -495,7 +504,8 @@ var RabbitMQClient = class {
|
|
|
495
504
|
callHook(hook, info) {
|
|
496
505
|
try {
|
|
497
506
|
hook?.(info);
|
|
498
|
-
} catch {
|
|
507
|
+
} catch (error) {
|
|
508
|
+
this.logger.debug({ error }, "Observability hook error");
|
|
499
509
|
}
|
|
500
510
|
}
|
|
501
511
|
sleep(ms) {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/client.ts","../src/logger.ts"],"sourcesContent":["export { RabbitMQClient } from './client.js'\nexport type {\n RabbitMQClientOptions,\n RabbitMQHooks,\n RabbitMQMessage,\n RabbitMQMessageHandler,\n RabbitMQSubscription,\n SubscribeOptions,\n} from './types.js'\n","import amqp from 'amqplib'\nimport type {\n RabbitMQClientOptions,\n RabbitMQHooks,\n RabbitMQMessage,\n RabbitMQMessageHandler,\n RabbitMQSubscription,\n SubscribeOptions,\n} from './types.js'\nimport { createLogger } from './logger.js'\nimport type { Logger } from 'pino'\n\nconst DEFAULT_PREFETCH = 10\nconst MAX_PUBLISH_RETRY_DELAY_MS = 60_000\n\nconst DEFAULTS = {\n maxRetries: 3,\n retryDelay: 1000,\n connectionRetryDelay: 5000,\n initMaxAttempts: 5,\n publishMaxAttempts: 5,\n prefetch: DEFAULT_PREFETCH,\n closeTimeout: 5000,\n} as const\n\n/**\n * Production-grade RabbitMQ client with confirm channels, automatic DLQ\n * infrastructure, reconnection with subscription restoration, and\n * exponential-backoff publishing.\n *\n * @example\n * ```ts\n * const client = new RabbitMQClient({ url: 'amqp://localhost' })\n * await client.init()\n * await client.publish('events', 'user.created', { userId: '123' })\n * await client.subscribe('events', 'user.created', 'user-service', handler)\n * ```\n */\nexport class RabbitMQClient {\n private connection: amqp.ChannelModel | null = null\n private channel: amqp.ConfirmChannel | null = null\n private connected = false\n private subscriptions: RabbitMQSubscription[] = []\n private readonly options: Required<Omit<RabbitMQClientOptions, 'logger' | 'hooks'>>\n private readonly logger: Logger\n private readonly hooks: RabbitMQHooks\n private initializationPromise: Promise<void> | null = null\n private reconnectionPromise: Promise<void> | null = null\n private assertedExchanges = new Set<string>()\n private consumerTags = new Map<string, string>()\n private inflightCount = 0\n private drainResolve: (() => void) | null = null\n\n constructor(options: RabbitMQClientOptions) {\n this.options = {\n url: options.url,\n maxRetries: options.maxRetries ?? DEFAULTS.maxRetries,\n retryDelay: options.retryDelay ?? DEFAULTS.retryDelay,\n connectionRetryDelay: options.connectionRetryDelay ?? DEFAULTS.connectionRetryDelay,\n initMaxAttempts: options.initMaxAttempts ?? DEFAULTS.initMaxAttempts,\n publishMaxAttempts: options.publishMaxAttempts ?? DEFAULTS.publishMaxAttempts,\n prefetch: options.prefetch ?? DEFAULTS.prefetch,\n closeTimeout: options.closeTimeout ?? DEFAULTS.closeTimeout,\n }\n this.logger = createLogger(options.logger)\n this.hooks = options.hooks ?? {}\n }\n\n /**\n * Opens a connection and creates a confirm channel. Retries up to\n * `initMaxAttempts` times, then throws. Idempotent and safe to call\n * concurrently — duplicate calls share the same in-flight promise.\n */\n async init(): Promise<void> {\n if (this.connection && this.connected) {\n return\n }\n if (this.initializationPromise) {\n return this.initializationPromise\n }\n // Attach a no-op catch to prevent Node from briefly treating this as an\n // unhandled rejection before the await below registers its own handler.\n this.initializationPromise = this.doConnect(this.options.initMaxAttempts)\n this.initializationPromise.catch(() => undefined)\n try {\n await this.initializationPromise\n } finally {\n this.initializationPromise = null\n }\n }\n\n private async doConnect(maxAttempts?: number): Promise<void> {\n this.assertedExchanges.clear()\n this.consumerTags.clear()\n let attempts = 0\n while (!this.connected) {\n try {\n this.connection = await amqp.connect(this.options.url)\n this.logger.info('Connected to server')\n this.channel = await this.connection.createConfirmChannel()\n this.logger.info('Confirm channel created')\n await this.channel.prefetch(this.options.prefetch)\n this.logger.info({ prefetch: this.options.prefetch }, 'Channel prefetch set')\n\n this.connection.on('error', (error: Error) => {\n this.connected = false\n this.logger.error({ error }, 'Connection error')\n })\n this.connection.on('close', () => {\n this.connected = false\n this.logger.warn('Connection closed')\n this.reconnectWithRetry()\n })\n this.channel.on('error', (error: Error) => {\n this.logger.error({ error }, 'Channel error')\n this.handleChannelFailure()\n })\n this.channel.on('close', () => {\n this.logger.warn('Channel closed')\n this.handleChannelFailure()\n })\n\n this.connected = true\n this.logger.info('Client initialized successfully')\n } catch (error) {\n attempts++\n this.connected = false\n if (maxAttempts !== undefined && attempts >= maxAttempts) {\n this.logger.error({ error, attempts, maxAttempts }, 'Connection failed after maximum attempts')\n throw new Error(\n `Failed to connect to RabbitMQ after ${attempts} attempts. ` +\n 'Check RABBITMQ_URL configuration and RabbitMQ server availability.',\n )\n }\n this.logger.warn(\n {\n error,\n attempt: attempts,\n maxAttempts: maxAttempts ?? 'unlimited',\n retryDelayMs: this.options.connectionRetryDelay,\n },\n 'Connection attempt failed, retrying...',\n )\n await this.sleep(this.options.connectionRetryDelay)\n }\n }\n }\n\n private handleChannelFailure(): void {\n if (this.connected) {\n this.connected = false\n this.reconnectWithRetry()\n }\n }\n\n /**\n * Returns whether the client currently has an active connection and channel.\n */\n isConnected(): boolean {\n return this.connected\n }\n\n /**\n * Publishes a JSON message to a topic exchange with publisher confirms.\n * Retries with exponential backoff (capped at 60 s), forcing a reconnect\n * on each failure. Throws after `publishMaxAttempts` exhausted.\n */\n async publish(\n exchange: string,\n routingKey: string,\n message: RabbitMQMessage,\n options?: { maxAttempts?: number },\n ): Promise<void> {\n let attempts = 0\n const maxAttempts = options?.maxAttempts ?? this.options.publishMaxAttempts\n const baseDelay = this.options.connectionRetryDelay\n const content = Buffer.from(JSON.stringify(message))\n\n while (attempts < maxAttempts) {\n try {\n if (!this.connected) {\n await this.reconnectWithRetry()\n }\n\n if (!this.channel) {\n throw new Error('Channel not available')\n }\n\n if (!this.assertedExchanges.has(exchange)) {\n await this.channel.assertExchange(exchange, 'topic', { durable: true })\n this.assertedExchanges.add(exchange)\n }\n\n this.channel.publish(exchange, routingKey, content, {\n persistent: true,\n })\n\n await this.channel.waitForConfirms()\n\n if (attempts > 0) {\n this.logger.info({ exchange, routingKey, messageSize: content.length, attempts }, 'Published message after retries')\n } else {\n this.logger.info({ exchange, routingKey, messageSize: content.length }, 'Published message')\n }\n this.logger.debug({ exchange, routingKey, payload: message }, 'Published message payload')\n\n this.callHook(this.hooks.onPublish, { exchange, routingKey, attempts: attempts + 1 })\n\n return\n } catch (error) {\n attempts++\n this.connected = false\n\n if (attempts >= maxAttempts) {\n this.logger.error(\n { error, exchange, routingKey, attempts, maxAttempts },\n 'Publish failed after max attempts',\n )\n throw new Error(\n `Failed to publish to ${exchange}/${routingKey} after ${attempts} attempts: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n\n const retryDelay = Math.min(\n baseDelay * Math.pow(2, attempts - 1),\n MAX_PUBLISH_RETRY_DELAY_MS,\n )\n\n this.logger.warn(\n { error, exchange, routingKey, attempt: attempts, maxAttempts, retryDelayMs: retryDelay },\n 'Publish attempt failed, retrying',\n )\n\n await this.sleep(retryDelay)\n }\n }\n }\n\n /**\n * Gracefully shuts down the client. Waits up to `closeTimeout` ms for\n * in-flight message handlers to finish before closing the channel and\n * connection. Pass `false` to preserve subscriptions for a later\n * `init()` / reconnect cycle.\n */\n async close(clearSubscriptions = true): Promise<void> {\n try {\n if (this.inflightCount > 0) {\n this.logger.info({ inflightCount: this.inflightCount }, 'Waiting for in-flight messages to drain')\n await this.waitForDrain(this.options.closeTimeout)\n }\n await this.channel?.close()\n await this.connection?.close()\n this.connection = null\n this.channel = null\n this.connected = false\n this.initializationPromise = null\n this.reconnectionPromise = null\n this.assertedExchanges.clear()\n this.consumerTags.clear()\n if (clearSubscriptions) {\n this.subscriptions = []\n }\n this.logger.info('Connection closed')\n } catch (error) {\n this.logger.error({ error }, 'Error closing connection')\n throw error\n }\n }\n\n private async reconnectWithRetry(): Promise<void> {\n if (this.reconnectionPromise) {\n return this.reconnectionPromise\n }\n this.connected = false\n this.logger.info('Starting reconnection...')\n this.reconnectionPromise = this.doReconnect()\n this.reconnectionPromise.catch(() => undefined)\n try {\n await this.reconnectionPromise\n } finally {\n this.reconnectionPromise = null\n }\n }\n\n private async doReconnect(): Promise<void> {\n await this.doConnect()\n await this.resubscribeAll()\n }\n\n private async resubscribeAll(): Promise<void> {\n if (this.subscriptions.length === 0) {\n return\n }\n this.logger.info({ count: this.subscriptions.length }, 'Re-establishing subscriptions')\n const subs = [...this.subscriptions]\n const results = await Promise.allSettled(\n subs.map(async (sub) => {\n await this.setupSubscription(sub)\n return sub.queue\n }),\n )\n const succeeded: string[] = []\n const failed: string[] = []\n results.forEach((result, index) => {\n if (result.status === 'fulfilled') {\n succeeded.push(result.value)\n } else {\n const queue = subs[index].queue\n failed.push(queue)\n this.logger.error({ error: result.reason, queue }, 'Failed to re-subscribe to queue')\n }\n })\n if (succeeded.length > 0) {\n this.logger.info({ count: succeeded.length, queues: succeeded }, 'Successfully re-subscribed to queues')\n }\n if (failed.length > 0) {\n this.logger.warn({ count: failed.length, queues: failed }, 'Some subscriptions failed to restore')\n }\n this.callHook(this.hooks.onReconnect, { subscriptionsRestored: succeeded.length, subscriptionsFailed: failed.length })\n }\n\n /**\n * Subscribes to a queue with automatic DLQ infrastructure setup.\n *\n * Pass `options.queueArguments` to override the default quorum-queue\n * arguments (merged with the DLQ wiring defaults).\n */\n async subscribe(\n exchange: string,\n routingKey: string,\n queue: string,\n handler: RabbitMQMessageHandler,\n options?: SubscribeOptions,\n ): Promise<void> {\n if (!this.connected || !this.channel) {\n throw new Error('RabbitMQ client not connected. Call init() first.')\n }\n const sub: RabbitMQSubscription = { exchange, routingKey, queue, handler, options }\n const existingIndex = this.subscriptions.findIndex((s) => s.queue === queue)\n if (existingIndex === -1) {\n this.subscriptions.push(sub)\n } else {\n this.subscriptions[existingIndex] = sub\n }\n await this.setupSubscription(sub)\n }\n\n /**\n * Cancels a queue subscription and removes it from the restoration list.\n */\n async unsubscribe(queue: string): Promise<void> {\n const tag = this.consumerTags.get(queue)\n if (tag && this.channel) {\n await this.channel.cancel(tag)\n }\n this.consumerTags.delete(queue)\n this.subscriptions = this.subscriptions.filter((s) => s.queue !== queue)\n this.logger.info({ queue }, 'Unsubscribed from queue')\n }\n\n private async setupSubscription(sub: RabbitMQSubscription): Promise<void> {\n if (!this.channel) {\n throw new Error('Channel not available')\n }\n const { exchange, routingKey, queue, handler, options } = sub\n const dlxExchange = `${exchange}.dlx`\n const dlqQueue = `${queue}.dlq`\n const dlqRoutingKey = `${routingKey}.dead`\n\n await this.channel.assertExchange(dlxExchange, 'topic', { durable: true })\n await this.channel.assertQueue(dlqQueue, { durable: true })\n await this.channel.bindQueue(dlqQueue, dlxExchange, dlqRoutingKey)\n\n if (!this.assertedExchanges.has(exchange)) {\n await this.channel.assertExchange(exchange, 'topic', { durable: true })\n this.assertedExchanges.add(exchange)\n }\n\n await this.channel.assertQueue(queue, {\n durable: true,\n deadLetterExchange: dlxExchange,\n deadLetterRoutingKey: dlqRoutingKey,\n arguments: {\n 'x-dead-letter-strategy': 'at-least-once',\n 'x-queue-type': 'quorum',\n 'x-overflow': 'reject-publish',\n ...options?.queueArguments,\n },\n })\n\n await this.channel.bindQueue(queue, exchange, routingKey)\n const { consumerTag } = await this.channel.consume(\n queue,\n (message) => {\n if (message) {\n this.handleWithRetry(message, handler)\n }\n },\n { noAck: false },\n )\n this.consumerTags.set(queue, consumerTag)\n this.logger.info({ exchange, routingKey, queue }, 'Subscribed to queue')\n }\n\n private async handleWithRetry(\n message: amqp.ConsumeMessage,\n handler: RabbitMQMessageHandler,\n ): Promise<void> {\n // Capture the channel reference so ack/nack always targets the channel\n // that delivered this message, even if a reconnection swaps this.channel.\n const channel = this.channel\n if (!channel) {\n this.logger.warn('Cannot process message -- channel unavailable')\n return\n }\n this.inflightCount++\n try {\n const startTime = Date.now()\n let attempts = 0\n const routingKey = message.fields.routingKey\n const exchange = message.fields.exchange\n\n let content: RabbitMQMessage\n try {\n content = JSON.parse(message.content.toString())\n } catch (parseError) {\n const rawContent = message.content.toString()\n const rawPreview = rawContent.substring(0, 100)\n this.logger.error(\n {\n error: parseError,\n exchange,\n routingKey,\n rawContentPreview: rawPreview + (rawContent.length > 100 ? '...' : ''),\n },\n 'Failed to parse message JSON, sending to DLQ',\n )\n channel.nack(message, false, false)\n this.callHook(this.hooks.onMessageDlq, { exchange, routingKey, duration: 0, reason: 'invalid_json' })\n return\n }\n\n this.logger.debug({ exchange, routingKey, payload: content }, 'Message received, processing')\n\n while (attempts < this.options.maxRetries) {\n try {\n await handler(content)\n const duration = Date.now() - startTime\n this.logger.info(\n { exchange, routingKey, duration, attempts: attempts + 1 },\n 'Message processed successfully',\n )\n channel.ack(message)\n this.callHook(this.hooks.onMessageProcessed, { exchange, routingKey, duration, attempts: attempts + 1 })\n return\n } catch (error) {\n attempts++\n this.logger.error(\n {\n error: error instanceof Error ? error.message : error,\n stack: error instanceof Error ? error.stack : undefined,\n exchange,\n routingKey,\n attempt: attempts,\n maxRetries: this.options.maxRetries,\n },\n 'Handler failed',\n )\n if (attempts < this.options.maxRetries) {\n await this.sleep(this.options.retryDelay)\n }\n }\n }\n\n const duration = Date.now() - startTime\n this.logger.error(\n { exchange, routingKey, maxRetries: this.options.maxRetries, duration },\n 'Message failed after max retries, sending to DLQ',\n )\n channel.nack(message, false, false)\n this.callHook(this.hooks.onMessageDlq, { exchange, routingKey, duration, reason: 'max_retries_exhausted' })\n } finally {\n this.inflightCount--\n if (this.inflightCount === 0 && this.drainResolve) {\n this.drainResolve()\n }\n }\n }\n\n /**\n * Lightweight liveness probe: creates and immediately deletes a temporary\n * exclusive queue. Returns `false` when disconnected or on broker error.\n */\n async checkHealth(): Promise<boolean> {\n if (!this.connected || !this.channel) {\n return false\n }\n try {\n const { queue } = await this.channel.assertQueue('', {\n exclusive: true,\n autoDelete: true,\n })\n await this.channel.deleteQueue(queue)\n return true\n } catch (error) {\n this.logger.warn({ error }, 'Health check failed')\n return false\n }\n }\n\n private waitForDrain(timeout: number): Promise<void> {\n if (this.inflightCount === 0) return Promise.resolve()\n return new Promise<void>((resolve) => {\n const timer = setTimeout(() => {\n this.logger.warn(\n { inflightCount: this.inflightCount },\n 'Close timeout reached with messages still in flight',\n )\n this.drainResolve = null\n resolve()\n }, timeout)\n this.drainResolve = () => {\n clearTimeout(timer)\n this.drainResolve = null\n resolve()\n }\n })\n }\n\n /** Invokes a hook callback, swallowing errors so hooks never break message flow. */\n private callHook<T>(hook: ((info: T) => void) | undefined, info: T): void {\n try { hook?.(info) } catch { /* swallowed */ }\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms))\n }\n}\n","import pino, { type Logger } from 'pino'\n\n/**\n * Creates a child pino logger for the RabbitMQ client.\n *\n * If a parent logger is provided, the child inherits its configuration\n * (level, transports, etc.) for unified log output. Otherwise, a new\n * root logger is created.\n */\nexport const createLogger = (parent?: Logger): Logger => {\n if (parent) {\n return parent.child({ service: 'rabbitmq-client' })\n }\n return pino({ name: 'rabbitmq-client' })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAAiB;;;ACAjB,kBAAkC;AAS3B,IAAM,eAAe,CAAC,WAA4B;AACvD,MAAI,QAAQ;AACV,WAAO,OAAO,MAAM,EAAE,SAAS,kBAAkB,CAAC;AAAA,EACpD;AACA,aAAO,YAAAA,SAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC;;;ADFA,IAAM,mBAAmB;AACzB,IAAM,6BAA6B;AAEnC,IAAM,WAAW;AAAA,EACf,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,sBAAsB;AAAA,EACtB,iBAAiB;AAAA,EACjB,oBAAoB;AAAA,EACpB,UAAU;AAAA,EACV,cAAc;AAChB;AAeO,IAAM,iBAAN,MAAqB;AAAA,EAClB,aAAuC;AAAA,EACvC,UAAsC;AAAA,EACtC,YAAY;AAAA,EACZ,gBAAwC,CAAC;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACT,wBAA8C;AAAA,EAC9C,sBAA4C;AAAA,EAC5C,oBAAoB,oBAAI,IAAY;AAAA,EACpC,eAAe,oBAAI,IAAoB;AAAA,EACvC,gBAAgB;AAAA,EAChB,eAAoC;AAAA,EAE5C,YAAY,SAAgC;AAC1C,SAAK,UAAU;AAAA,MACb,KAAK,QAAQ;AAAA,MACb,YAAY,QAAQ,cAAc,SAAS;AAAA,MAC3C,YAAY,QAAQ,cAAc,SAAS;AAAA,MAC3C,sBAAsB,QAAQ,wBAAwB,SAAS;AAAA,MAC/D,iBAAiB,QAAQ,mBAAmB,SAAS;AAAA,MACrD,oBAAoB,QAAQ,sBAAsB,SAAS;AAAA,MAC3D,UA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,YAAY;AAAA,MACd,CAAC;AACD,YAAM,KAAK,QAAQ,YAAY,KAAK;AACpC,aAAO;AAAA,IACT,SAAS,OAAO;AACd,WAAK,OAAO,KAAK,EAAE,MAAM,GAAG,qBAAqB;AACjD,aAAO;AAAA,IACT;AAAA,EACF;AAAA,EAEQ,aAAa,SAAgC;AACnD,QAAI,KAAK,kBAAkB,EAAG,QAAO,QAAQ,QAAQ;AACrD,WAAO,IAAI,QAAc,CAAC,YAAY;AACpC,YAAM,QAAQ,WAAW,MAAM;AAC7B,aAAK,OAAO;AAAA,UACV,EAAE,eAAe,KAAK,cAAc;AAAA,UACpC;AAAA,QACF;AACA,aAAK,eAAe;AACpB,gBAAQ;AAAA,MACV,GAAG,OAAO;AACV,WAAK,eAAe,MAAM;AACxB,qBAAa,KAAK;AAClB,aAAK,eAAe;AACpB,gBAAQ;AAAA,MACV;AAAA,IACF,CAAC;AAAA,EACH;AAAA;AAAA,EAGQ,SAAY,MAAuC,MAAe;AACxE,QAAI;AAAE,aAAO,IAAI;AAAA,IAAE,QAAQ;AAAA,IAAkB;AAAA,EAC/C;AAAA,EAEQ,MAAM,IAA2B;AACvC,WAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,EAAE,CAAC;AAAA,EACzD;AACF;","names":["pino","amqp","duration"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/client.ts","../src/logger.ts"],"sourcesContent":["export { RabbitMQClient } from './client.js'\nexport type {\n PublishOptions,\n RabbitMQClientOptions,\n RabbitMQHooks,\n RabbitMQMessage,\n RabbitMQMessageHandler,\n RabbitMQSubscription,\n SubscribeOptions,\n} from './types.js'\n","import amqp from 'amqplib'\nimport type {\n PublishOptions,\n RabbitMQClientOptions,\n RabbitMQHooks,\n RabbitMQMessage,\n RabbitMQMessageHandler,\n RabbitMQSubscription,\n SubscribeOptions,\n} from './types.js'\nimport { createLogger } from './logger.js'\nimport type { Logger } from 'pino'\n\nconst DEFAULT_PREFETCH = 10\nconst MAX_PUBLISH_RETRY_DELAY_MS = 60_000\n\nconst DEFAULTS = {\n maxRetries: 3,\n retryDelay: 1000,\n connectionRetryDelay: 5000,\n initMaxAttempts: 5,\n publishMaxAttempts: 5,\n prefetch: DEFAULT_PREFETCH,\n closeTimeout: 5000,\n} as const\n\n/**\n * Production-grade RabbitMQ client with confirm channels, automatic DLQ\n * infrastructure, reconnection with subscription restoration, and\n * exponential-backoff publishing.\n *\n * @example\n * ```ts\n * const client = new RabbitMQClient({ url: 'amqp://localhost' })\n * await client.init()\n * await client.publish('events', 'user.created', { userId: '123' })\n * await client.subscribe('events', 'user.created', 'user-service', handler)\n * ```\n */\nexport class RabbitMQClient {\n private connection: amqp.ChannelModel | null = null\n private channel: amqp.ConfirmChannel | null = null\n private connected = false\n private subscriptions: RabbitMQSubscription[] = []\n private readonly options: Required<Omit<RabbitMQClientOptions, 'logger' | 'hooks'>>\n private readonly logger: Logger\n private readonly hooks: RabbitMQHooks\n private initializationPromise: Promise<void> | null = null\n private reconnectionPromise: Promise<void> | null = null\n private assertedExchanges = new Set<string>()\n private consumerTags = new Map<string, string>()\n private inflightCount = 0\n private drainResolve: (() => void) | null = null\n\n constructor(options: RabbitMQClientOptions) {\n this.options = {\n url: options.url,\n maxRetries: options.maxRetries ?? DEFAULTS.maxRetries,\n retryDelay: options.retryDelay ?? DEFAULTS.retryDelay,\n connectionRetryDelay: options.connectionRetryDelay ?? DEFAULTS.connectionRetryDelay,\n initMaxAttempts: options.initMaxAttempts ?? DEFAULTS.initMaxAttempts,\n publishMaxAttempts: options.publishMaxAttempts ?? DEFAULTS.publishMaxAttempts,\n prefetch: options.prefetch ?? DEFAULTS.prefetch,\n closeTimeout: options.closeTimeout ?? DEFAULTS.closeTimeout,\n }\n this.logger = createLogger(options.logger)\n this.hooks = options.hooks ?? {}\n }\n\n /**\n * Opens a connection and creates a confirm channel. Retries up to\n * `initMaxAttempts` times, then throws. Idempotent and safe to call\n * concurrently — duplicate calls share the same in-flight promise.\n */\n async init(): Promise<void> {\n if (this.connection && this.connected) {\n return\n }\n if (this.initializationPromise) {\n return this.initializationPromise\n }\n // Attach a no-op catch to prevent Node from briefly treating this as an\n // unhandled rejection before the await below registers its own handler.\n this.initializationPromise = this.doConnect(this.options.initMaxAttempts)\n this.initializationPromise.catch(() => undefined)\n try {\n await this.initializationPromise\n } finally {\n this.initializationPromise = null\n }\n }\n\n private async doConnect(maxAttempts?: number): Promise<void> {\n this.assertedExchanges.clear()\n this.consumerTags.clear()\n let attempts = 0\n while (!this.connected) {\n try {\n this.connection = await amqp.connect(this.options.url)\n this.logger.info('Connected to server')\n this.channel = await this.connection.createConfirmChannel()\n this.logger.info('Confirm channel created')\n await this.channel.prefetch(this.options.prefetch)\n this.logger.info({ prefetch: this.options.prefetch }, 'Channel prefetch set')\n\n this.connection.on('error', (error: Error) => {\n this.connected = false\n this.logger.error({ error }, 'Connection error')\n })\n this.connection.on('close', () => {\n this.connected = false\n this.logger.warn('Connection closed')\n this.reconnectWithRetry()\n })\n this.channel.on('error', (error: Error) => {\n this.logger.error({ error }, 'Channel error')\n this.handleChannelFailure()\n })\n this.channel.on('close', () => {\n this.logger.warn('Channel closed')\n this.handleChannelFailure()\n })\n\n this.connected = true\n this.logger.info('Client initialized successfully')\n } catch (error) {\n attempts++\n this.connected = false\n if (maxAttempts !== undefined && attempts >= maxAttempts) {\n this.logger.error({ error, attempts, maxAttempts }, 'Connection failed after maximum attempts')\n throw new Error(\n `Failed to connect to RabbitMQ after ${attempts} attempts. ` +\n 'Check RABBITMQ_URL configuration and RabbitMQ server availability.',\n )\n }\n this.logger.warn(\n {\n error,\n attempt: attempts,\n maxAttempts: maxAttempts ?? 'unlimited',\n retryDelayMs: this.options.connectionRetryDelay,\n },\n 'Connection attempt failed, retrying...',\n )\n await this.sleep(this.options.connectionRetryDelay)\n }\n }\n }\n\n private handleChannelFailure(): void {\n if (this.connected) {\n this.connected = false\n this.reconnectWithRetry()\n }\n }\n\n /**\n * Returns whether the client currently has an active connection and channel.\n */\n isConnected(): boolean {\n return this.connected\n }\n\n /**\n * Publishes a JSON message to a topic exchange with publisher confirms.\n * Retries with exponential backoff (capped at 60 s), forcing a reconnect\n * on each failure. Throws after `publishMaxAttempts` exhausted.\n */\n async publish(\n exchange: string,\n routingKey: string,\n message: RabbitMQMessage,\n options?: PublishOptions,\n ): Promise<void> {\n let attempts = 0\n const maxAttempts = options?.maxAttempts ?? this.options.publishMaxAttempts\n const baseDelay = this.options.connectionRetryDelay\n const content = Buffer.from(JSON.stringify(message))\n\n while (attempts < maxAttempts) {\n try {\n if (!this.connected) {\n await this.reconnectWithRetry()\n }\n\n if (!this.channel) {\n throw new Error('Channel not available')\n }\n\n if (!this.assertedExchanges.has(exchange)) {\n await this.channel.assertExchange(exchange, 'topic', { durable: true })\n this.assertedExchanges.add(exchange)\n }\n\n this.channel.publish(exchange, routingKey, content, {\n persistent: true,\n headers: options?.headers,\n correlationId: options?.correlationId,\n messageId: options?.messageId,\n expiration: options?.expiration,\n })\n\n await this.channel.waitForConfirms()\n\n if (attempts > 0) {\n this.logger.info({ exchange, routingKey, messageSize: content.length, attempts }, 'Published message after retries')\n } else {\n this.logger.info({ exchange, routingKey, messageSize: content.length }, 'Published message')\n }\n this.logger.debug({ exchange, routingKey, payload: message }, 'Published message payload')\n\n this.callHook(this.hooks.onPublish, { exchange, routingKey, attempts: attempts + 1 })\n\n return\n } catch (error) {\n attempts++\n this.connected = false\n\n if (attempts >= maxAttempts) {\n this.logger.error(\n { error, exchange, routingKey, attempts, maxAttempts },\n 'Publish failed after max attempts',\n )\n throw new Error(\n `Failed to publish to ${exchange}/${routingKey} after ${attempts} attempts: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n\n const retryDelay = Math.min(\n baseDelay * Math.pow(2, attempts - 1),\n MAX_PUBLISH_RETRY_DELAY_MS,\n )\n\n this.logger.warn(\n { error, exchange, routingKey, attempt: attempts, maxAttempts, retryDelayMs: retryDelay },\n 'Publish attempt failed, retrying',\n )\n\n await this.sleep(retryDelay)\n }\n }\n }\n\n /**\n * Gracefully shuts down the client. Waits up to `closeTimeout` ms for\n * in-flight message handlers to finish before closing the channel and\n * connection. Pass `false` to preserve subscriptions for a later\n * `init()` / reconnect cycle.\n */\n async close(clearSubscriptions = true): Promise<void> {\n try {\n if (this.inflightCount > 0) {\n this.logger.info({ inflightCount: this.inflightCount }, 'Waiting for in-flight messages to drain')\n await this.waitForDrain(this.options.closeTimeout)\n }\n await this.channel?.close()\n await this.connection?.close()\n this.connection = null\n this.channel = null\n this.connected = false\n this.initializationPromise = null\n this.reconnectionPromise = null\n this.assertedExchanges.clear()\n this.consumerTags.clear()\n if (clearSubscriptions) {\n this.subscriptions = []\n }\n this.logger.info('Connection closed')\n } catch (error) {\n this.logger.error({ error }, 'Error closing connection')\n throw error\n }\n }\n\n private async reconnectWithRetry(): Promise<void> {\n if (this.reconnectionPromise) {\n return this.reconnectionPromise\n }\n this.connected = false\n this.logger.info('Starting reconnection...')\n this.reconnectionPromise = this.doReconnect()\n this.reconnectionPromise.catch(() => undefined)\n try {\n await this.reconnectionPromise\n } finally {\n this.reconnectionPromise = null\n }\n }\n\n private async doReconnect(): Promise<void> {\n await this.doConnect()\n await this.resubscribeAll()\n }\n\n private async resubscribeAll(): Promise<void> {\n if (this.subscriptions.length === 0) {\n return\n }\n this.logger.info({ count: this.subscriptions.length }, 'Re-establishing subscriptions')\n const subs = [...this.subscriptions]\n const results = await Promise.allSettled(\n subs.map(async (sub) => {\n await this.setupSubscription(sub)\n return sub.queue\n }),\n )\n const succeeded: string[] = []\n const failed: string[] = []\n results.forEach((result, index) => {\n if (result.status === 'fulfilled') {\n succeeded.push(result.value)\n } else {\n const queue = subs[index].queue\n failed.push(queue)\n this.logger.error({ error: result.reason, queue }, 'Failed to re-subscribe to queue')\n }\n })\n if (succeeded.length > 0) {\n this.logger.info({ count: succeeded.length, queues: succeeded }, 'Successfully re-subscribed to queues')\n }\n if (failed.length > 0) {\n this.logger.warn({ count: failed.length, queues: failed }, 'Some subscriptions failed to restore')\n }\n this.callHook(this.hooks.onReconnect, { subscriptionsRestored: succeeded.length, subscriptionsFailed: failed.length })\n }\n\n /**\n * Subscribes to a queue with automatic DLQ infrastructure setup.\n *\n * Pass `options.queueArguments` to override the default quorum-queue\n * arguments (merged with the DLQ wiring defaults).\n */\n async subscribe(\n exchange: string,\n routingKey: string,\n queue: string,\n handler: RabbitMQMessageHandler,\n options?: SubscribeOptions,\n ): Promise<void> {\n if (!this.connected || !this.channel) {\n throw new Error('RabbitMQ client not connected. Call init() first.')\n }\n const sub: RabbitMQSubscription = { exchange, routingKey, queue, handler, options }\n const existingIndex = this.subscriptions.findIndex((s) => s.queue === queue)\n if (existingIndex === -1) {\n this.subscriptions.push(sub)\n } else {\n this.subscriptions[existingIndex] = sub\n }\n await this.setupSubscription(sub)\n }\n\n /**\n * Cancels a queue subscription and removes it from the restoration list.\n */\n async unsubscribe(queue: string): Promise<void> {\n const tag = this.consumerTags.get(queue)\n if (tag && this.channel) {\n await this.channel.cancel(tag)\n }\n this.consumerTags.delete(queue)\n this.subscriptions = this.subscriptions.filter((s) => s.queue !== queue)\n this.logger.info({ queue }, 'Unsubscribed from queue')\n }\n\n private async setupSubscription(sub: RabbitMQSubscription): Promise<void> {\n if (!this.channel) {\n throw new Error('Channel not available')\n }\n const { exchange, routingKey, queue, handler, options } = sub\n const dlxExchange = `${exchange}.dlx`\n const dlqQueue = `${queue}.dlq`\n const dlqRoutingKey = `${routingKey}.dead`\n\n await this.channel.assertExchange(dlxExchange, 'topic', { durable: true })\n await this.channel.assertQueue(dlqQueue, { durable: true })\n await this.channel.bindQueue(dlqQueue, dlxExchange, dlqRoutingKey)\n\n if (!this.assertedExchanges.has(exchange)) {\n await this.channel.assertExchange(exchange, 'topic', { durable: true })\n this.assertedExchanges.add(exchange)\n }\n\n const queueType = options?.queueArguments?.['x-queue-type'] ?? 'quorum'\n const queueArgs: Record<string, unknown> = {\n 'x-queue-type': queueType,\n 'x-overflow': 'reject-publish',\n }\n // at-least-once DLQ strategy is only supported by quorum queues\n if (queueType === 'quorum') {\n queueArgs['x-dead-letter-strategy'] = 'at-least-once'\n }\n\n await this.channel.assertQueue(queue, {\n durable: true,\n deadLetterExchange: dlxExchange,\n deadLetterRoutingKey: dlqRoutingKey,\n arguments: { ...queueArgs, ...options?.queueArguments },\n })\n\n await this.channel.bindQueue(queue, exchange, routingKey)\n const { consumerTag } = await this.channel.consume(\n queue,\n (message) => {\n if (message) {\n this.handleWithRetry(message, handler).catch((error) => {\n this.logger.error({ error }, 'Unhandled error in message handler')\n })\n }\n },\n { noAck: false },\n )\n this.consumerTags.set(queue, consumerTag)\n this.logger.info({ exchange, routingKey, queue }, 'Subscribed to queue')\n }\n\n private async handleWithRetry(\n message: amqp.ConsumeMessage,\n handler: RabbitMQMessageHandler,\n ): Promise<void> {\n // Capture the channel reference so ack/nack always targets the channel\n // that delivered this message, even if a reconnection swaps this.channel.\n const channel = this.channel\n if (!channel) {\n this.logger.warn('Cannot process message -- channel unavailable')\n return\n }\n this.inflightCount++\n try {\n const startTime = Date.now()\n let attempts = 0\n const routingKey = message.fields.routingKey\n const exchange = message.fields.exchange\n\n let content: RabbitMQMessage\n try {\n content = JSON.parse(message.content.toString())\n } catch (parseError) {\n const rawContent = message.content.toString()\n const rawPreview = rawContent.substring(0, 100)\n this.logger.error(\n {\n error: parseError,\n exchange,\n routingKey,\n rawContentPreview: rawPreview + (rawContent.length > 100 ? '...' : ''),\n },\n 'Failed to parse message JSON, sending to DLQ',\n )\n channel.nack(message, false, false)\n this.callHook(this.hooks.onMessageDlq, { exchange, routingKey, duration: 0, reason: 'invalid_json' })\n return\n }\n\n this.logger.debug({ exchange, routingKey, payload: content }, 'Message received, processing')\n\n while (attempts < this.options.maxRetries) {\n try {\n await handler(content)\n const duration = Date.now() - startTime\n this.logger.info(\n { exchange, routingKey, duration, attempts: attempts + 1 },\n 'Message processed successfully',\n )\n channel.ack(message)\n this.callHook(this.hooks.onMessageProcessed, { exchange, routingKey, duration, attempts: attempts + 1 })\n return\n } catch (error) {\n attempts++\n this.logger.error(\n {\n error: error instanceof Error ? error.message : error,\n stack: error instanceof Error ? error.stack : undefined,\n exchange,\n routingKey,\n attempt: attempts,\n maxRetries: this.options.maxRetries,\n },\n 'Handler failed',\n )\n if (attempts < this.options.maxRetries) {\n await this.sleep(this.options.retryDelay)\n }\n }\n }\n\n const duration = Date.now() - startTime\n this.logger.error(\n { exchange, routingKey, maxRetries: this.options.maxRetries, duration },\n 'Message failed after max retries, sending to DLQ',\n )\n channel.nack(message, false, false)\n this.callHook(this.hooks.onMessageDlq, { exchange, routingKey, duration, reason: 'max_retries_exhausted' })\n } finally {\n this.inflightCount--\n if (this.inflightCount === 0 && this.drainResolve) {\n this.drainResolve()\n }\n }\n }\n\n /**\n * Lightweight liveness probe: creates and immediately deletes a temporary\n * exclusive queue. Returns `false` when disconnected or on broker error.\n */\n async checkHealth(): Promise<boolean> {\n if (!this.connected || !this.channel) {\n return false\n }\n try {\n const { queue } = await this.channel.assertQueue('', {\n exclusive: true,\n autoDelete: true,\n })\n await this.channel.deleteQueue(queue)\n return true\n } catch (error) {\n this.logger.warn({ error }, 'Health check failed')\n return false\n }\n }\n\n private waitForDrain(timeout: number): Promise<void> {\n if (this.inflightCount === 0) return Promise.resolve()\n return new Promise<void>((resolve) => {\n const timer = setTimeout(() => {\n this.logger.warn(\n { inflightCount: this.inflightCount },\n 'Close timeout reached with messages still in flight',\n )\n this.drainResolve = null\n resolve()\n }, timeout)\n this.drainResolve = () => {\n clearTimeout(timer)\n this.drainResolve = null\n resolve()\n }\n })\n }\n\n /** Invokes a hook callback, swallowing errors so hooks never break message flow. */\n private callHook<T>(hook: ((info: T) => void) | undefined, info: T): void {\n try { hook?.(info) } catch (error) { this.logger.debug({ error }, 'Observability hook error') }\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms))\n }\n}\n","import pino, { type Logger } from 'pino'\n\n/**\n * Creates a child pino logger for the RabbitMQ client.\n *\n * If a parent logger is provided, the child inherits its configuration\n * (level, transports, etc.) for unified log output. Otherwise, a new\n * root logger is created.\n */\nexport const createLogger = (parent?: Logger): Logger => {\n if (parent) {\n return parent.child({ service: 'rabbitmq-client' })\n }\n return pino({ name: 'rabbitmq-client' })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAAiB;;;ACAjB,kBAAkC;AAS3B,IAAM,eAAe,CAAC,WAA4B;AACvD,MAAI,QAAQ;AACV,WAAO,OAAO,MAAM,EAAE,SAAS,kBAAkB,CAAC;AAAA,EACpD;AACA,aAAO,YAAAA,SAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC;;;ADDA,IAAM,mBAAmB;AACzB,IAAM,6BAA6B;AAEnC,IAAM,WAAW;AAAA,EACf,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,sBAAsB;AAAA,EACtB,iBAAiB;AAAA,EACjB,oBAAoB;AAAA,EACpB,UAAU;AAAA,EACV,cAAc;AAChB;AAeO,IAAM,iBAAN,MAAqB;AAAA,EAClB,aAAuC;AAAA,EACvC,UAAsC;AAAA,EACtC,YAAY;AAAA,EACZ,gBAAwC,CAAC;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACT,wBAA8C;AAAA,EAC9C,sBAA4C;AAAA,EAC5C,oBAAoB,oBAAI,IAAY;AAAA,EACpC,eAAe,oBAAI,IAAoB;AAAA,EACvC,gBAAgB;AAAA,EAChB,eAAoC;AAAA,EAE5C,YAAY,SAAgC;AAC1C,SAAK,UAAU;AAAA,MACb,KAAK,QAAQ;AAAA,MACb,YAAY,QAAQ,cAAc,SAAS;AAAA,MAC3C,YAAY,QAAQ,cAAc,SAAS;AAAA,MAC3C,sBAAsB,QAAQ,wBAAwB,SAAS;AAAA,MAC/D,iBAAiB,QAAQ,mBAAmB,SAAS;AAAA,MACrD,oBAAoB,QAAQ,sBAAsB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,27 +5,27 @@ import { Logger } from 'pino';
|
|
|
5
5
|
* Use these to wire metrics, tracing, or custom logging.
|
|
6
6
|
*/
|
|
7
7
|
interface RabbitMQHooks {
|
|
8
|
-
/** Called after
|
|
8
|
+
/** Called after the broker confirms a published message */
|
|
9
9
|
onPublish?: (info: {
|
|
10
10
|
exchange: string;
|
|
11
11
|
routingKey: string;
|
|
12
12
|
attempts: number;
|
|
13
13
|
}) => void;
|
|
14
|
-
/** Called after a message handler
|
|
14
|
+
/** Called after a message handler returns successfully (duration includes retries) */
|
|
15
15
|
onMessageProcessed?: (info: {
|
|
16
16
|
exchange: string;
|
|
17
17
|
routingKey: string;
|
|
18
18
|
duration: number;
|
|
19
19
|
attempts: number;
|
|
20
20
|
}) => void;
|
|
21
|
-
/** Called when a message is
|
|
21
|
+
/** Called when a message is nacked to the dead-letter queue */
|
|
22
22
|
onMessageDlq?: (info: {
|
|
23
23
|
exchange: string;
|
|
24
24
|
routingKey: string;
|
|
25
25
|
duration: number;
|
|
26
26
|
reason: 'invalid_json' | 'max_retries_exhausted';
|
|
27
27
|
}) => void;
|
|
28
|
-
/** Called after
|
|
28
|
+
/** Called after reconnection completes and subscriptions are re-established */
|
|
29
29
|
onReconnect?: (info: {
|
|
30
30
|
subscriptionsRestored: number;
|
|
31
31
|
subscriptionsFailed: number;
|
|
@@ -63,6 +63,21 @@ interface RabbitMQClientOptions {
|
|
|
63
63
|
/** Observability hooks for metrics and monitoring */
|
|
64
64
|
hooks?: RabbitMQHooks;
|
|
65
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Options for the `publish()` method.
|
|
68
|
+
*/
|
|
69
|
+
interface PublishOptions {
|
|
70
|
+
/** Max publish attempts with backoff (overrides client default) */
|
|
71
|
+
maxAttempts?: number;
|
|
72
|
+
/** Custom message headers for tracing and metadata */
|
|
73
|
+
headers?: Record<string, unknown>;
|
|
74
|
+
/** Correlation ID for request-reply patterns */
|
|
75
|
+
correlationId?: string;
|
|
76
|
+
/** Unique message identifier */
|
|
77
|
+
messageId?: string;
|
|
78
|
+
/** Per-message TTL in milliseconds (as string per AMQP spec) */
|
|
79
|
+
expiration?: string;
|
|
80
|
+
}
|
|
66
81
|
/** JSON-serializable message payload */
|
|
67
82
|
type RabbitMQMessage = Record<string, unknown>;
|
|
68
83
|
/** Async handler function for consumed messages */
|
|
@@ -121,9 +136,7 @@ declare class RabbitMQClient {
|
|
|
121
136
|
* Retries with exponential backoff (capped at 60 s), forcing a reconnect
|
|
122
137
|
* on each failure. Throws after `publishMaxAttempts` exhausted.
|
|
123
138
|
*/
|
|
124
|
-
publish(exchange: string, routingKey: string, message: RabbitMQMessage, options?:
|
|
125
|
-
maxAttempts?: number;
|
|
126
|
-
}): Promise<void>;
|
|
139
|
+
publish(exchange: string, routingKey: string, message: RabbitMQMessage, options?: PublishOptions): Promise<void>;
|
|
127
140
|
/**
|
|
128
141
|
* Gracefully shuts down the client. Waits up to `closeTimeout` ms for
|
|
129
142
|
* in-flight message handlers to finish before closing the channel and
|
|
@@ -158,4 +171,4 @@ declare class RabbitMQClient {
|
|
|
158
171
|
private sleep;
|
|
159
172
|
}
|
|
160
173
|
|
|
161
|
-
export { RabbitMQClient, type RabbitMQClientOptions, type RabbitMQHooks, type RabbitMQMessage, type RabbitMQMessageHandler, type RabbitMQSubscription, type SubscribeOptions };
|
|
174
|
+
export { type PublishOptions, RabbitMQClient, type RabbitMQClientOptions, type RabbitMQHooks, type RabbitMQMessage, type RabbitMQMessageHandler, type RabbitMQSubscription, type SubscribeOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,27 +5,27 @@ import { Logger } from 'pino';
|
|
|
5
5
|
* Use these to wire metrics, tracing, or custom logging.
|
|
6
6
|
*/
|
|
7
7
|
interface RabbitMQHooks {
|
|
8
|
-
/** Called after
|
|
8
|
+
/** Called after the broker confirms a published message */
|
|
9
9
|
onPublish?: (info: {
|
|
10
10
|
exchange: string;
|
|
11
11
|
routingKey: string;
|
|
12
12
|
attempts: number;
|
|
13
13
|
}) => void;
|
|
14
|
-
/** Called after a message handler
|
|
14
|
+
/** Called after a message handler returns successfully (duration includes retries) */
|
|
15
15
|
onMessageProcessed?: (info: {
|
|
16
16
|
exchange: string;
|
|
17
17
|
routingKey: string;
|
|
18
18
|
duration: number;
|
|
19
19
|
attempts: number;
|
|
20
20
|
}) => void;
|
|
21
|
-
/** Called when a message is
|
|
21
|
+
/** Called when a message is nacked to the dead-letter queue */
|
|
22
22
|
onMessageDlq?: (info: {
|
|
23
23
|
exchange: string;
|
|
24
24
|
routingKey: string;
|
|
25
25
|
duration: number;
|
|
26
26
|
reason: 'invalid_json' | 'max_retries_exhausted';
|
|
27
27
|
}) => void;
|
|
28
|
-
/** Called after
|
|
28
|
+
/** Called after reconnection completes and subscriptions are re-established */
|
|
29
29
|
onReconnect?: (info: {
|
|
30
30
|
subscriptionsRestored: number;
|
|
31
31
|
subscriptionsFailed: number;
|
|
@@ -63,6 +63,21 @@ interface RabbitMQClientOptions {
|
|
|
63
63
|
/** Observability hooks for metrics and monitoring */
|
|
64
64
|
hooks?: RabbitMQHooks;
|
|
65
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Options for the `publish()` method.
|
|
68
|
+
*/
|
|
69
|
+
interface PublishOptions {
|
|
70
|
+
/** Max publish attempts with backoff (overrides client default) */
|
|
71
|
+
maxAttempts?: number;
|
|
72
|
+
/** Custom message headers for tracing and metadata */
|
|
73
|
+
headers?: Record<string, unknown>;
|
|
74
|
+
/** Correlation ID for request-reply patterns */
|
|
75
|
+
correlationId?: string;
|
|
76
|
+
/** Unique message identifier */
|
|
77
|
+
messageId?: string;
|
|
78
|
+
/** Per-message TTL in milliseconds (as string per AMQP spec) */
|
|
79
|
+
expiration?: string;
|
|
80
|
+
}
|
|
66
81
|
/** JSON-serializable message payload */
|
|
67
82
|
type RabbitMQMessage = Record<string, unknown>;
|
|
68
83
|
/** Async handler function for consumed messages */
|
|
@@ -121,9 +136,7 @@ declare class RabbitMQClient {
|
|
|
121
136
|
* Retries with exponential backoff (capped at 60 s), forcing a reconnect
|
|
122
137
|
* on each failure. Throws after `publishMaxAttempts` exhausted.
|
|
123
138
|
*/
|
|
124
|
-
publish(exchange: string, routingKey: string, message: RabbitMQMessage, options?:
|
|
125
|
-
maxAttempts?: number;
|
|
126
|
-
}): Promise<void>;
|
|
139
|
+
publish(exchange: string, routingKey: string, message: RabbitMQMessage, options?: PublishOptions): Promise<void>;
|
|
127
140
|
/**
|
|
128
141
|
* Gracefully shuts down the client. Waits up to `closeTimeout` ms for
|
|
129
142
|
* in-flight message handlers to finish before closing the channel and
|
|
@@ -158,4 +171,4 @@ declare class RabbitMQClient {
|
|
|
158
171
|
private sleep;
|
|
159
172
|
}
|
|
160
173
|
|
|
161
|
-
export { RabbitMQClient, type RabbitMQClientOptions, type RabbitMQHooks, type RabbitMQMessage, type RabbitMQMessageHandler, type RabbitMQSubscription, type SubscribeOptions };
|
|
174
|
+
export { type PublishOptions, RabbitMQClient, type RabbitMQClientOptions, type RabbitMQHooks, type RabbitMQMessage, type RabbitMQMessageHandler, type RabbitMQSubscription, type SubscribeOptions };
|
package/dist/index.js
CHANGED
|
@@ -158,7 +158,11 @@ var RabbitMQClient = class {
|
|
|
158
158
|
this.assertedExchanges.add(exchange);
|
|
159
159
|
}
|
|
160
160
|
this.channel.publish(exchange, routingKey, content, {
|
|
161
|
-
persistent: true
|
|
161
|
+
persistent: true,
|
|
162
|
+
headers: options?.headers,
|
|
163
|
+
correlationId: options?.correlationId,
|
|
164
|
+
messageId: options?.messageId,
|
|
165
|
+
expiration: options?.expiration
|
|
162
166
|
});
|
|
163
167
|
await this.channel.waitForConfirms();
|
|
164
168
|
if (attempts > 0) {
|
|
@@ -318,23 +322,28 @@ var RabbitMQClient = class {
|
|
|
318
322
|
await this.channel.assertExchange(exchange, "topic", { durable: true });
|
|
319
323
|
this.assertedExchanges.add(exchange);
|
|
320
324
|
}
|
|
325
|
+
const queueType = options?.queueArguments?.["x-queue-type"] ?? "quorum";
|
|
326
|
+
const queueArgs = {
|
|
327
|
+
"x-queue-type": queueType,
|
|
328
|
+
"x-overflow": "reject-publish"
|
|
329
|
+
};
|
|
330
|
+
if (queueType === "quorum") {
|
|
331
|
+
queueArgs["x-dead-letter-strategy"] = "at-least-once";
|
|
332
|
+
}
|
|
321
333
|
await this.channel.assertQueue(queue, {
|
|
322
334
|
durable: true,
|
|
323
335
|
deadLetterExchange: dlxExchange,
|
|
324
336
|
deadLetterRoutingKey: dlqRoutingKey,
|
|
325
|
-
arguments: {
|
|
326
|
-
"x-dead-letter-strategy": "at-least-once",
|
|
327
|
-
"x-queue-type": "quorum",
|
|
328
|
-
"x-overflow": "reject-publish",
|
|
329
|
-
...options?.queueArguments
|
|
330
|
-
}
|
|
337
|
+
arguments: { ...queueArgs, ...options?.queueArguments }
|
|
331
338
|
});
|
|
332
339
|
await this.channel.bindQueue(queue, exchange, routingKey);
|
|
333
340
|
const { consumerTag } = await this.channel.consume(
|
|
334
341
|
queue,
|
|
335
342
|
(message) => {
|
|
336
343
|
if (message) {
|
|
337
|
-
this.handleWithRetry(message, handler)
|
|
344
|
+
this.handleWithRetry(message, handler).catch((error) => {
|
|
345
|
+
this.logger.error({ error }, "Unhandled error in message handler");
|
|
346
|
+
});
|
|
338
347
|
}
|
|
339
348
|
},
|
|
340
349
|
{ noAck: false }
|
|
@@ -459,7 +468,8 @@ var RabbitMQClient = class {
|
|
|
459
468
|
callHook(hook, info) {
|
|
460
469
|
try {
|
|
461
470
|
hook?.(info);
|
|
462
|
-
} catch {
|
|
471
|
+
} catch (error) {
|
|
472
|
+
this.logger.debug({ error }, "Observability hook error");
|
|
463
473
|
}
|
|
464
474
|
}
|
|
465
475
|
sleep(ms) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts","../src/logger.ts"],"sourcesContent":["import amqp from 'amqplib'\nimport type {\n RabbitMQClientOptions,\n RabbitMQHooks,\n RabbitMQMessage,\n RabbitMQMessageHandler,\n RabbitMQSubscription,\n SubscribeOptions,\n} from './types.js'\nimport { createLogger } from './logger.js'\nimport type { Logger } from 'pino'\n\nconst DEFAULT_PREFETCH = 10\nconst MAX_PUBLISH_RETRY_DELAY_MS = 60_000\n\nconst DEFAULTS = {\n maxRetries: 3,\n retryDelay: 1000,\n connectionRetryDelay: 5000,\n initMaxAttempts: 5,\n publishMaxAttempts: 5,\n prefetch: DEFAULT_PREFETCH,\n closeTimeout: 5000,\n} as const\n\n/**\n * Production-grade RabbitMQ client with confirm channels, automatic DLQ\n * infrastructure, reconnection with subscription restoration, and\n * exponential-backoff publishing.\n *\n * @example\n * ```ts\n * const client = new RabbitMQClient({ url: 'amqp://localhost' })\n * await client.init()\n * await client.publish('events', 'user.created', { userId: '123' })\n * await client.subscribe('events', 'user.created', 'user-service', handler)\n * ```\n */\nexport class RabbitMQClient {\n private connection: amqp.ChannelModel | null = null\n private channel: amqp.ConfirmChannel | null = null\n private connected = false\n private subscriptions: RabbitMQSubscription[] = []\n private readonly options: Required<Omit<RabbitMQClientOptions, 'logger' | 'hooks'>>\n private readonly logger: Logger\n private readonly hooks: RabbitMQHooks\n private initializationPromise: Promise<void> | null = null\n private reconnectionPromise: Promise<void> | null = null\n private assertedExchanges = new Set<string>()\n private consumerTags = new Map<string, string>()\n private inflightCount = 0\n private drainResolve: (() => void) | null = null\n\n constructor(options: RabbitMQClientOptions) {\n this.options = {\n url: options.url,\n maxRetries: options.maxRetries ?? DEFAULTS.maxRetries,\n retryDelay: options.retryDelay ?? DEFAULTS.retryDelay,\n connectionRetryDelay: options.connectionRetryDelay ?? DEFAULTS.connectionRetryDelay,\n initMaxAttempts: options.initMaxAttempts ?? DEFAULTS.initMaxAttempts,\n publishMaxAttempts: options.publishMaxAttempts ?? DEFAULTS.publishMaxAttempts,\n prefetch: options.prefetch ?? DEFAULTS.prefetch,\n closeTimeout: options.closeTimeout ?? DEFAULTS.closeTimeout,\n }\n this.logger = createLogger(options.logger)\n this.hooks = options.hooks ?? {}\n }\n\n /**\n * Opens a connection and creates a confirm channel. Retries up to\n * `initMaxAttempts` times, then throws. Idempotent and safe to call\n * concurrently — duplicate calls share the same in-flight promise.\n */\n async init(): Promise<void> {\n if (this.connection && this.connected) {\n return\n }\n if (this.initializationPromise) {\n return this.initializationPromise\n }\n // Attach a no-op catch to prevent Node from briefly treating this as an\n // unhandled rejection before the await below registers its own handler.\n this.initializationPromise = this.doConnect(this.options.initMaxAttempts)\n this.initializationPromise.catch(() => undefined)\n try {\n await this.initializationPromise\n } finally {\n this.initializationPromise = null\n }\n }\n\n private async doConnect(maxAttempts?: number): Promise<void> {\n this.assertedExchanges.clear()\n this.consumerTags.clear()\n let attempts = 0\n while (!this.connected) {\n try {\n this.connection = await amqp.connect(this.options.url)\n this.logger.info('Connected to server')\n this.channel = await this.connection.createConfirmChannel()\n this.logger.info('Confirm channel created')\n await this.channel.prefetch(this.options.prefetch)\n this.logger.info({ prefetch: this.options.prefetch }, 'Channel prefetch set')\n\n this.connection.on('error', (error: Error) => {\n this.connected = false\n this.logger.error({ error }, 'Connection error')\n })\n this.connection.on('close', () => {\n this.connected = false\n this.logger.warn('Connection closed')\n this.reconnectWithRetry()\n })\n this.channel.on('error', (error: Error) => {\n this.logger.error({ error }, 'Channel error')\n this.handleChannelFailure()\n })\n this.channel.on('close', () => {\n this.logger.warn('Channel closed')\n this.handleChannelFailure()\n })\n\n this.connected = true\n this.logger.info('Client initialized successfully')\n } catch (error) {\n attempts++\n this.connected = false\n if (maxAttempts !== undefined && attempts >= maxAttempts) {\n this.logger.error({ error, attempts, maxAttempts }, 'Connection failed after maximum attempts')\n throw new Error(\n `Failed to connect to RabbitMQ after ${attempts} attempts. ` +\n 'Check RABBITMQ_URL configuration and RabbitMQ server availability.',\n )\n }\n this.logger.warn(\n {\n error,\n attempt: attempts,\n maxAttempts: maxAttempts ?? 'unlimited',\n retryDelayMs: this.options.connectionRetryDelay,\n },\n 'Connection attempt failed, retrying...',\n )\n await this.sleep(this.options.connectionRetryDelay)\n }\n }\n }\n\n private handleChannelFailure(): void {\n if (this.connected) {\n this.connected = false\n this.reconnectWithRetry()\n }\n }\n\n /**\n * Returns whether the client currently has an active connection and channel.\n */\n isConnected(): boolean {\n return this.connected\n }\n\n /**\n * Publishes a JSON message to a topic exchange with publisher confirms.\n * Retries with exponential backoff (capped at 60 s), forcing a reconnect\n * on each failure. Throws after `publishMaxAttempts` exhausted.\n */\n async publish(\n exchange: string,\n routingKey: string,\n message: RabbitMQMessage,\n options?: { maxAttempts?: number },\n ): Promise<void> {\n let attempts = 0\n const maxAttempts = options?.maxAttempts ?? this.options.publishMaxAttempts\n const baseDelay = this.options.connectionRetryDelay\n const content = Buffer.from(JSON.stringify(message))\n\n while (attempts < maxAttempts) {\n try {\n if (!this.connected) {\n await this.reconnectWithRetry()\n }\n\n if (!this.channel) {\n throw new Error('Channel not available')\n }\n\n if (!this.assertedExchanges.has(exchange)) {\n await this.channel.assertExchange(exchange, 'topic', { durable: true })\n this.assertedExchanges.add(exchange)\n }\n\n this.channel.publish(exchange, routingKey, content, {\n persistent: true,\n })\n\n await this.channel.waitForConfirms()\n\n if (attempts > 0) {\n this.logger.info({ exchange, routingKey, messageSize: content.length, attempts }, 'Published message after retries')\n } else {\n this.logger.info({ exchange, routingKey, messageSize: content.length }, 'Published message')\n }\n this.logger.debug({ exchange, routingKey, payload: message }, 'Published message payload')\n\n this.callHook(this.hooks.onPublish, { exchange, routingKey, attempts: attempts + 1 })\n\n return\n } catch (error) {\n attempts++\n this.connected = false\n\n if (attempts >= maxAttempts) {\n this.logger.error(\n { error, exchange, routingKey, attempts, maxAttempts },\n 'Publish failed after max attempts',\n )\n throw new Error(\n `Failed to publish to ${exchange}/${routingKey} after ${attempts} attempts: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n\n const retryDelay = Math.min(\n baseDelay * Math.pow(2, attempts - 1),\n MAX_PUBLISH_RETRY_DELAY_MS,\n )\n\n this.logger.warn(\n { error, exchange, routingKey, attempt: attempts, maxAttempts, retryDelayMs: retryDelay },\n 'Publish attempt failed, retrying',\n )\n\n await this.sleep(retryDelay)\n }\n }\n }\n\n /**\n * Gracefully shuts down the client. Waits up to `closeTimeout` ms for\n * in-flight message handlers to finish before closing the channel and\n * connection. Pass `false` to preserve subscriptions for a later\n * `init()` / reconnect cycle.\n */\n async close(clearSubscriptions = true): Promise<void> {\n try {\n if (this.inflightCount > 0) {\n this.logger.info({ inflightCount: this.inflightCount }, 'Waiting for in-flight messages to drain')\n await this.waitForDrain(this.options.closeTimeout)\n }\n await this.channel?.close()\n await this.connection?.close()\n this.connection = null\n this.channel = null\n this.connected = false\n this.initializationPromise = null\n this.reconnectionPromise = null\n this.assertedExchanges.clear()\n this.consumerTags.clear()\n if (clearSubscriptions) {\n this.subscriptions = []\n }\n this.logger.info('Connection closed')\n } catch (error) {\n this.logger.error({ error }, 'Error closing connection')\n throw error\n }\n }\n\n private async reconnectWithRetry(): Promise<void> {\n if (this.reconnectionPromise) {\n return this.reconnectionPromise\n }\n this.connected = false\n this.logger.info('Starting reconnection...')\n this.reconnectionPromise = this.doReconnect()\n this.reconnectionPromise.catch(() => undefined)\n try {\n await this.reconnectionPromise\n } finally {\n this.reconnectionPromise = null\n }\n }\n\n private async doReconnect(): Promise<void> {\n await this.doConnect()\n await this.resubscribeAll()\n }\n\n private async resubscribeAll(): Promise<void> {\n if (this.subscriptions.length === 0) {\n return\n }\n this.logger.info({ count: this.subscriptions.length }, 'Re-establishing subscriptions')\n const subs = [...this.subscriptions]\n const results = await Promise.allSettled(\n subs.map(async (sub) => {\n await this.setupSubscription(sub)\n return sub.queue\n }),\n )\n const succeeded: string[] = []\n const failed: string[] = []\n results.forEach((result, index) => {\n if (result.status === 'fulfilled') {\n succeeded.push(result.value)\n } else {\n const queue = subs[index].queue\n failed.push(queue)\n this.logger.error({ error: result.reason, queue }, 'Failed to re-subscribe to queue')\n }\n })\n if (succeeded.length > 0) {\n this.logger.info({ count: succeeded.length, queues: succeeded }, 'Successfully re-subscribed to queues')\n }\n if (failed.length > 0) {\n this.logger.warn({ count: failed.length, queues: failed }, 'Some subscriptions failed to restore')\n }\n this.callHook(this.hooks.onReconnect, { subscriptionsRestored: succeeded.length, subscriptionsFailed: failed.length })\n }\n\n /**\n * Subscribes to a queue with automatic DLQ infrastructure setup.\n *\n * Pass `options.queueArguments` to override the default quorum-queue\n * arguments (merged with the DLQ wiring defaults).\n */\n async subscribe(\n exchange: string,\n routingKey: string,\n queue: string,\n handler: RabbitMQMessageHandler,\n options?: SubscribeOptions,\n ): Promise<void> {\n if (!this.connected || !this.channel) {\n throw new Error('RabbitMQ client not connected. Call init() first.')\n }\n const sub: RabbitMQSubscription = { exchange, routingKey, queue, handler, options }\n const existingIndex = this.subscriptions.findIndex((s) => s.queue === queue)\n if (existingIndex === -1) {\n this.subscriptions.push(sub)\n } else {\n this.subscriptions[existingIndex] = sub\n }\n await this.setupSubscription(sub)\n }\n\n /**\n * Cancels a queue subscription and removes it from the restoration list.\n */\n async unsubscribe(queue: string): Promise<void> {\n const tag = this.consumerTags.get(queue)\n if (tag && this.channel) {\n await this.channel.cancel(tag)\n }\n this.consumerTags.delete(queue)\n this.subscriptions = this.subscriptions.filter((s) => s.queue !== queue)\n this.logger.info({ queue }, 'Unsubscribed from queue')\n }\n\n private async setupSubscription(sub: RabbitMQSubscription): Promise<void> {\n if (!this.channel) {\n throw new Error('Channel not available')\n }\n const { exchange, routingKey, queue, handler, options } = sub\n const dlxExchange = `${exchange}.dlx`\n const dlqQueue = `${queue}.dlq`\n const dlqRoutingKey = `${routingKey}.dead`\n\n await this.channel.assertExchange(dlxExchange, 'topic', { durable: true })\n await this.channel.assertQueue(dlqQueue, { durable: true })\n await this.channel.bindQueue(dlqQueue, dlxExchange, dlqRoutingKey)\n\n if (!this.assertedExchanges.has(exchange)) {\n await this.channel.assertExchange(exchange, 'topic', { durable: true })\n this.assertedExchanges.add(exchange)\n }\n\n await this.channel.assertQueue(queue, {\n durable: true,\n deadLetterExchange: dlxExchange,\n deadLetterRoutingKey: dlqRoutingKey,\n arguments: {\n 'x-dead-letter-strategy': 'at-least-once',\n 'x-queue-type': 'quorum',\n 'x-overflow': 'reject-publish',\n ...options?.queueArguments,\n },\n })\n\n await this.channel.bindQueue(queue, exchange, routingKey)\n const { consumerTag } = await this.channel.consume(\n queue,\n (message) => {\n if (message) {\n this.handleWithRetry(message, handler)\n }\n },\n { noAck: false },\n )\n this.consumerTags.set(queue, consumerTag)\n this.logger.info({ exchange, routingKey, queue }, 'Subscribed to queue')\n }\n\n private async handleWithRetry(\n message: amqp.ConsumeMessage,\n handler: RabbitMQMessageHandler,\n ): Promise<void> {\n // Capture the channel reference so ack/nack always targets the channel\n // that delivered this message, even if a reconnection swaps this.channel.\n const channel = this.channel\n if (!channel) {\n this.logger.warn('Cannot process message -- channel unavailable')\n return\n }\n this.inflightCount++\n try {\n const startTime = Date.now()\n let attempts = 0\n const routingKey = message.fields.routingKey\n const exchange = message.fields.exchange\n\n let content: RabbitMQMessage\n try {\n content = JSON.parse(message.content.toString())\n } catch (parseError) {\n const rawContent = message.content.toString()\n const rawPreview = rawContent.substring(0, 100)\n this.logger.error(\n {\n error: parseError,\n exchange,\n routingKey,\n rawContentPreview: rawPreview + (rawContent.length > 100 ? '...' : ''),\n },\n 'Failed to parse message JSON, sending to DLQ',\n )\n channel.nack(message, false, false)\n this.callHook(this.hooks.onMessageDlq, { exchange, routingKey, duration: 0, reason: 'invalid_json' })\n return\n }\n\n this.logger.debug({ exchange, routingKey, payload: content }, 'Message received, processing')\n\n while (attempts < this.options.maxRetries) {\n try {\n await handler(content)\n const duration = Date.now() - startTime\n this.logger.info(\n { exchange, routingKey, duration, attempts: attempts + 1 },\n 'Message processed successfully',\n )\n channel.ack(message)\n this.callHook(this.hooks.onMessageProcessed, { exchange, routingKey, duration, attempts: attempts + 1 })\n return\n } catch (error) {\n attempts++\n this.logger.error(\n {\n error: error instanceof Error ? error.message : error,\n stack: error instanceof Error ? error.stack : undefined,\n exchange,\n routingKey,\n attempt: attempts,\n maxRetries: this.options.maxRetries,\n },\n 'Handler failed',\n )\n if (attempts < this.options.maxRetries) {\n await this.sleep(this.options.retryDelay)\n }\n }\n }\n\n const duration = Date.now() - startTime\n this.logger.error(\n { exchange, routingKey, maxRetries: this.options.maxRetries, duration },\n 'Message failed after max retries, sending to DLQ',\n )\n channel.nack(message, false, false)\n this.callHook(this.hooks.onMessageDlq, { exchange, routingKey, duration, reason: 'max_retries_exhausted' })\n } finally {\n this.inflightCount--\n if (this.inflightCount === 0 && this.drainResolve) {\n this.drainResolve()\n }\n }\n }\n\n /**\n * Lightweight liveness probe: creates and immediately deletes a temporary\n * exclusive queue. Returns `false` when disconnected or on broker error.\n */\n async checkHealth(): Promise<boolean> {\n if (!this.connected || !this.channel) {\n return false\n }\n try {\n const { queue } = await this.channel.assertQueue('', {\n exclusive: true,\n autoDelete: true,\n })\n await this.channel.deleteQueue(queue)\n return true\n } catch (error) {\n this.logger.warn({ error }, 'Health check failed')\n return false\n }\n }\n\n private waitForDrain(timeout: number): Promise<void> {\n if (this.inflightCount === 0) return Promise.resolve()\n return new Promise<void>((resolve) => {\n const timer = setTimeout(() => {\n this.logger.warn(\n { inflightCount: this.inflightCount },\n 'Close timeout reached with messages still in flight',\n )\n this.drainResolve = null\n resolve()\n }, timeout)\n this.drainResolve = () => {\n clearTimeout(timer)\n this.drainResolve = null\n resolve()\n }\n })\n }\n\n /** Invokes a hook callback, swallowing errors so hooks never break message flow. */\n private callHook<T>(hook: ((info: T) => void) | undefined, info: T): void {\n try { hook?.(info) } catch { /* swallowed */ }\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms))\n }\n}\n","import pino, { type Logger } from 'pino'\n\n/**\n * Creates a child pino logger for the RabbitMQ client.\n *\n * If a parent logger is provided, the child inherits its configuration\n * (level, transports, etc.) for unified log output. Otherwise, a new\n * root logger is created.\n */\nexport const createLogger = (parent?: Logger): Logger =>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EACF;AAAA,EAEQ,aAAa,SAAgC;AACnD,QAAI,KAAK,kBAAkB,EAAG,QAAO,QAAQ,QAAQ;AACrD,WAAO,IAAI,QAAc,CAAC,YAAY;AACpC,YAAM,QAAQ,WAAW,MAAM;AAC7B,aAAK,OAAO;AAAA,UACV,EAAE,eAAe,KAAK,cAAc;AAAA,UACpC;AAAA,QACF;AACA,aAAK,eAAe;AACpB,gBAAQ;AAAA,MACV,GAAG,OAAO;AACV,WAAK,eAAe,MAAM;AACxB,qBAAa,KAAK;AAClB,aAAK,eAAe;AACpB,gBAAQ;AAAA,MACV;AAAA,IACF,CAAC;AAAA,EACH;AAAA;AAAA,EAGQ,SAAY,MAAuC,MAAe;AACxE,QAAI;AAAE,aAAO,IAAI;AAAA,IAAE,QAAQ;AAAA,IAAkB;AAAA,EAC/C;AAAA,EAEQ,MAAM,IAA2B;AACvC,WAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,EAAE,CAAC;AAAA,EACzD;AACF;","names":["duration"]}
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/logger.ts"],"sourcesContent":["import amqp from 'amqplib'\nimport type {\n PublishOptions,\n RabbitMQClientOptions,\n RabbitMQHooks,\n RabbitMQMessage,\n RabbitMQMessageHandler,\n RabbitMQSubscription,\n SubscribeOptions,\n} from './types.js'\nimport { createLogger } from './logger.js'\nimport type { Logger } from 'pino'\n\nconst DEFAULT_PREFETCH = 10\nconst MAX_PUBLISH_RETRY_DELAY_MS = 60_000\n\nconst DEFAULTS = {\n maxRetries: 3,\n retryDelay: 1000,\n connectionRetryDelay: 5000,\n initMaxAttempts: 5,\n publishMaxAttempts: 5,\n prefetch: DEFAULT_PREFETCH,\n closeTimeout: 5000,\n} as const\n\n/**\n * Production-grade RabbitMQ client with confirm channels, automatic DLQ\n * infrastructure, reconnection with subscription restoration, and\n * exponential-backoff publishing.\n *\n * @example\n * ```ts\n * const client = new RabbitMQClient({ url: 'amqp://localhost' })\n * await client.init()\n * await client.publish('events', 'user.created', { userId: '123' })\n * await client.subscribe('events', 'user.created', 'user-service', handler)\n * ```\n */\nexport class RabbitMQClient {\n private connection: amqp.ChannelModel | null = null\n private channel: amqp.ConfirmChannel | null = null\n private connected = false\n private subscriptions: RabbitMQSubscription[] = []\n private readonly options: Required<Omit<RabbitMQClientOptions, 'logger' | 'hooks'>>\n private readonly logger: Logger\n private readonly hooks: RabbitMQHooks\n private initializationPromise: Promise<void> | null = null\n private reconnectionPromise: Promise<void> | null = null\n private assertedExchanges = new Set<string>()\n private consumerTags = new Map<string, string>()\n private inflightCount = 0\n private drainResolve: (() => void) | null = null\n\n constructor(options: RabbitMQClientOptions) {\n this.options = {\n url: options.url,\n maxRetries: options.maxRetries ?? DEFAULTS.maxRetries,\n retryDelay: options.retryDelay ?? DEFAULTS.retryDelay,\n connectionRetryDelay: options.connectionRetryDelay ?? DEFAULTS.connectionRetryDelay,\n initMaxAttempts: options.initMaxAttempts ?? DEFAULTS.initMaxAttempts,\n publishMaxAttempts: options.publishMaxAttempts ?? DEFAULTS.publishMaxAttempts,\n prefetch: options.prefetch ?? DEFAULTS.prefetch,\n closeTimeout: options.closeTimeout ?? DEFAULTS.closeTimeout,\n }\n this.logger = createLogger(options.logger)\n this.hooks = options.hooks ?? {}\n }\n\n /**\n * Opens a connection and creates a confirm channel. Retries up to\n * `initMaxAttempts` times, then throws. Idempotent and safe to call\n * concurrently — duplicate calls share the same in-flight promise.\n */\n async init(): Promise<void> {\n if (this.connection && this.connected) {\n return\n }\n if (this.initializationPromise) {\n return this.initializationPromise\n }\n // Attach a no-op catch to prevent Node from briefly treating this as an\n // unhandled rejection before the await below registers its own handler.\n this.initializationPromise = this.doConnect(this.options.initMaxAttempts)\n this.initializationPromise.catch(() => undefined)\n try {\n await this.initializationPromise\n } finally {\n this.initializationPromise = null\n }\n }\n\n private async doConnect(maxAttempts?: number): Promise<void> {\n this.assertedExchanges.clear()\n this.consumerTags.clear()\n let attempts = 0\n while (!this.connected) {\n try {\n this.connection = await amqp.connect(this.options.url)\n this.logger.info('Connected to server')\n this.channel = await this.connection.createConfirmChannel()\n this.logger.info('Confirm channel created')\n await this.channel.prefetch(this.options.prefetch)\n this.logger.info({ prefetch: this.options.prefetch }, 'Channel prefetch set')\n\n this.connection.on('error', (error: Error) => {\n this.connected = false\n this.logger.error({ error }, 'Connection error')\n })\n this.connection.on('close', () => {\n this.connected = false\n this.logger.warn('Connection closed')\n this.reconnectWithRetry()\n })\n this.channel.on('error', (error: Error) => {\n this.logger.error({ error }, 'Channel error')\n this.handleChannelFailure()\n })\n this.channel.on('close', () => {\n this.logger.warn('Channel closed')\n this.handleChannelFailure()\n })\n\n this.connected = true\n this.logger.info('Client initialized successfully')\n } catch (error) {\n attempts++\n this.connected = false\n if (maxAttempts !== undefined && attempts >= maxAttempts) {\n this.logger.error({ error, attempts, maxAttempts }, 'Connection failed after maximum attempts')\n throw new Error(\n `Failed to connect to RabbitMQ after ${attempts} attempts. ` +\n 'Check RABBITMQ_URL configuration and RabbitMQ server availability.',\n )\n }\n this.logger.warn(\n {\n error,\n attempt: attempts,\n maxAttempts: maxAttempts ?? 'unlimited',\n retryDelayMs: this.options.connectionRetryDelay,\n },\n 'Connection attempt failed, retrying...',\n )\n await this.sleep(this.options.connectionRetryDelay)\n }\n }\n }\n\n private handleChannelFailure(): void {\n if (this.connected) {\n this.connected = false\n this.reconnectWithRetry()\n }\n }\n\n /**\n * Returns whether the client currently has an active connection and channel.\n */\n isConnected(): boolean {\n return this.connected\n }\n\n /**\n * Publishes a JSON message to a topic exchange with publisher confirms.\n * Retries with exponential backoff (capped at 60 s), forcing a reconnect\n * on each failure. Throws after `publishMaxAttempts` exhausted.\n */\n async publish(\n exchange: string,\n routingKey: string,\n message: RabbitMQMessage,\n options?: PublishOptions,\n ): Promise<void> {\n let attempts = 0\n const maxAttempts = options?.maxAttempts ?? this.options.publishMaxAttempts\n const baseDelay = this.options.connectionRetryDelay\n const content = Buffer.from(JSON.stringify(message))\n\n while (attempts < maxAttempts) {\n try {\n if (!this.connected) {\n await this.reconnectWithRetry()\n }\n\n if (!this.channel) {\n throw new Error('Channel not available')\n }\n\n if (!this.assertedExchanges.has(exchange)) {\n await this.channel.assertExchange(exchange, 'topic', { durable: true })\n this.assertedExchanges.add(exchange)\n }\n\n this.channel.publish(exchange, routingKey, content, {\n persistent: true,\n headers: options?.headers,\n correlationId: options?.correlationId,\n messageId: options?.messageId,\n expiration: options?.expiration,\n })\n\n await this.channel.waitForConfirms()\n\n if (attempts > 0) {\n this.logger.info({ exchange, routingKey, messageSize: content.length, attempts }, 'Published message after retries')\n } else {\n this.logger.info({ exchange, routingKey, messageSize: content.length }, 'Published message')\n }\n this.logger.debug({ exchange, routingKey, payload: message }, 'Published message payload')\n\n this.callHook(this.hooks.onPublish, { exchange, routingKey, attempts: attempts + 1 })\n\n return\n } catch (error) {\n attempts++\n this.connected = false\n\n if (attempts >= maxAttempts) {\n this.logger.error(\n { error, exchange, routingKey, attempts, maxAttempts },\n 'Publish failed after max attempts',\n )\n throw new Error(\n `Failed to publish to ${exchange}/${routingKey} after ${attempts} attempts: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n\n const retryDelay = Math.min(\n baseDelay * Math.pow(2, attempts - 1),\n MAX_PUBLISH_RETRY_DELAY_MS,\n )\n\n this.logger.warn(\n { error, exchange, routingKey, attempt: attempts, maxAttempts, retryDelayMs: retryDelay },\n 'Publish attempt failed, retrying',\n )\n\n await this.sleep(retryDelay)\n }\n }\n }\n\n /**\n * Gracefully shuts down the client. Waits up to `closeTimeout` ms for\n * in-flight message handlers to finish before closing the channel and\n * connection. Pass `false` to preserve subscriptions for a later\n * `init()` / reconnect cycle.\n */\n async close(clearSubscriptions = true): Promise<void> {\n try {\n if (this.inflightCount > 0) {\n this.logger.info({ inflightCount: this.inflightCount }, 'Waiting for in-flight messages to drain')\n await this.waitForDrain(this.options.closeTimeout)\n }\n await this.channel?.close()\n await this.connection?.close()\n this.connection = null\n this.channel = null\n this.connected = false\n this.initializationPromise = null\n this.reconnectionPromise = null\n this.assertedExchanges.clear()\n this.consumerTags.clear()\n if (clearSubscriptions) {\n this.subscriptions = []\n }\n this.logger.info('Connection closed')\n } catch (error) {\n this.logger.error({ error }, 'Error closing connection')\n throw error\n }\n }\n\n private async reconnectWithRetry(): Promise<void> {\n if (this.reconnectionPromise) {\n return this.reconnectionPromise\n }\n this.connected = false\n this.logger.info('Starting reconnection...')\n this.reconnectionPromise = this.doReconnect()\n this.reconnectionPromise.catch(() => undefined)\n try {\n await this.reconnectionPromise\n } finally {\n this.reconnectionPromise = null\n }\n }\n\n private async doReconnect(): Promise<void> {\n await this.doConnect()\n await this.resubscribeAll()\n }\n\n private async resubscribeAll(): Promise<void> {\n if (this.subscriptions.length === 0) {\n return\n }\n this.logger.info({ count: this.subscriptions.length }, 'Re-establishing subscriptions')\n const subs = [...this.subscriptions]\n const results = await Promise.allSettled(\n subs.map(async (sub) => {\n await this.setupSubscription(sub)\n return sub.queue\n }),\n )\n const succeeded: string[] = []\n const failed: string[] = []\n results.forEach((result, index) => {\n if (result.status === 'fulfilled') {\n succeeded.push(result.value)\n } else {\n const queue = subs[index].queue\n failed.push(queue)\n this.logger.error({ error: result.reason, queue }, 'Failed to re-subscribe to queue')\n }\n })\n if (succeeded.length > 0) {\n this.logger.info({ count: succeeded.length, queues: succeeded }, 'Successfully re-subscribed to queues')\n }\n if (failed.length > 0) {\n this.logger.warn({ count: failed.length, queues: failed }, 'Some subscriptions failed to restore')\n }\n this.callHook(this.hooks.onReconnect, { subscriptionsRestored: succeeded.length, subscriptionsFailed: failed.length })\n }\n\n /**\n * Subscribes to a queue with automatic DLQ infrastructure setup.\n *\n * Pass `options.queueArguments` to override the default quorum-queue\n * arguments (merged with the DLQ wiring defaults).\n */\n async subscribe(\n exchange: string,\n routingKey: string,\n queue: string,\n handler: RabbitMQMessageHandler,\n options?: SubscribeOptions,\n ): Promise<void> {\n if (!this.connected || !this.channel) {\n throw new Error('RabbitMQ client not connected. Call init() first.')\n }\n const sub: RabbitMQSubscription = { exchange, routingKey, queue, handler, options }\n const existingIndex = this.subscriptions.findIndex((s) => s.queue === queue)\n if (existingIndex === -1) {\n this.subscriptions.push(sub)\n } else {\n this.subscriptions[existingIndex] = sub\n }\n await this.setupSubscription(sub)\n }\n\n /**\n * Cancels a queue subscription and removes it from the restoration list.\n */\n async unsubscribe(queue: string): Promise<void> {\n const tag = this.consumerTags.get(queue)\n if (tag && this.channel) {\n await this.channel.cancel(tag)\n }\n this.consumerTags.delete(queue)\n this.subscriptions = this.subscriptions.filter((s) => s.queue !== queue)\n this.logger.info({ queue }, 'Unsubscribed from queue')\n }\n\n private async setupSubscription(sub: RabbitMQSubscription): Promise<void> {\n if (!this.channel) {\n throw new Error('Channel not available')\n }\n const { exchange, routingKey, queue, handler, options } = sub\n const dlxExchange = `${exchange}.dlx`\n const dlqQueue = `${queue}.dlq`\n const dlqRoutingKey = `${routingKey}.dead`\n\n await this.channel.assertExchange(dlxExchange, 'topic', { durable: true })\n await this.channel.assertQueue(dlqQueue, { durable: true })\n await this.channel.bindQueue(dlqQueue, dlxExchange, dlqRoutingKey)\n\n if (!this.assertedExchanges.has(exchange)) {\n await this.channel.assertExchange(exchange, 'topic', { durable: true })\n this.assertedExchanges.add(exchange)\n }\n\n const queueType = options?.queueArguments?.['x-queue-type'] ?? 'quorum'\n const queueArgs: Record<string, unknown> = {\n 'x-queue-type': queueType,\n 'x-overflow': 'reject-publish',\n }\n // at-least-once DLQ strategy is only supported by quorum queues\n if (queueType === 'quorum') {\n queueArgs['x-dead-letter-strategy'] = 'at-least-once'\n }\n\n await this.channel.assertQueue(queue, {\n durable: true,\n deadLetterExchange: dlxExchange,\n deadLetterRoutingKey: dlqRoutingKey,\n arguments: { ...queueArgs, ...options?.queueArguments },\n })\n\n await this.channel.bindQueue(queue, exchange, routingKey)\n const { consumerTag } = await this.channel.consume(\n queue,\n (message) => {\n if (message) {\n this.handleWithRetry(message, handler).catch((error) => {\n this.logger.error({ error }, 'Unhandled error in message handler')\n })\n }\n },\n { noAck: false },\n )\n this.consumerTags.set(queue, consumerTag)\n this.logger.info({ exchange, routingKey, queue }, 'Subscribed to queue')\n }\n\n private async handleWithRetry(\n message: amqp.ConsumeMessage,\n handler: RabbitMQMessageHandler,\n ): Promise<void> {\n // Capture the channel reference so ack/nack always targets the channel\n // that delivered this message, even if a reconnection swaps this.channel.\n const channel = this.channel\n if (!channel) {\n this.logger.warn('Cannot process message -- channel unavailable')\n return\n }\n this.inflightCount++\n try {\n const startTime = Date.now()\n let attempts = 0\n const routingKey = message.fields.routingKey\n const exchange = message.fields.exchange\n\n let content: RabbitMQMessage\n try {\n content = JSON.parse(message.content.toString())\n } catch (parseError) {\n const rawContent = message.content.toString()\n const rawPreview = rawContent.substring(0, 100)\n this.logger.error(\n {\n error: parseError,\n exchange,\n routingKey,\n rawContentPreview: rawPreview + (rawContent.length > 100 ? '...' : ''),\n },\n 'Failed to parse message JSON, sending to DLQ',\n )\n channel.nack(message, false, false)\n this.callHook(this.hooks.onMessageDlq, { exchange, routingKey, duration: 0, reason: 'invalid_json' })\n return\n }\n\n this.logger.debug({ exchange, routingKey, payload: content }, 'Message received, processing')\n\n while (attempts < this.options.maxRetries) {\n try {\n await handler(content)\n const duration = Date.now() - startTime\n this.logger.info(\n { exchange, routingKey, duration, attempts: attempts + 1 },\n 'Message processed successfully',\n )\n channel.ack(message)\n this.callHook(this.hooks.onMessageProcessed, { exchange, routingKey, duration, attempts: attempts + 1 })\n return\n } catch (error) {\n attempts++\n this.logger.error(\n {\n error: error instanceof Error ? error.message : error,\n stack: error instanceof Error ? error.stack : undefined,\n exchange,\n routingKey,\n attempt: attempts,\n maxRetries: this.options.maxRetries,\n },\n 'Handler failed',\n )\n if (attempts < this.options.maxRetries) {\n await this.sleep(this.options.retryDelay)\n }\n }\n }\n\n const duration = Date.now() - startTime\n this.logger.error(\n { exchange, routingKey, maxRetries: this.options.maxRetries, duration },\n 'Message failed after max retries, sending to DLQ',\n )\n channel.nack(message, false, false)\n this.callHook(this.hooks.onMessageDlq, { exchange, routingKey, duration, reason: 'max_retries_exhausted' })\n } finally {\n this.inflightCount--\n if (this.inflightCount === 0 && this.drainResolve) {\n this.drainResolve()\n }\n }\n }\n\n /**\n * Lightweight liveness probe: creates and immediately deletes a temporary\n * exclusive queue. Returns `false` when disconnected or on broker error.\n */\n async checkHealth(): Promise<boolean> {\n if (!this.connected || !this.channel) {\n return false\n }\n try {\n const { queue } = await this.channel.assertQueue('', {\n exclusive: true,\n autoDelete: true,\n })\n await this.channel.deleteQueue(queue)\n return true\n } catch (error) {\n this.logger.warn({ error }, 'Health check failed')\n return false\n }\n }\n\n private waitForDrain(timeout: number): Promise<void> {\n if (this.inflightCount === 0) return Promise.resolve()\n return new Promise<void>((resolve) => {\n const timer = setTimeout(() => {\n this.logger.warn(\n { inflightCount: this.inflightCount },\n 'Close timeout reached with messages still in flight',\n )\n this.drainResolve = null\n resolve()\n }, timeout)\n this.drainResolve = () => {\n clearTimeout(timer)\n this.drainResolve = null\n resolve()\n }\n })\n }\n\n /** Invokes a hook callback, swallowing errors so hooks never break message flow. */\n private callHook<T>(hook: ((info: T) => void) | undefined, info: T): void {\n try { hook?.(info) } catch (error) { this.logger.debug({ error }, 'Observability hook error') }\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms))\n }\n}\n","import pino, { type Logger } from 'pino'\n\n/**\n * Creates a child pino logger for the RabbitMQ client.\n *\n * If a parent logger is provided, the child inherits its configuration\n * (level, transports, etc.) for unified log output. Otherwise, a new\n * root logger is created.\n */\nexport const createLogger = (parent?: Logger): Logger => {\n if (parent) {\n return parent.child({ service: 'rabbitmq-client' })\n }\n return pino({ name: 'rabbitmq-client' })\n}\n"],"mappings":";AAAA,OAAO,UAAU;;;ACAjB,OAAO,UAA2B;AAS3B,IAAM,eAAe,CAAC,WAA4B;AACvD,MAAI,QAAQ;AACV,WAAO,OAAO,MAAM,EAAE,SAAS,kBA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AAAA,IACT,SAAS,OAAO;AACd,WAAK,OAAO,KAAK,EAAE,MAAM,GAAG,qBAAqB;AACjD,aAAO;AAAA,IACT;AAAA,EACF;AAAA,EAEQ,aAAa,SAAgC;AACnD,QAAI,KAAK,kBAAkB,EAAG,QAAO,QAAQ,QAAQ;AACrD,WAAO,IAAI,QAAc,CAAC,YAAY;AACpC,YAAM,QAAQ,WAAW,MAAM;AAC7B,aAAK,OAAO;AAAA,UACV,EAAE,eAAe,KAAK,cAAc;AAAA,UACpC;AAAA,QACF;AACA,aAAK,eAAe;AACpB,gBAAQ;AAAA,MACV,GAAG,OAAO;AACV,WAAK,eAAe,MAAM;AACxB,qBAAa,KAAK;AAClB,aAAK,eAAe;AACpB,gBAAQ;AAAA,MACV;AAAA,IACF,CAAC;AAAA,EACH;AAAA;AAAA,EAGQ,SAAY,MAAuC,MAAe;AACxE,QAAI;AAAE,aAAO,IAAI;AAAA,IAAE,SAAS,OAAO;AAAE,WAAK,OAAO,MAAM,EAAE,MAAM,GAAG,0BAA0B;AAAA,IAAE;AAAA,EAChG;AAAA,EAEQ,MAAM,IAA2B;AACvC,WAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,EAAE,CAAC;AAAA,EACzD;AACF;","names":["duration"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linagora/rabbitmq-client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Production-grade RabbitMQ client with confirm channels, DLQ infrastructure, auto-reconnection, exponential backoff, graceful shutdown, and observability hooks",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"engines": {
|
|
52
52
|
"node": ">=18"
|
|
53
53
|
},
|
|
54
|
-
"license": "
|
|
54
|
+
"license": "MIT",
|
|
55
55
|
"repository": {
|
|
56
56
|
"type": "git",
|
|
57
57
|
"url": "https://github.com/linagora/rabbitmq-client.git"
|