@linagora/rabbitmq-client 0.2.2 → 0.3.1
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 +9 -0
- package/dist/index.cjs +20 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -124
- package/dist/index.d.ts +3 -124
- package/dist/index.js +20 -2
- package/dist/index.js.map +1 -1
- package/dist/testing/index.cjs +6 -5
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.d.cts +4 -2
- package/dist/testing/index.d.ts +4 -2
- package/dist/testing/index.js +6 -5
- package/dist/testing/index.js.map +1 -1
- package/dist/types-0S6O7J60.d.cts +137 -0
- package/dist/types-0S6O7J60.d.ts +137 -0
- package/package.json +2 -1
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal logging contract required by this library.
|
|
3
|
+
*
|
|
4
|
+
* Calls are message-first (`logger.error('message', { context })`), matching
|
|
5
|
+
* `console`, Winston, and Bunyan. A pino logger is recognised and called
|
|
6
|
+
* pino's way (`(context, message)`, errors under `err`), so any of them can be
|
|
7
|
+
* passed directly without writing a wrapper. Only these four levels are used.
|
|
8
|
+
*/
|
|
9
|
+
interface ILogger {
|
|
10
|
+
/** Detailed diagnostic information for developers. */
|
|
11
|
+
debug(message: string, ...args: unknown[]): void;
|
|
12
|
+
/** Routine informational messages about library operations. */
|
|
13
|
+
info(message: string, ...args: unknown[]): void;
|
|
14
|
+
/** Warnings about non-fatal issues. */
|
|
15
|
+
warn(message: string, ...args: unknown[]): void;
|
|
16
|
+
/** Errors indicating an operation failed. */
|
|
17
|
+
error(message: string, ...args: unknown[]): void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Hooks for observability — optional callbacks invoked on key client events.
|
|
21
|
+
* Use these to wire metrics, tracing, or custom logging.
|
|
22
|
+
*/
|
|
23
|
+
interface RabbitMQHooks {
|
|
24
|
+
/** Called after the broker confirms a published message */
|
|
25
|
+
onPublish?: (info: {
|
|
26
|
+
exchange: string;
|
|
27
|
+
routingKey: string;
|
|
28
|
+
attempts: number;
|
|
29
|
+
}) => void;
|
|
30
|
+
/** Called after a message handler returns successfully (duration includes retries) */
|
|
31
|
+
onMessageProcessed?: (info: {
|
|
32
|
+
exchange: string;
|
|
33
|
+
routingKey: string;
|
|
34
|
+
duration: number;
|
|
35
|
+
attempts: number;
|
|
36
|
+
}) => void;
|
|
37
|
+
/** Called when a message is nacked to the dead-letter queue */
|
|
38
|
+
onMessageDlq?: (info: {
|
|
39
|
+
exchange: string;
|
|
40
|
+
routingKey: string;
|
|
41
|
+
duration: number;
|
|
42
|
+
reason: 'invalid_json' | 'max_retries_exhausted';
|
|
43
|
+
}) => void;
|
|
44
|
+
/** Called after reconnection completes and subscriptions are re-established */
|
|
45
|
+
onReconnect?: (info: {
|
|
46
|
+
subscriptionsRestored: number;
|
|
47
|
+
subscriptionsFailed: number;
|
|
48
|
+
}) => void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Options for queue subscription.
|
|
52
|
+
*/
|
|
53
|
+
interface SubscribeOptions {
|
|
54
|
+
/** Override default AMQP queue arguments (merged with DLQ wiring defaults) */
|
|
55
|
+
queueArguments?: Record<string, unknown>;
|
|
56
|
+
/**
|
|
57
|
+
* Max message handlers to run concurrently for this subscription.
|
|
58
|
+
* Overrides the client-level `concurrency` for this queue only. Prefetch
|
|
59
|
+
* bounds messages held in memory; concurrency bounds how many are processed
|
|
60
|
+
* at once, and only throttles when set below `prefetch`. `0` means no limit.
|
|
61
|
+
*/
|
|
62
|
+
concurrency?: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Configuration options for the RabbitMQ client.
|
|
66
|
+
*/
|
|
67
|
+
interface RabbitMQClientOptions {
|
|
68
|
+
/** AMQP connection URL (e.g., 'amqp://user:pass@host:5672') */
|
|
69
|
+
url: string;
|
|
70
|
+
/** Max handler retries before sending to DLQ (default: 3) */
|
|
71
|
+
maxRetries?: number;
|
|
72
|
+
/** Delay in ms between handler retries (default: 1000) */
|
|
73
|
+
retryDelay?: number;
|
|
74
|
+
/** Delay in ms between reconnection attempts (default: 5000) */
|
|
75
|
+
connectionRetryDelay?: number;
|
|
76
|
+
/** Max connection attempts during init; undefined = unlimited (default: 5) */
|
|
77
|
+
initMaxAttempts?: number;
|
|
78
|
+
/** Max publish attempts with exponential backoff (default: 5) */
|
|
79
|
+
publishMaxAttempts?: number;
|
|
80
|
+
/** Channel prefetch count (default: 10) */
|
|
81
|
+
prefetch?: number;
|
|
82
|
+
/**
|
|
83
|
+
* Max message handlers to run concurrently per subscription (default: equal
|
|
84
|
+
* to `prefetch`). Bounds how many `handler` callbacks execute at once, on top
|
|
85
|
+
* of how many messages prefetch keeps buffered in memory. Only throttles when
|
|
86
|
+
* set below `prefetch`, since the broker never delivers more than `prefetch`
|
|
87
|
+
* unacked messages at a time; `0` (or a negative value) means no limit.
|
|
88
|
+
* Override per queue via `SubscribeOptions.concurrency`.
|
|
89
|
+
*/
|
|
90
|
+
concurrency?: number;
|
|
91
|
+
/** Logger satisfying the ILogger contract; defaults to console warn/error only if omitted */
|
|
92
|
+
logger?: ILogger;
|
|
93
|
+
/** Timeout in ms to wait for in-flight messages during close (default: 5000) */
|
|
94
|
+
closeTimeout?: number;
|
|
95
|
+
/** Observability hooks for metrics and monitoring */
|
|
96
|
+
hooks?: RabbitMQHooks;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Options for the `publish()` method.
|
|
100
|
+
*/
|
|
101
|
+
interface PublishOptions {
|
|
102
|
+
/** Max publish attempts with backoff (overrides client default) */
|
|
103
|
+
maxAttempts?: number;
|
|
104
|
+
/** Custom message headers for tracing and metadata */
|
|
105
|
+
headers?: Record<string, unknown>;
|
|
106
|
+
/** Correlation ID for request-reply patterns */
|
|
107
|
+
correlationId?: string;
|
|
108
|
+
/** Unique message identifier */
|
|
109
|
+
messageId?: string;
|
|
110
|
+
/** Per-message TTL in milliseconds (as string per AMQP spec) */
|
|
111
|
+
expiration?: string;
|
|
112
|
+
}
|
|
113
|
+
/** JSON-serializable message payload */
|
|
114
|
+
type RabbitMQMessage = Record<string, unknown>;
|
|
115
|
+
/** What the publisher and the broker attached to a consumed message */
|
|
116
|
+
interface RabbitMQMessageProperties {
|
|
117
|
+
/** AMQP headers, including broker-added ones such as `x-death` on a dead-lettered message */
|
|
118
|
+
headers: Record<string, unknown>;
|
|
119
|
+
/** AMQP timestamp in seconds, if the publisher set one */
|
|
120
|
+
timestamp?: number;
|
|
121
|
+
/** Unique message identifier, if the publisher set one */
|
|
122
|
+
messageId?: string;
|
|
123
|
+
/** Correlation ID, if the publisher set one */
|
|
124
|
+
correlationId?: string;
|
|
125
|
+
}
|
|
126
|
+
/** Async handler function for consumed messages */
|
|
127
|
+
type RabbitMQMessageHandler = (message: RabbitMQMessage, properties: RabbitMQMessageProperties) => Promise<void>;
|
|
128
|
+
/** Stored subscription metadata for restoration after reconnection */
|
|
129
|
+
interface RabbitMQSubscription {
|
|
130
|
+
exchange: string;
|
|
131
|
+
routingKey: string;
|
|
132
|
+
queue: string;
|
|
133
|
+
handler: RabbitMQMessageHandler;
|
|
134
|
+
options?: SubscribeOptions;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export type { ILogger as I, PublishOptions as P, RabbitMQClientOptions as R, SubscribeOptions as S, RabbitMQMessage as a, RabbitMQMessageHandler as b, RabbitMQHooks as c, RabbitMQMessageProperties as d, RabbitMQSubscription as e };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linagora/rabbitmq-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
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": {
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/amqplib": "^0.10.7",
|
|
46
|
+
"pino": "^9.14.0",
|
|
46
47
|
"tsup": "^8.4.0",
|
|
47
48
|
"typescript": "^5.7.3",
|
|
48
49
|
"vitest": "^3.1.1"
|