amqp-resilient 1.0.0
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 +257 -0
- package/dist/connection/ConnectionManager.d.ts +84 -0
- package/dist/connection/ConnectionManager.d.ts.map +1 -0
- package/dist/connection/ConnectionManager.js +312 -0
- package/dist/connection/ConnectionManager.js.map +1 -0
- package/dist/connection/index.d.ts +2 -0
- package/dist/connection/index.d.ts.map +1 -0
- package/dist/connection/index.js +2 -0
- package/dist/connection/index.js.map +1 -0
- package/dist/consumer/BaseConsumer.d.ts +131 -0
- package/dist/consumer/BaseConsumer.d.ts.map +1 -0
- package/dist/consumer/BaseConsumer.js +398 -0
- package/dist/consumer/BaseConsumer.js.map +1 -0
- package/dist/consumer/index.d.ts +2 -0
- package/dist/consumer/index.d.ts.map +1 -0
- package/dist/consumer/index.js +2 -0
- package/dist/consumer/index.js.map +1 -0
- package/dist/health/HealthService.d.ts +46 -0
- package/dist/health/HealthService.d.ts.map +1 -0
- package/dist/health/HealthService.js +85 -0
- package/dist/health/HealthService.js.map +1 -0
- package/dist/health/index.d.ts +2 -0
- package/dist/health/index.d.ts.map +1 -0
- package/dist/health/index.js +2 -0
- package/dist/health/index.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/patterns/CircuitBreaker.d.ts +76 -0
- package/dist/patterns/CircuitBreaker.d.ts.map +1 -0
- package/dist/patterns/CircuitBreaker.js +156 -0
- package/dist/patterns/CircuitBreaker.js.map +1 -0
- package/dist/patterns/index.d.ts +2 -0
- package/dist/patterns/index.d.ts.map +1 -0
- package/dist/patterns/index.js +2 -0
- package/dist/patterns/index.js.map +1 -0
- package/dist/publisher/BasePublisher.d.ts +87 -0
- package/dist/publisher/BasePublisher.d.ts.map +1 -0
- package/dist/publisher/BasePublisher.js +275 -0
- package/dist/publisher/BasePublisher.js.map +1 -0
- package/dist/publisher/index.d.ts +2 -0
- package/dist/publisher/index.d.ts.map +1 -0
- package/dist/publisher/index.js +2 -0
- package/dist/publisher/index.js.map +1 -0
- package/dist/types.d.ts +184 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +35 -0
- package/dist/types.js.map +1 -0
- package/package.json +81 -0
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { randomUUID } from 'crypto';
|
|
2
|
+
import { CircuitBreaker, CircuitBreakerOpenError } from '../patterns/CircuitBreaker.js';
|
|
3
|
+
/** Default retry configuration */
|
|
4
|
+
const DEFAULTS = {
|
|
5
|
+
MAX_RETRIES: 3,
|
|
6
|
+
INITIAL_RETRY_DELAY: 100,
|
|
7
|
+
MAX_RETRY_DELAY: 5000,
|
|
8
|
+
CIRCUIT_BREAKER_THRESHOLD: 5,
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* BasePublisher - Base class for AMQP publishers
|
|
12
|
+
* Use this class directly or extend it for specific publishers
|
|
13
|
+
*/
|
|
14
|
+
export class BasePublisher {
|
|
15
|
+
connection;
|
|
16
|
+
channel = null;
|
|
17
|
+
isInitialized = false;
|
|
18
|
+
circuitBreaker = null;
|
|
19
|
+
logger;
|
|
20
|
+
exchange;
|
|
21
|
+
exchangeType;
|
|
22
|
+
confirm;
|
|
23
|
+
maxRetries;
|
|
24
|
+
initialRetryDelay;
|
|
25
|
+
maxRetryDelay;
|
|
26
|
+
useCircuitBreaker;
|
|
27
|
+
constructor(connection, options) {
|
|
28
|
+
this.connection = connection;
|
|
29
|
+
this.exchange = options.exchange;
|
|
30
|
+
this.exchangeType = options.exchangeType ?? 'topic';
|
|
31
|
+
this.confirm = options.confirm ?? true;
|
|
32
|
+
this.maxRetries = options.maxRetries ?? DEFAULTS.MAX_RETRIES;
|
|
33
|
+
this.initialRetryDelay = options.initialRetryDelay ?? DEFAULTS.INITIAL_RETRY_DELAY;
|
|
34
|
+
this.maxRetryDelay = options.maxRetryDelay ?? DEFAULTS.MAX_RETRY_DELAY;
|
|
35
|
+
this.useCircuitBreaker = options.useCircuitBreaker ?? true;
|
|
36
|
+
this.logger = options.logger ?? connection.getLogger();
|
|
37
|
+
// Initialize circuit breaker if enabled
|
|
38
|
+
if (this.useCircuitBreaker) {
|
|
39
|
+
this.circuitBreaker = new CircuitBreaker({
|
|
40
|
+
name: `publisher-${this.exchange}`,
|
|
41
|
+
failureThreshold: options.circuitBreakerThreshold ?? DEFAULTS.CIRCUIT_BREAKER_THRESHOLD,
|
|
42
|
+
resetTimeout: 30000,
|
|
43
|
+
successThreshold: 3,
|
|
44
|
+
logger: this.logger,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Initialize the publisher - setup exchange
|
|
50
|
+
*/
|
|
51
|
+
async initialize() {
|
|
52
|
+
if (this.isInitialized)
|
|
53
|
+
return;
|
|
54
|
+
try {
|
|
55
|
+
// Get appropriate channel type
|
|
56
|
+
if (this.confirm) {
|
|
57
|
+
this.channel = await this.connection.getConfirmChannel();
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
this.channel = await this.connection.getChannel();
|
|
61
|
+
}
|
|
62
|
+
// Assert the exchange
|
|
63
|
+
await this.channel.assertExchange(this.exchange, this.exchangeType, { durable: true });
|
|
64
|
+
this.isInitialized = true;
|
|
65
|
+
this.logger.info({ exchange: this.exchange, type: this.exchangeType, confirms: this.confirm }, 'Publisher initialized');
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
this.logger.error({ err: error, exchange: this.exchange }, 'Failed to initialize publisher');
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Execute single publish attempt
|
|
74
|
+
*/
|
|
75
|
+
async executePublishAttempt(routingKey, message, options) {
|
|
76
|
+
if (this.circuitBreaker) {
|
|
77
|
+
await this.circuitBreaker.execute(() => this.doPublish(routingKey, message, options));
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
await this.doPublish(routingKey, message, options);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Handle publish retry logic
|
|
85
|
+
*/
|
|
86
|
+
async handlePublishRetry(routingKey, messageId, retries, lastError) {
|
|
87
|
+
if (retries > this.maxRetries)
|
|
88
|
+
return false;
|
|
89
|
+
const delay = this.calculateRetryDelay(retries);
|
|
90
|
+
this.logger.warn({
|
|
91
|
+
exchange: this.exchange,
|
|
92
|
+
routingKey,
|
|
93
|
+
messageId,
|
|
94
|
+
retry: retries,
|
|
95
|
+
maxRetries: this.maxRetries,
|
|
96
|
+
delayMs: delay,
|
|
97
|
+
error: lastError.message,
|
|
98
|
+
}, 'Retrying publish after failure');
|
|
99
|
+
await this.sleep(delay);
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Log publish failure after all retries exhausted
|
|
104
|
+
*/
|
|
105
|
+
logPublishFailure(routingKey, messageId, retries, error) {
|
|
106
|
+
this.logger.error({
|
|
107
|
+
exchange: this.exchange,
|
|
108
|
+
routingKey,
|
|
109
|
+
messageId,
|
|
110
|
+
retries,
|
|
111
|
+
error: error?.message,
|
|
112
|
+
}, 'Failed to publish message after all retries');
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Handle circuit breaker error during publish
|
|
116
|
+
*/
|
|
117
|
+
handleCircuitBreakerError(error, routingKey, messageId) {
|
|
118
|
+
this.logger.warn({
|
|
119
|
+
exchange: this.exchange,
|
|
120
|
+
routingKey,
|
|
121
|
+
messageId,
|
|
122
|
+
remainingResetTime: error.remainingResetTime,
|
|
123
|
+
}, 'Publish blocked by circuit breaker');
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Publish a message to the exchange
|
|
128
|
+
*/
|
|
129
|
+
async publish(routingKey, message, options = {}) {
|
|
130
|
+
const messageId = options.messageId ?? randomUUID();
|
|
131
|
+
const correlationId = options.correlationId ?? randomUUID();
|
|
132
|
+
const publishOptions = { ...options, messageId, correlationId };
|
|
133
|
+
let retries = 0;
|
|
134
|
+
let lastError;
|
|
135
|
+
while (retries <= this.maxRetries) {
|
|
136
|
+
try {
|
|
137
|
+
await this.executePublishAttempt(routingKey, message, publishOptions);
|
|
138
|
+
if (retries > 0) {
|
|
139
|
+
this.logger.info({ exchange: this.exchange, routingKey, messageId, retries }, 'Message published after retry');
|
|
140
|
+
}
|
|
141
|
+
return { success: true, messageId, correlationId, retries };
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
145
|
+
if (error instanceof CircuitBreakerOpenError) {
|
|
146
|
+
this.handleCircuitBreakerError(error, routingKey, messageId);
|
|
147
|
+
}
|
|
148
|
+
retries++;
|
|
149
|
+
if (!(await this.handlePublishRetry(routingKey, messageId, retries, lastError))) {
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
this.logPublishFailure(routingKey, messageId, retries, lastError);
|
|
155
|
+
return { success: false, messageId, correlationId, retries, error: lastError };
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Publish a message and throw on failure (for critical messages)
|
|
159
|
+
*/
|
|
160
|
+
async publishOrThrow(routingKey, message, options = {}) {
|
|
161
|
+
const result = await this.publish(routingKey, message, options);
|
|
162
|
+
if (!result.success) {
|
|
163
|
+
throw result.error ?? new Error('Failed to publish message');
|
|
164
|
+
}
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Build publish options
|
|
169
|
+
*/
|
|
170
|
+
buildPublishOptions(options) {
|
|
171
|
+
return {
|
|
172
|
+
messageId: options.messageId,
|
|
173
|
+
correlationId: options.correlationId,
|
|
174
|
+
persistent: options.persistent ?? true,
|
|
175
|
+
contentType: options.contentType ?? 'application/json',
|
|
176
|
+
timestamp: Date.now(),
|
|
177
|
+
priority: options.priority,
|
|
178
|
+
expiration: options.expiration,
|
|
179
|
+
replyTo: options.replyTo,
|
|
180
|
+
headers: {
|
|
181
|
+
...options.headers,
|
|
182
|
+
'x-published-at': new Date().toISOString(),
|
|
183
|
+
'x-publisher': this.exchange,
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Publish with confirm channel (guaranteed delivery)
|
|
189
|
+
*/
|
|
190
|
+
async publishWithConfirm(routingKey, content, publishOptions) {
|
|
191
|
+
await new Promise((resolve, reject) => {
|
|
192
|
+
this.channel.publish(this.exchange, routingKey, content, publishOptions, (err) => {
|
|
193
|
+
if (err) {
|
|
194
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
resolve();
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Publish without confirmation (fire and forget)
|
|
204
|
+
*/
|
|
205
|
+
async publishWithoutConfirm(routingKey, content, publishOptions) {
|
|
206
|
+
if (!this.channel) {
|
|
207
|
+
throw new Error('Channel not available for publishing');
|
|
208
|
+
}
|
|
209
|
+
const published = this.channel.publish(this.exchange, routingKey, content, publishOptions);
|
|
210
|
+
if (!published) {
|
|
211
|
+
await new Promise((resolve) => {
|
|
212
|
+
this.channel?.once('drain', resolve);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Internal publish implementation
|
|
218
|
+
*/
|
|
219
|
+
async doPublish(routingKey, message, options) {
|
|
220
|
+
if (!this.isInitialized) {
|
|
221
|
+
await this.initialize();
|
|
222
|
+
}
|
|
223
|
+
if (!this.channel) {
|
|
224
|
+
throw new Error('Publisher not initialized');
|
|
225
|
+
}
|
|
226
|
+
const content = Buffer.from(JSON.stringify(message));
|
|
227
|
+
const publishOptions = this.buildPublishOptions(options);
|
|
228
|
+
if (this.confirm) {
|
|
229
|
+
await this.publishWithConfirm(routingKey, content, publishOptions);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
await this.publishWithoutConfirm(routingKey, content, publishOptions);
|
|
233
|
+
}
|
|
234
|
+
this.logger.debug({
|
|
235
|
+
exchange: this.exchange,
|
|
236
|
+
routingKey,
|
|
237
|
+
messageId: options.messageId,
|
|
238
|
+
correlationId: options.correlationId,
|
|
239
|
+
confirms: this.confirm,
|
|
240
|
+
}, 'Message published');
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Calculate retry delay with exponential backoff
|
|
244
|
+
*/
|
|
245
|
+
calculateRetryDelay(retryCount) {
|
|
246
|
+
const delay = Math.min(this.initialRetryDelay * Math.pow(2, retryCount - 1), this.maxRetryDelay);
|
|
247
|
+
// Add jitter (0-25%)
|
|
248
|
+
const jitter = delay * Math.random() * 0.25;
|
|
249
|
+
return Math.floor(delay + jitter);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Sleep for specified milliseconds
|
|
253
|
+
*/
|
|
254
|
+
sleep(ms) {
|
|
255
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Get publisher stats
|
|
259
|
+
*/
|
|
260
|
+
getStats() {
|
|
261
|
+
return {
|
|
262
|
+
exchange: this.exchange,
|
|
263
|
+
isInitialized: this.isInitialized,
|
|
264
|
+
confirm: this.confirm,
|
|
265
|
+
circuitBreakerState: this.circuitBreaker?.getState(),
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Reset circuit breaker (useful for testing or manual recovery)
|
|
270
|
+
*/
|
|
271
|
+
resetCircuitBreaker() {
|
|
272
|
+
this.circuitBreaker?.reset();
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
//# sourceMappingURL=BasePublisher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,GAAG,CAAC,CAAC,EACpD,IAAI,CAAC,aAAa,CACnB,CAAC;QACF,qBAAqB;QACrB,MAAM,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;QAC5C,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC;IACpC,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,EAAU;QACtB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED;;OAEG;IACH,QAAQ;QAMN,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,mBAAmB,EAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,EAAE;SACrD,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,mBAAmB;QACjB,IAAI,CAAC,cAAc,EAAE,KAAK,EAAE,CAAC;IAC/B,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/publisher/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/publisher/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for amqp-resilient
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Logger interface - inject your own logger implementation
|
|
6
|
+
* Compatible with pino, winston, bunyan, console, etc.
|
|
7
|
+
*/
|
|
8
|
+
export interface AmqpLogger {
|
|
9
|
+
info(obj: object, msg?: string): void;
|
|
10
|
+
warn(obj: object, msg?: string): void;
|
|
11
|
+
error(obj: object, msg?: string): void;
|
|
12
|
+
debug(obj: object, msg?: string): void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Connection options
|
|
16
|
+
*/
|
|
17
|
+
export interface ConnectionOptions {
|
|
18
|
+
/** Full AMQP URL (alternative to individual params) */
|
|
19
|
+
url?: string;
|
|
20
|
+
/** RabbitMQ host */
|
|
21
|
+
host?: string;
|
|
22
|
+
/** RabbitMQ port (default: 5672) */
|
|
23
|
+
port?: number;
|
|
24
|
+
/** RabbitMQ username */
|
|
25
|
+
username?: string;
|
|
26
|
+
/** RabbitMQ password */
|
|
27
|
+
password?: string;
|
|
28
|
+
/** RabbitMQ virtual host (default: /) */
|
|
29
|
+
vhost?: string;
|
|
30
|
+
/** Connection name for identification (default: default) */
|
|
31
|
+
connectionName?: string;
|
|
32
|
+
/** Prefetch count for channels (default: 10) */
|
|
33
|
+
prefetch?: number;
|
|
34
|
+
/** Connection heartbeat in seconds (default: 60) */
|
|
35
|
+
heartbeat?: number;
|
|
36
|
+
/** Maximum reconnection attempts (0 = unlimited, default: 0) */
|
|
37
|
+
maxReconnectAttempts?: number;
|
|
38
|
+
/** Initial reconnection delay in ms (default: 1000) */
|
|
39
|
+
initialReconnectDelay?: number;
|
|
40
|
+
/** Maximum reconnection delay in ms (default: 60000) */
|
|
41
|
+
maxReconnectDelay?: number;
|
|
42
|
+
/** Logger instance (optional) */
|
|
43
|
+
logger?: AmqpLogger;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Connection status
|
|
47
|
+
*/
|
|
48
|
+
export declare enum ConnectionStatus {
|
|
49
|
+
DISCONNECTED = "disconnected",
|
|
50
|
+
CONNECTING = "connecting",
|
|
51
|
+
CONNECTED = "connected",
|
|
52
|
+
RECONNECTING = "reconnecting",
|
|
53
|
+
DEAD = "dead"
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Consumer options
|
|
57
|
+
*/
|
|
58
|
+
export interface ConsumerOptions {
|
|
59
|
+
/** Queue name to consume from */
|
|
60
|
+
queue: string;
|
|
61
|
+
/** Exchange to bind to */
|
|
62
|
+
exchange: string;
|
|
63
|
+
/** Routing keys for binding */
|
|
64
|
+
routingKeys: string[];
|
|
65
|
+
/** Prefetch count (default: 10) */
|
|
66
|
+
prefetch?: number;
|
|
67
|
+
/** Maximum number of retries (default: 3) */
|
|
68
|
+
maxRetries?: number;
|
|
69
|
+
/** Initial retry delay in ms (default: 1000) */
|
|
70
|
+
initialRetryDelay?: number;
|
|
71
|
+
/** Maximum retry delay in ms (default: 30000) */
|
|
72
|
+
maxRetryDelay?: number;
|
|
73
|
+
/** Whether to use circuit breaker (default: true) */
|
|
74
|
+
useCircuitBreaker?: boolean;
|
|
75
|
+
/** Circuit breaker failure threshold (default: 5) */
|
|
76
|
+
circuitBreakerThreshold?: number;
|
|
77
|
+
/** Exchange type (default: topic) */
|
|
78
|
+
exchangeType?: 'direct' | 'topic' | 'fanout' | 'headers';
|
|
79
|
+
/** Logger instance (optional, inherits from connection if not provided) */
|
|
80
|
+
logger?: AmqpLogger;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Message context passed to consumer handler
|
|
84
|
+
*/
|
|
85
|
+
export interface MessageContext {
|
|
86
|
+
/** Routing key */
|
|
87
|
+
routingKey: string;
|
|
88
|
+
/** Message ID */
|
|
89
|
+
messageId: string;
|
|
90
|
+
/** Correlation ID for tracing */
|
|
91
|
+
correlationId?: string;
|
|
92
|
+
/** Current retry count */
|
|
93
|
+
retryCount: number;
|
|
94
|
+
/** Timestamp when message was received */
|
|
95
|
+
receivedAt: Date;
|
|
96
|
+
/** Raw message headers */
|
|
97
|
+
headers: Record<string, unknown>;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Publisher options
|
|
101
|
+
*/
|
|
102
|
+
export interface PublisherOptions {
|
|
103
|
+
/** Exchange name to publish to */
|
|
104
|
+
exchange: string;
|
|
105
|
+
/** Exchange type (default: topic) */
|
|
106
|
+
exchangeType?: 'direct' | 'topic' | 'fanout' | 'headers';
|
|
107
|
+
/** Whether to use publisher confirms (default: true) */
|
|
108
|
+
confirm?: boolean;
|
|
109
|
+
/** Maximum number of publish retries (default: 3) */
|
|
110
|
+
maxRetries?: number;
|
|
111
|
+
/** Initial retry delay in ms (default: 100) */
|
|
112
|
+
initialRetryDelay?: number;
|
|
113
|
+
/** Maximum retry delay in ms (default: 5000) */
|
|
114
|
+
maxRetryDelay?: number;
|
|
115
|
+
/** Whether to use circuit breaker (default: true) */
|
|
116
|
+
useCircuitBreaker?: boolean;
|
|
117
|
+
/** Circuit breaker failure threshold (default: 5) */
|
|
118
|
+
circuitBreakerThreshold?: number;
|
|
119
|
+
/** Logger instance (optional, inherits from connection if not provided) */
|
|
120
|
+
logger?: AmqpLogger;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Publish options for individual messages
|
|
124
|
+
*/
|
|
125
|
+
export interface PublishOptions {
|
|
126
|
+
/** Correlation ID for message tracing */
|
|
127
|
+
correlationId?: string;
|
|
128
|
+
/** Message ID (auto-generated if not provided) */
|
|
129
|
+
messageId?: string;
|
|
130
|
+
/** Message priority (0-9, higher = more important) */
|
|
131
|
+
priority?: number;
|
|
132
|
+
/** Message expiration in milliseconds */
|
|
133
|
+
expiration?: string;
|
|
134
|
+
/** Custom headers */
|
|
135
|
+
headers?: Record<string, unknown>;
|
|
136
|
+
/** Whether message should be persistent (default: true) */
|
|
137
|
+
persistent?: boolean;
|
|
138
|
+
/** Reply-to queue for RPC patterns */
|
|
139
|
+
replyTo?: string;
|
|
140
|
+
/** Content type (default: application/json) */
|
|
141
|
+
contentType?: string;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Publish result
|
|
145
|
+
*/
|
|
146
|
+
export interface PublishResult {
|
|
147
|
+
/** Whether the publish was successful */
|
|
148
|
+
success: boolean;
|
|
149
|
+
/** Message ID */
|
|
150
|
+
messageId: string;
|
|
151
|
+
/** Correlation ID */
|
|
152
|
+
correlationId: string;
|
|
153
|
+
/** Number of retries needed */
|
|
154
|
+
retries: number;
|
|
155
|
+
/** Error if publish failed */
|
|
156
|
+
error?: Error;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Circuit breaker options
|
|
160
|
+
*/
|
|
161
|
+
export interface CircuitBreakerOptions {
|
|
162
|
+
/** Name for logging purposes */
|
|
163
|
+
name: string;
|
|
164
|
+
/** Number of failures before opening circuit (default: 5) */
|
|
165
|
+
failureThreshold?: number;
|
|
166
|
+
/** Time in ms to wait before attempting recovery (default: 30000) */
|
|
167
|
+
resetTimeout?: number;
|
|
168
|
+
/** Number of successful calls in half-open state before closing (default: 3) */
|
|
169
|
+
successThreshold?: number;
|
|
170
|
+
/** Time window in ms to count failures (default: 60000) */
|
|
171
|
+
failureWindow?: number;
|
|
172
|
+
/** Logger instance (optional) */
|
|
173
|
+
logger?: AmqpLogger;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Circuit breaker state
|
|
177
|
+
*/
|
|
178
|
+
export declare enum CircuitState {
|
|
179
|
+
CLOSED = "CLOSED",
|
|
180
|
+
OPEN = "OPEN",
|
|
181
|
+
HALF_OPEN = "HALF_OPEN"
|
|
182
|
+
}
|
|
183
|
+
export declare const noopLogger: AmqpLogger;
|
|
184
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,IAAI,CAAC,GAAG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AE,UAAU,CAAC;CACrB;AAED;;GAEG;AACH,oBAAY,YAAY;IACtB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,SAAS,cAAc;CACxB;AAOD,eAAO,MAAM,UAAU,EAAE,UAKxB,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for amqp-resilient
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Connection status
|
|
6
|
+
*/
|
|
7
|
+
export var ConnectionStatus;
|
|
8
|
+
(function (ConnectionStatus) {
|
|
9
|
+
ConnectionStatus["DISCONNECTED"] = "disconnected";
|
|
10
|
+
ConnectionStatus["CONNECTING"] = "connecting";
|
|
11
|
+
ConnectionStatus["CONNECTED"] = "connected";
|
|
12
|
+
ConnectionStatus["RECONNECTING"] = "reconnecting";
|
|
13
|
+
ConnectionStatus["DEAD"] = "dead";
|
|
14
|
+
})(ConnectionStatus || (ConnectionStatus = {}));
|
|
15
|
+
/**
|
|
16
|
+
* Circuit breaker state
|
|
17
|
+
*/
|
|
18
|
+
export var CircuitState;
|
|
19
|
+
(function (CircuitState) {
|
|
20
|
+
CircuitState["CLOSED"] = "CLOSED";
|
|
21
|
+
CircuitState["OPEN"] = "OPEN";
|
|
22
|
+
CircuitState["HALF_OPEN"] = "HALF_OPEN";
|
|
23
|
+
})(CircuitState || (CircuitState = {}));
|
|
24
|
+
/**
|
|
25
|
+
* No-op logger for when no logger is provided
|
|
26
|
+
*/
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
28
|
+
const noop = () => { };
|
|
29
|
+
export const noopLogger = {
|
|
30
|
+
info: noop,
|
|
31
|
+
warn: noop,
|
|
32
|
+
error: noop,
|
|
33
|
+
debug: noop,
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AA6CH;;GAEG;AACH,MAAM,CAAN,IAAY,gBAMX;AAND,WAAY,gBAAgB;IAC1B,iDAA6B,CAAA;IAC7B,6CAAyB,CAAA;IACzB,2CAAuB,CAAA;IACvB,iDAA6B,CAAA;IAC7B,iCAAa,CAAA;AACf,CAAC,EANW,gBAAgB,KAAhB,gBAAgB,QAM3B;AAgID;;GAEG;AACH,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,iCAAiB,CAAA;IACjB,6BAAa,CAAA;IACb,uCAAuB,CAAA;AACzB,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB;AAED;;GAEG;AACH,gEAAgE;AAChE,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AACtB,MAAM,CAAC,MAAM,UAAU,GAAe;IACpC,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;CACZ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "amqp-resilient",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Production-ready AMQP client with retry, reconnection, and resilience patterns for Node.js",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc -p tsconfig.build.json",
|
|
19
|
+
"dev": "tsc -p tsconfig.build.json --watch",
|
|
20
|
+
"test": "vitest run --exclude tests/integration.test.ts",
|
|
21
|
+
"test:unit": "vitest run --exclude tests/integration.test.ts",
|
|
22
|
+
"test:integration": "vitest run tests/integration.test.ts",
|
|
23
|
+
"test:all": "vitest run",
|
|
24
|
+
"test:watch": "vitest",
|
|
25
|
+
"test:coverage": "vitest run --coverage",
|
|
26
|
+
"lint": "eslint src",
|
|
27
|
+
"lint:fix": "eslint src --fix",
|
|
28
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
29
|
+
"format:check": "prettier --check \"src/**/*.ts\"",
|
|
30
|
+
"typecheck": "tsc --noEmit",
|
|
31
|
+
"prepare": "husky",
|
|
32
|
+
"prepublishOnly": "npm run lint && npm run typecheck && npm run test && npm run build"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"amqp",
|
|
36
|
+
"rabbitmq",
|
|
37
|
+
"queue",
|
|
38
|
+
"message-queue",
|
|
39
|
+
"resilient",
|
|
40
|
+
"retry",
|
|
41
|
+
"reconnection",
|
|
42
|
+
"circuit-breaker",
|
|
43
|
+
"consumer",
|
|
44
|
+
"publisher",
|
|
45
|
+
"microservices",
|
|
46
|
+
"typescript",
|
|
47
|
+
"nodejs"
|
|
48
|
+
],
|
|
49
|
+
"author": "berkeerdo",
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "git+https://github.com/berkeerdo/amqp-resilient.git"
|
|
54
|
+
},
|
|
55
|
+
"bugs": {
|
|
56
|
+
"url": "https://github.com/berkeerdo/amqp-resilient/issues"
|
|
57
|
+
},
|
|
58
|
+
"homepage": "https://github.com/berkeerdo/amqp-resilient#readme",
|
|
59
|
+
"engines": {
|
|
60
|
+
"node": ">=18.0.0"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"amqplib": ">=0.10.0"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@commitlint/cli": "^19.6.1",
|
|
67
|
+
"@commitlint/config-conventional": "^19.6.0",
|
|
68
|
+
"@eslint/js": "^9.18.0",
|
|
69
|
+
"@types/amqplib": "^0.10.5",
|
|
70
|
+
"@types/node": "^22.0.0",
|
|
71
|
+
"@vitest/coverage-v8": "^2.0.0",
|
|
72
|
+
"amqplib": "^0.10.5",
|
|
73
|
+
"eslint": "^9.18.0",
|
|
74
|
+
"husky": "^9.1.7",
|
|
75
|
+
"lint-staged": "^15.3.0",
|
|
76
|
+
"prettier": "^3.4.2",
|
|
77
|
+
"typescript": "^5.7.0",
|
|
78
|
+
"typescript-eslint": "^8.20.0",
|
|
79
|
+
"vitest": "^2.0.0"
|
|
80
|
+
}
|
|
81
|
+
}
|