@amqp-contract/worker 0.9.0 → 0.11.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/README.md +53 -34
- package/dist/index.cjs +205 -245
- package/dist/index.d.cts +136 -271
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +136 -271
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +205 -243
- package/dist/index.mjs.map +1 -1
- package/docs/index.md +123 -685
- package/package.json +8 -8
package/docs/index.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
### MessageValidationError
|
|
10
10
|
|
|
11
|
-
Defined in: [packages/worker/src/errors.ts:35](https://github.com/btravers/amqp-contract/blob/
|
|
11
|
+
Defined in: [packages/worker/src/errors.ts:35](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/errors.ts#L35)
|
|
12
12
|
|
|
13
13
|
Error thrown when message validation fails
|
|
14
14
|
|
|
@@ -24,7 +24,7 @@ Error thrown when message validation fails
|
|
|
24
24
|
new MessageValidationError(consumerName, issues): MessageValidationError;
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
Defined in: [packages/worker/src/errors.ts:36](https://github.com/btravers/amqp-contract/blob/
|
|
27
|
+
Defined in: [packages/worker/src/errors.ts:36](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/errors.ts#L36)
|
|
28
28
|
|
|
29
29
|
###### Parameters
|
|
30
30
|
|
|
@@ -48,12 +48,12 @@ WorkerError.constructor
|
|
|
48
48
|
| Property | Modifier | Type | Description | Inherited from | Defined in |
|
|
49
49
|
| ------ | ------ | ------ | ------ | ------ | ------ |
|
|
50
50
|
| <a id="cause"></a> `cause?` | `public` | `unknown` | - | `WorkerError.cause` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es2022.error.d.ts:26 |
|
|
51
|
-
| <a id="consumername"></a> `consumerName` | `readonly` | `string` | - | - | [packages/worker/src/errors.ts:37](https://github.com/btravers/amqp-contract/blob/
|
|
52
|
-
| <a id="issues"></a> `issues` | `readonly` | `unknown` | - | - | [packages/worker/src/errors.ts:38](https://github.com/btravers/amqp-contract/blob/
|
|
51
|
+
| <a id="consumername"></a> `consumerName` | `readonly` | `string` | - | - | [packages/worker/src/errors.ts:37](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/errors.ts#L37) |
|
|
52
|
+
| <a id="issues"></a> `issues` | `readonly` | `unknown` | - | - | [packages/worker/src/errors.ts:38](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/errors.ts#L38) |
|
|
53
53
|
| <a id="message"></a> `message` | `public` | `string` | - | `WorkerError.message` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1077 |
|
|
54
54
|
| <a id="name"></a> `name` | `public` | `string` | - | `WorkerError.name` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
|
|
55
55
|
| <a id="stack"></a> `stack?` | `public` | `string` | - | `WorkerError.stack` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1078 |
|
|
56
|
-
| <a id="stacktracelimit"></a> `stackTraceLimit` | `static` | `number` | The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | `WorkerError.stackTraceLimit` | node\_modules/.pnpm/@types+node@25.0.
|
|
56
|
+
| <a id="stacktracelimit"></a> `stackTraceLimit` | `static` | `number` | The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | `WorkerError.stackTraceLimit` | node\_modules/.pnpm/@types+node@25.0.9/node\_modules/@types/node/globals.d.ts:67 |
|
|
57
57
|
|
|
58
58
|
#### Methods
|
|
59
59
|
|
|
@@ -63,7 +63,7 @@ WorkerError.constructor
|
|
|
63
63
|
static captureStackTrace(targetObject, constructorOpt?): void;
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
Defined in: node\_modules/.pnpm/@types+node@25.0.
|
|
66
|
+
Defined in: node\_modules/.pnpm/@types+node@25.0.9/node\_modules/@types/node/globals.d.ts:51
|
|
67
67
|
|
|
68
68
|
Creates a `.stack` property on `targetObject`, which when accessed returns
|
|
69
69
|
a string representing the location in the code at which
|
|
@@ -132,7 +132,7 @@ WorkerError.captureStackTrace
|
|
|
132
132
|
static prepareStackTrace(err, stackTraces): any;
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
-
Defined in: node\_modules/.pnpm/@types+node@25.0.
|
|
135
|
+
Defined in: node\_modules/.pnpm/@types+node@25.0.9/node\_modules/@types/node/globals.d.ts:55
|
|
136
136
|
|
|
137
137
|
###### Parameters
|
|
138
138
|
|
|
@@ -159,7 +159,7 @@ WorkerError.prepareStackTrace
|
|
|
159
159
|
|
|
160
160
|
### NonRetryableError
|
|
161
161
|
|
|
162
|
-
Defined in: [packages/worker/src/errors.ts:69](https://github.com/btravers/amqp-contract/blob/
|
|
162
|
+
Defined in: [packages/worker/src/errors.ts:69](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/errors.ts#L69)
|
|
163
163
|
|
|
164
164
|
Non-retryable errors - permanent failures that should not be retried
|
|
165
165
|
Examples: invalid data, business rule violations, permanent external failures
|
|
@@ -179,7 +179,7 @@ immediately sent to the dead letter queue (DLQ) if configured.
|
|
|
179
179
|
new NonRetryableError(message, cause?): NonRetryableError;
|
|
180
180
|
```
|
|
181
181
|
|
|
182
|
-
Defined in: [packages/worker/src/errors.ts:70](https://github.com/btravers/amqp-contract/blob/
|
|
182
|
+
Defined in: [packages/worker/src/errors.ts:70](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/errors.ts#L70)
|
|
183
183
|
|
|
184
184
|
###### Parameters
|
|
185
185
|
|
|
@@ -202,11 +202,11 @@ WorkerError.constructor
|
|
|
202
202
|
|
|
203
203
|
| Property | Modifier | Type | Description | Inherited from | Defined in |
|
|
204
204
|
| ------ | ------ | ------ | ------ | ------ | ------ |
|
|
205
|
-
| <a id="cause-1"></a> `cause?` | `readonly` | `unknown` | - | `WorkerError.cause` | [packages/worker/src/errors.ts:72](https://github.com/btravers/amqp-contract/blob/
|
|
205
|
+
| <a id="cause-1"></a> `cause?` | `readonly` | `unknown` | - | `WorkerError.cause` | [packages/worker/src/errors.ts:72](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/errors.ts#L72) |
|
|
206
206
|
| <a id="message-1"></a> `message` | `public` | `string` | - | `WorkerError.message` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1077 |
|
|
207
207
|
| <a id="name-1"></a> `name` | `public` | `string` | - | `WorkerError.name` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
|
|
208
208
|
| <a id="stack-1"></a> `stack?` | `public` | `string` | - | `WorkerError.stack` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1078 |
|
|
209
|
-
| <a id="stacktracelimit-1"></a> `stackTraceLimit` | `static` | `number` | The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | `WorkerError.stackTraceLimit` | node\_modules/.pnpm/@types+node@25.0.
|
|
209
|
+
| <a id="stacktracelimit-1"></a> `stackTraceLimit` | `static` | `number` | The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | `WorkerError.stackTraceLimit` | node\_modules/.pnpm/@types+node@25.0.9/node\_modules/@types/node/globals.d.ts:67 |
|
|
210
210
|
|
|
211
211
|
#### Methods
|
|
212
212
|
|
|
@@ -216,7 +216,7 @@ WorkerError.constructor
|
|
|
216
216
|
static captureStackTrace(targetObject, constructorOpt?): void;
|
|
217
217
|
```
|
|
218
218
|
|
|
219
|
-
Defined in: node\_modules/.pnpm/@types+node@25.0.
|
|
219
|
+
Defined in: node\_modules/.pnpm/@types+node@25.0.9/node\_modules/@types/node/globals.d.ts:51
|
|
220
220
|
|
|
221
221
|
Creates a `.stack` property on `targetObject`, which when accessed returns
|
|
222
222
|
a string representing the location in the code at which
|
|
@@ -285,7 +285,7 @@ WorkerError.captureStackTrace
|
|
|
285
285
|
static prepareStackTrace(err, stackTraces): any;
|
|
286
286
|
```
|
|
287
287
|
|
|
288
|
-
Defined in: node\_modules/.pnpm/@types+node@25.0.
|
|
288
|
+
Defined in: node\_modules/.pnpm/@types+node@25.0.9/node\_modules/@types/node/globals.d.ts:55
|
|
289
289
|
|
|
290
290
|
###### Parameters
|
|
291
291
|
|
|
@@ -312,7 +312,7 @@ WorkerError.prepareStackTrace
|
|
|
312
312
|
|
|
313
313
|
### RetryableError
|
|
314
314
|
|
|
315
|
-
Defined in: [packages/worker/src/errors.ts:52](https://github.com/btravers/amqp-contract/blob/
|
|
315
|
+
Defined in: [packages/worker/src/errors.ts:52](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/errors.ts#L52)
|
|
316
316
|
|
|
317
317
|
Retryable errors - transient failures that may succeed on retry
|
|
318
318
|
Examples: network timeouts, rate limiting, temporary service unavailability
|
|
@@ -332,7 +332,7 @@ The worker will apply exponential backoff and retry the message.
|
|
|
332
332
|
new RetryableError(message, cause?): RetryableError;
|
|
333
333
|
```
|
|
334
334
|
|
|
335
|
-
Defined in: [packages/worker/src/errors.ts:53](https://github.com/btravers/amqp-contract/blob/
|
|
335
|
+
Defined in: [packages/worker/src/errors.ts:53](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/errors.ts#L53)
|
|
336
336
|
|
|
337
337
|
###### Parameters
|
|
338
338
|
|
|
@@ -355,11 +355,11 @@ WorkerError.constructor
|
|
|
355
355
|
|
|
356
356
|
| Property | Modifier | Type | Description | Inherited from | Defined in |
|
|
357
357
|
| ------ | ------ | ------ | ------ | ------ | ------ |
|
|
358
|
-
| <a id="cause-2"></a> `cause?` | `readonly` | `unknown` | - | `WorkerError.cause` | [packages/worker/src/errors.ts:55](https://github.com/btravers/amqp-contract/blob/
|
|
358
|
+
| <a id="cause-2"></a> `cause?` | `readonly` | `unknown` | - | `WorkerError.cause` | [packages/worker/src/errors.ts:55](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/errors.ts#L55) |
|
|
359
359
|
| <a id="message-2"></a> `message` | `public` | `string` | - | `WorkerError.message` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1077 |
|
|
360
360
|
| <a id="name-2"></a> `name` | `public` | `string` | - | `WorkerError.name` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
|
|
361
361
|
| <a id="stack-2"></a> `stack?` | `public` | `string` | - | `WorkerError.stack` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1078 |
|
|
362
|
-
| <a id="stacktracelimit-2"></a> `stackTraceLimit` | `static` | `number` | The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | `WorkerError.stackTraceLimit` | node\_modules/.pnpm/@types+node@25.0.
|
|
362
|
+
| <a id="stacktracelimit-2"></a> `stackTraceLimit` | `static` | `number` | The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | `WorkerError.stackTraceLimit` | node\_modules/.pnpm/@types+node@25.0.9/node\_modules/@types/node/globals.d.ts:67 |
|
|
363
363
|
|
|
364
364
|
#### Methods
|
|
365
365
|
|
|
@@ -369,7 +369,7 @@ WorkerError.constructor
|
|
|
369
369
|
static captureStackTrace(targetObject, constructorOpt?): void;
|
|
370
370
|
```
|
|
371
371
|
|
|
372
|
-
Defined in: node\_modules/.pnpm/@types+node@25.0.
|
|
372
|
+
Defined in: node\_modules/.pnpm/@types+node@25.0.9/node\_modules/@types/node/globals.d.ts:51
|
|
373
373
|
|
|
374
374
|
Creates a `.stack` property on `targetObject`, which when accessed returns
|
|
375
375
|
a string representing the location in the code at which
|
|
@@ -438,7 +438,7 @@ WorkerError.captureStackTrace
|
|
|
438
438
|
static prepareStackTrace(err, stackTraces): any;
|
|
439
439
|
```
|
|
440
440
|
|
|
441
|
-
Defined in: node\_modules/.pnpm/@types+node@25.0.
|
|
441
|
+
Defined in: node\_modules/.pnpm/@types+node@25.0.9/node\_modules/@types/node/globals.d.ts:55
|
|
442
442
|
|
|
443
443
|
###### Parameters
|
|
444
444
|
|
|
@@ -465,7 +465,7 @@ WorkerError.prepareStackTrace
|
|
|
465
465
|
|
|
466
466
|
### TechnicalError
|
|
467
467
|
|
|
468
|
-
Defined in: [packages/worker/src/errors.ts:22](https://github.com/btravers/amqp-contract/blob/
|
|
468
|
+
Defined in: [packages/worker/src/errors.ts:22](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/errors.ts#L22)
|
|
469
469
|
|
|
470
470
|
Error for technical/runtime failures in worker operations
|
|
471
471
|
This includes validation failures, parsing failures, and processing failures
|
|
@@ -482,7 +482,7 @@ This includes validation failures, parsing failures, and processing failures
|
|
|
482
482
|
new TechnicalError(message, cause?): TechnicalError;
|
|
483
483
|
```
|
|
484
484
|
|
|
485
|
-
Defined in: [packages/worker/src/errors.ts:23](https://github.com/btravers/amqp-contract/blob/
|
|
485
|
+
Defined in: [packages/worker/src/errors.ts:23](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/errors.ts#L23)
|
|
486
486
|
|
|
487
487
|
###### Parameters
|
|
488
488
|
|
|
@@ -505,11 +505,11 @@ WorkerError.constructor
|
|
|
505
505
|
|
|
506
506
|
| Property | Modifier | Type | Description | Inherited from | Defined in |
|
|
507
507
|
| ------ | ------ | ------ | ------ | ------ | ------ |
|
|
508
|
-
| <a id="cause-3"></a> `cause?` | `readonly` | `unknown` | - | `WorkerError.cause` | [packages/worker/src/errors.ts:25](https://github.com/btravers/amqp-contract/blob/
|
|
508
|
+
| <a id="cause-3"></a> `cause?` | `readonly` | `unknown` | - | `WorkerError.cause` | [packages/worker/src/errors.ts:25](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/errors.ts#L25) |
|
|
509
509
|
| <a id="message-3"></a> `message` | `public` | `string` | - | `WorkerError.message` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1077 |
|
|
510
510
|
| <a id="name-3"></a> `name` | `public` | `string` | - | `WorkerError.name` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
|
|
511
511
|
| <a id="stack-3"></a> `stack?` | `public` | `string` | - | `WorkerError.stack` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1078 |
|
|
512
|
-
| <a id="stacktracelimit-3"></a> `stackTraceLimit` | `static` | `number` | The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | `WorkerError.stackTraceLimit` | node\_modules/.pnpm/@types+node@25.0.
|
|
512
|
+
| <a id="stacktracelimit-3"></a> `stackTraceLimit` | `static` | `number` | The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | `WorkerError.stackTraceLimit` | node\_modules/.pnpm/@types+node@25.0.9/node\_modules/@types/node/globals.d.ts:67 |
|
|
513
513
|
|
|
514
514
|
#### Methods
|
|
515
515
|
|
|
@@ -519,7 +519,7 @@ WorkerError.constructor
|
|
|
519
519
|
static captureStackTrace(targetObject, constructorOpt?): void;
|
|
520
520
|
```
|
|
521
521
|
|
|
522
|
-
Defined in: node\_modules/.pnpm/@types+node@25.0.
|
|
522
|
+
Defined in: node\_modules/.pnpm/@types+node@25.0.9/node\_modules/@types/node/globals.d.ts:51
|
|
523
523
|
|
|
524
524
|
Creates a `.stack` property on `targetObject`, which when accessed returns
|
|
525
525
|
a string representing the location in the code at which
|
|
@@ -588,7 +588,7 @@ WorkerError.captureStackTrace
|
|
|
588
588
|
static prepareStackTrace(err, stackTraces): any;
|
|
589
589
|
```
|
|
590
590
|
|
|
591
|
-
Defined in: node\_modules/.pnpm/@types+node@25.0.
|
|
591
|
+
Defined in: node\_modules/.pnpm/@types+node@25.0.9/node\_modules/@types/node/globals.d.ts:55
|
|
592
592
|
|
|
593
593
|
###### Parameters
|
|
594
594
|
|
|
@@ -615,7 +615,7 @@ WorkerError.prepareStackTrace
|
|
|
615
615
|
|
|
616
616
|
### TypedAmqpWorker
|
|
617
617
|
|
|
618
|
-
Defined in: [packages/worker/src/worker.ts:
|
|
618
|
+
Defined in: [packages/worker/src/worker.ts:178](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/worker.ts#L178)
|
|
619
619
|
|
|
620
620
|
Type-safe AMQP worker for consuming messages from RabbitMQ.
|
|
621
621
|
|
|
@@ -669,7 +669,7 @@ await worker.close().resultToPromise();
|
|
|
669
669
|
close(): Future<Result<void, TechnicalError>>;
|
|
670
670
|
```
|
|
671
671
|
|
|
672
|
-
Defined in: [packages/worker/src/worker.ts:
|
|
672
|
+
Defined in: [packages/worker/src/worker.ts:299](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/worker.ts#L299)
|
|
673
673
|
|
|
674
674
|
Close the AMQP channel and connection.
|
|
675
675
|
|
|
@@ -697,7 +697,7 @@ if (closeResult.isOk()) {
|
|
|
697
697
|
static create<TContract>(options): Future<Result<TypedAmqpWorker<TContract>, TechnicalError>>;
|
|
698
698
|
```
|
|
699
699
|
|
|
700
|
-
Defined in: [packages/worker/src/worker.ts:
|
|
700
|
+
Defined in: [packages/worker/src/worker.ts:255](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/worker.ts#L255)
|
|
701
701
|
|
|
702
702
|
Create a type-safe AMQP worker from a contract.
|
|
703
703
|
|
|
@@ -733,7 +733,7 @@ A Future that resolves to a Result containing the worker or an error
|
|
|
733
733
|
const worker = await TypedAmqpWorker.create({
|
|
734
734
|
contract: myContract,
|
|
735
735
|
handlers: {
|
|
736
|
-
processOrder: async (
|
|
736
|
+
processOrder: async ({ payload }) => console.log('Order:', payload.orderId)
|
|
737
737
|
},
|
|
738
738
|
urls: ['amqp://localhost']
|
|
739
739
|
}).resultToPromise();
|
|
@@ -747,7 +747,7 @@ const worker = await TypedAmqpWorker.create({
|
|
|
747
747
|
type CreateWorkerOptions<TContract> = object;
|
|
748
748
|
```
|
|
749
749
|
|
|
750
|
-
Defined in: [packages/worker/src/worker.ts:
|
|
750
|
+
Defined in: [packages/worker/src/worker.ts:115](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/worker.ts#L115)
|
|
751
751
|
|
|
752
752
|
Options for creating a type-safe AMQP worker.
|
|
753
753
|
|
|
@@ -758,39 +758,30 @@ const options: CreateWorkerOptions<typeof contract> = {
|
|
|
758
758
|
contract: myContract,
|
|
759
759
|
handlers: {
|
|
760
760
|
// Simple handler
|
|
761
|
-
processOrder:
|
|
762
|
-
console.log('Processing order:',
|
|
761
|
+
processOrder: ({ payload }) => {
|
|
762
|
+
console.log('Processing order:', payload.orderId);
|
|
763
|
+
return Future.value(Result.Ok(undefined));
|
|
763
764
|
},
|
|
764
|
-
// Handler with
|
|
765
|
+
// Handler with prefetch configuration
|
|
765
766
|
processPayment: [
|
|
766
|
-
|
|
767
|
-
console.log('Processing payment:',
|
|
767
|
+
({ payload }) => {
|
|
768
|
+
console.log('Processing payment:', payload.paymentId);
|
|
769
|
+
return Future.value(Result.Ok(undefined));
|
|
768
770
|
},
|
|
769
771
|
{ prefetch: 10 }
|
|
770
|
-
],
|
|
771
|
-
// Handler with batch processing
|
|
772
|
-
processNotifications: [
|
|
773
|
-
async (messages) => {
|
|
774
|
-
console.log('Processing batch:', messages.length);
|
|
775
|
-
},
|
|
776
|
-
{ batchSize: 5, batchTimeout: 1000 }
|
|
777
772
|
]
|
|
778
773
|
},
|
|
779
774
|
urls: ['amqp://localhost'],
|
|
780
775
|
connectionOptions: {
|
|
781
776
|
heartbeatIntervalInSeconds: 30
|
|
782
777
|
},
|
|
783
|
-
logger: myLogger
|
|
784
|
-
retry: {
|
|
785
|
-
maxRetries: 3,
|
|
786
|
-
initialDelayMs: 1000,
|
|
787
|
-
maxDelayMs: 30000,
|
|
788
|
-
backoffMultiplier: 2,
|
|
789
|
-
jitter: true
|
|
790
|
-
}
|
|
778
|
+
logger: myLogger
|
|
791
779
|
};
|
|
792
780
|
```
|
|
793
781
|
|
|
782
|
+
Note: Retry configuration is defined at the queue level in the contract,
|
|
783
|
+
not at the handler level. See `QueueDefinition.retry` for configuration options.
|
|
784
|
+
|
|
794
785
|
#### Type Parameters
|
|
795
786
|
|
|
796
787
|
| Type Parameter | Description |
|
|
@@ -801,13 +792,12 @@ const options: CreateWorkerOptions<typeof contract> = {
|
|
|
801
792
|
|
|
802
793
|
| Property | Type | Description | Defined in |
|
|
803
794
|
| ------ | ------ | ------ | ------ |
|
|
804
|
-
| <a id="connectionoptions"></a> `connectionOptions?` | `AmqpConnectionManagerOptions` | Optional connection configuration (heartbeat, reconnect settings, etc.) | [packages/worker/src/worker.ts:
|
|
805
|
-
| <a id="contract"></a> `contract` | `TContract` | The AMQP contract definition specifying consumers and their message schemas | [packages/worker/src/worker.ts:
|
|
806
|
-
| <a id="handlers"></a> `handlers` | [`WorkerInferSafeConsumerHandlers`](#workerinfersafeconsumerhandlers)\<`TContract`\> | Handlers for each consumer defined in the contract. Handlers must return `Future<Result<void, HandlerError>>` for explicit error handling. Use defineHandler() to create
|
|
807
|
-
| <a id="logger"></a> `logger?` | `Logger` | Optional logger for logging message consumption and errors | [packages/worker/src/worker.ts:
|
|
808
|
-
| <a id="
|
|
809
|
-
| <a id="
|
|
810
|
-
| <a id="urls"></a> `urls` | `ConnectionUrl`[] | AMQP broker URL(s). Multiple URLs provide failover support | [packages/worker/src/worker.ts:135](https://github.com/btravers/amqp-contract/blob/f058a24938d9644a82812e57d7995cb683cfd6b5/packages/worker/src/worker.ts#L135) |
|
|
795
|
+
| <a id="connectionoptions"></a> `connectionOptions?` | `AmqpConnectionManagerOptions` | Optional connection configuration (heartbeat, reconnect settings, etc.) | [packages/worker/src/worker.ts:127](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/worker.ts#L127) |
|
|
796
|
+
| <a id="contract"></a> `contract` | `TContract` | The AMQP contract definition specifying consumers and their message schemas | [packages/worker/src/worker.ts:117](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/worker.ts#L117) |
|
|
797
|
+
| <a id="handlers"></a> `handlers` | [`WorkerInferSafeConsumerHandlers`](#workerinfersafeconsumerhandlers)\<`TContract`\> | Handlers for each consumer defined in the contract. Handlers must return `Future<Result<void, HandlerError>>` for explicit error handling. Use defineHandler() to create handlers. | [packages/worker/src/worker.ts:123](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/worker.ts#L123) |
|
|
798
|
+
| <a id="logger"></a> `logger?` | `Logger` | Optional logger for logging message consumption and errors | [packages/worker/src/worker.ts:129](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/worker.ts#L129) |
|
|
799
|
+
| <a id="telemetry"></a> `telemetry?` | `TelemetryProvider` | Optional telemetry provider for tracing and metrics. If not provided, uses the default provider which attempts to load OpenTelemetry. OpenTelemetry instrumentation is automatically enabled if @opentelemetry/api is installed. | [packages/worker/src/worker.ts:135](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/worker.ts#L135) |
|
|
800
|
+
| <a id="urls"></a> `urls` | `ConnectionUrl`[] | AMQP broker URL(s). Multiple URLs provide failover support | [packages/worker/src/worker.ts:125](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/worker.ts#L125) |
|
|
811
801
|
|
|
812
802
|
***
|
|
813
803
|
|
|
@@ -819,130 +809,64 @@ type HandlerError =
|
|
|
819
809
|
| NonRetryableError;
|
|
820
810
|
```
|
|
821
811
|
|
|
822
|
-
Defined in: [packages/worker/src/errors.ts:83](https://github.com/btravers/amqp-contract/blob/
|
|
812
|
+
Defined in: [packages/worker/src/errors.ts:83](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/errors.ts#L83)
|
|
823
813
|
|
|
824
814
|
Union type representing all handler errors.
|
|
825
815
|
Use this type when defining handlers that explicitly signal error outcomes.
|
|
826
816
|
|
|
827
817
|
***
|
|
828
818
|
|
|
829
|
-
###
|
|
819
|
+
### WorkerConsumedMessage
|
|
830
820
|
|
|
831
821
|
```ts
|
|
832
|
-
type
|
|
822
|
+
type WorkerConsumedMessage<TPayload, THeaders> = object;
|
|
833
823
|
```
|
|
834
824
|
|
|
835
|
-
Defined in: [packages/worker/src/
|
|
836
|
-
|
|
837
|
-
Retry configuration options for handling failed message processing.
|
|
838
|
-
|
|
839
|
-
When enabled, the worker will automatically retry failed messages using
|
|
840
|
-
RabbitMQ's native TTL + Dead Letter Exchange (DLX) pattern.
|
|
841
|
-
|
|
842
|
-
#### Properties
|
|
843
|
-
|
|
844
|
-
| Property | Type | Description | Defined in |
|
|
845
|
-
| ------ | ------ | ------ | ------ |
|
|
846
|
-
| <a id="backoffmultiplier"></a> `backoffMultiplier?` | `number` | Exponential backoff multiplier (default: 2) | [packages/worker/src/worker.ts:64](https://github.com/btravers/amqp-contract/blob/f058a24938d9644a82812e57d7995cb683cfd6b5/packages/worker/src/worker.ts#L64) |
|
|
847
|
-
| <a id="initialdelayms"></a> `initialDelayMs?` | `number` | Initial delay in ms before first retry (default: 1000) | [packages/worker/src/worker.ts:60](https://github.com/btravers/amqp-contract/blob/f058a24938d9644a82812e57d7995cb683cfd6b5/packages/worker/src/worker.ts#L60) |
|
|
848
|
-
| <a id="jitter"></a> `jitter?` | `boolean` | Add jitter to prevent thundering herd (default: true) | [packages/worker/src/worker.ts:66](https://github.com/btravers/amqp-contract/blob/f058a24938d9644a82812e57d7995cb683cfd6b5/packages/worker/src/worker.ts#L66) |
|
|
849
|
-
| <a id="maxdelayms"></a> `maxDelayMs?` | `number` | Maximum delay in ms between retries (default: 30000) | [packages/worker/src/worker.ts:62](https://github.com/btravers/amqp-contract/blob/f058a24938d9644a82812e57d7995cb683cfd6b5/packages/worker/src/worker.ts#L62) |
|
|
850
|
-
| <a id="maxretries"></a> `maxRetries?` | `number` | Maximum retry attempts before sending to DLQ (default: 3) | [packages/worker/src/worker.ts:58](https://github.com/btravers/amqp-contract/blob/f058a24938d9644a82812e57d7995cb683cfd6b5/packages/worker/src/worker.ts#L58) |
|
|
851
|
-
|
|
852
|
-
***
|
|
853
|
-
|
|
854
|
-
### ~~WorkerInferConsumerBatchHandler~~
|
|
855
|
-
|
|
856
|
-
```ts
|
|
857
|
-
type WorkerInferConsumerBatchHandler<TContract, TName> = WorkerInferUnsafeConsumerBatchHandler<TContract, TName>;
|
|
858
|
-
```
|
|
859
|
-
|
|
860
|
-
Defined in: [packages/worker/src/types.ts:195](https://github.com/btravers/amqp-contract/blob/f058a24938d9644a82812e57d7995cb683cfd6b5/packages/worker/src/types.ts#L195)
|
|
861
|
-
|
|
862
|
-
#### Type Parameters
|
|
863
|
-
|
|
864
|
-
| Type Parameter |
|
|
865
|
-
| ------ |
|
|
866
|
-
| `TContract` *extends* `ContractDefinition` |
|
|
867
|
-
| `TName` *extends* `InferConsumerNames`\<`TContract`\> |
|
|
868
|
-
|
|
869
|
-
#### Deprecated
|
|
870
|
-
|
|
871
|
-
Use WorkerInferUnsafeConsumerBatchHandler instead
|
|
872
|
-
|
|
873
|
-
***
|
|
874
|
-
|
|
875
|
-
### ~~WorkerInferConsumerHandler~~
|
|
876
|
-
|
|
877
|
-
```ts
|
|
878
|
-
type WorkerInferConsumerHandler<TContract, TName> = WorkerInferUnsafeConsumerHandler<TContract, TName>;
|
|
879
|
-
```
|
|
880
|
-
|
|
881
|
-
Defined in: [packages/worker/src/types.ts:187](https://github.com/btravers/amqp-contract/blob/f058a24938d9644a82812e57d7995cb683cfd6b5/packages/worker/src/types.ts#L187)
|
|
882
|
-
|
|
883
|
-
#### Type Parameters
|
|
884
|
-
|
|
885
|
-
| Type Parameter |
|
|
886
|
-
| ------ |
|
|
887
|
-
| `TContract` *extends* `ContractDefinition` |
|
|
888
|
-
| `TName` *extends* `InferConsumerNames`\<`TContract`\> |
|
|
889
|
-
|
|
890
|
-
#### Deprecated
|
|
891
|
-
|
|
892
|
-
Use WorkerInferUnsafeConsumerHandler instead
|
|
893
|
-
|
|
894
|
-
***
|
|
895
|
-
|
|
896
|
-
### ~~WorkerInferConsumerHandlerEntry~~
|
|
897
|
-
|
|
898
|
-
```ts
|
|
899
|
-
type WorkerInferConsumerHandlerEntry<TContract, TName> = WorkerInferUnsafeConsumerHandlerEntry<TContract, TName>;
|
|
900
|
-
```
|
|
901
|
-
|
|
902
|
-
Defined in: [packages/worker/src/types.ts:203](https://github.com/btravers/amqp-contract/blob/f058a24938d9644a82812e57d7995cb683cfd6b5/packages/worker/src/types.ts#L203)
|
|
903
|
-
|
|
904
|
-
#### Type Parameters
|
|
905
|
-
|
|
906
|
-
| Type Parameter |
|
|
907
|
-
| ------ |
|
|
908
|
-
| `TContract` *extends* `ContractDefinition` |
|
|
909
|
-
| `TName` *extends* `InferConsumerNames`\<`TContract`\> |
|
|
825
|
+
Defined in: [packages/worker/src/types.ts:86](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/types.ts#L86)
|
|
910
826
|
|
|
911
|
-
|
|
827
|
+
A consumed message containing parsed payload and headers.
|
|
912
828
|
|
|
913
|
-
|
|
829
|
+
This type represents the first argument passed to consumer handlers.
|
|
830
|
+
It contains the validated payload and (if defined in the message schema) the validated headers.
|
|
914
831
|
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
### ~~WorkerInferConsumerHandlers~~
|
|
832
|
+
#### Example
|
|
918
833
|
|
|
919
|
-
```
|
|
920
|
-
|
|
834
|
+
```typescript
|
|
835
|
+
// Handler receives the consumed message with typed payload and headers
|
|
836
|
+
const handler = defineHandler(contract, 'processOrder', (message, rawMessage) => {
|
|
837
|
+
console.log(message.payload.orderId); // Typed payload
|
|
838
|
+
console.log(message.headers?.priority); // Typed headers (if defined)
|
|
839
|
+
console.log(rawMessage.fields.deliveryTag); // Raw AMQP message
|
|
840
|
+
return Future.value(Result.Ok(undefined));
|
|
841
|
+
});
|
|
921
842
|
```
|
|
922
843
|
|
|
923
|
-
Defined in: [packages/worker/src/types.ts:211](https://github.com/btravers/amqp-contract/blob/f058a24938d9644a82812e57d7995cb683cfd6b5/packages/worker/src/types.ts#L211)
|
|
924
|
-
|
|
925
844
|
#### Type Parameters
|
|
926
845
|
|
|
927
|
-
| Type Parameter |
|
|
928
|
-
| ------ |
|
|
929
|
-
| `
|
|
846
|
+
| Type Parameter | Default type | Description |
|
|
847
|
+
| ------ | ------ | ------ |
|
|
848
|
+
| `TPayload` | - | The inferred payload type from the message schema |
|
|
849
|
+
| `THeaders` | `undefined` | The inferred headers type from the message schema (undefined if not defined) |
|
|
930
850
|
|
|
931
|
-
####
|
|
851
|
+
#### Properties
|
|
932
852
|
|
|
933
|
-
|
|
853
|
+
| Property | Type | Description | Defined in |
|
|
854
|
+
| ------ | ------ | ------ | ------ |
|
|
855
|
+
| <a id="headers"></a> `headers` | `THeaders` *extends* `undefined` ? `undefined` : `THeaders` | The validated message headers (present only when headers schema is defined) | [packages/worker/src/types.ts:90](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/types.ts#L90) |
|
|
856
|
+
| <a id="payload"></a> `payload` | `TPayload` | The validated message payload | [packages/worker/src/types.ts:88](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/types.ts#L88) |
|
|
934
857
|
|
|
935
858
|
***
|
|
936
859
|
|
|
937
|
-
###
|
|
860
|
+
### WorkerInferConsumedMessage
|
|
938
861
|
|
|
939
862
|
```ts
|
|
940
|
-
type
|
|
863
|
+
type WorkerInferConsumedMessage<TContract, TName> = WorkerConsumedMessage<WorkerInferConsumerPayload<TContract, TName>, WorkerInferConsumerHeaders<TContract, TName>>;
|
|
941
864
|
```
|
|
942
865
|
|
|
943
|
-
Defined in: [packages/worker/src/types.ts:
|
|
866
|
+
Defined in: [packages/worker/src/types.ts:97](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/types.ts#L97)
|
|
944
867
|
|
|
945
|
-
|
|
868
|
+
Infer the full consumed message type for a specific consumer.
|
|
869
|
+
Includes both payload and headers (if defined).
|
|
946
870
|
|
|
947
871
|
#### Type Parameters
|
|
948
872
|
|
|
@@ -953,16 +877,16 @@ Worker perspective types - for consuming messages
|
|
|
953
877
|
|
|
954
878
|
***
|
|
955
879
|
|
|
956
|
-
###
|
|
880
|
+
### WorkerInferConsumerHeaders
|
|
957
881
|
|
|
958
882
|
```ts
|
|
959
|
-
type
|
|
883
|
+
type WorkerInferConsumerHeaders<TContract, TName> = ConsumerInferHeadersInput<InferConsumer<TContract, TName>>;
|
|
960
884
|
```
|
|
961
885
|
|
|
962
|
-
Defined in: [packages/worker/src/types.ts:
|
|
886
|
+
Defined in: [packages/worker/src/types.ts:61](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/types.ts#L61)
|
|
963
887
|
|
|
964
|
-
|
|
965
|
-
Returns
|
|
888
|
+
Infer the headers type for a specific consumer
|
|
889
|
+
Returns undefined if no headers schema is defined
|
|
966
890
|
|
|
967
891
|
#### Type Parameters
|
|
968
892
|
|
|
@@ -971,32 +895,15 @@ Returns a `Future<Result<void, HandlerError>>` for explicit error handling.
|
|
|
971
895
|
| `TContract` *extends* `ContractDefinition` |
|
|
972
896
|
| `TName` *extends* `InferConsumerNames`\<`TContract`\> |
|
|
973
897
|
|
|
974
|
-
#### Parameters
|
|
975
|
-
|
|
976
|
-
| Parameter | Type |
|
|
977
|
-
| ------ | ------ |
|
|
978
|
-
| `messages` | [`WorkerInferConsumerInput`](#workerinferconsumerinput)\<`TContract`, `TName`\>[] |
|
|
979
|
-
|
|
980
|
-
#### Returns
|
|
981
|
-
|
|
982
|
-
`Future`\<`Result`\<`void`, [`HandlerError`](#handlererror)\>\>
|
|
983
|
-
|
|
984
|
-
#### Example
|
|
985
|
-
|
|
986
|
-
```typescript
|
|
987
|
-
const handler: WorkerInferSafeConsumerBatchHandler<typeof contract, 'processOrders'> =
|
|
988
|
-
(messages) => Future.value(Result.Ok(undefined));
|
|
989
|
-
```
|
|
990
|
-
|
|
991
898
|
***
|
|
992
899
|
|
|
993
900
|
### WorkerInferSafeConsumerHandler()
|
|
994
901
|
|
|
995
902
|
```ts
|
|
996
|
-
type WorkerInferSafeConsumerHandler<TContract, TName> = (message) => Future<Result<void, HandlerError>>;
|
|
903
|
+
type WorkerInferSafeConsumerHandler<TContract, TName> = (message, rawMessage) => Future<Result<void, HandlerError>>;
|
|
997
904
|
```
|
|
998
905
|
|
|
999
|
-
Defined in: [packages/worker/src/types.ts:
|
|
906
|
+
Defined in: [packages/worker/src/types.ts:133](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/types.ts#L133)
|
|
1000
907
|
|
|
1001
908
|
Safe consumer handler type for a specific consumer.
|
|
1002
909
|
Returns a `Future<Result<void, HandlerError>>` for explicit error handling.
|
|
@@ -1014,9 +921,10 @@ Returns a `Future<Result<void, HandlerError>>` for explicit error handling.
|
|
|
1014
921
|
|
|
1015
922
|
#### Parameters
|
|
1016
923
|
|
|
1017
|
-
| Parameter | Type |
|
|
1018
|
-
| ------ | ------ |
|
|
1019
|
-
| `message` | [`
|
|
924
|
+
| Parameter | Type | Description |
|
|
925
|
+
| ------ | ------ | ------ |
|
|
926
|
+
| `message` | [`WorkerInferConsumedMessage`](#workerinferconsumedmessage)\<`TContract`, `TName`\> | The parsed message containing validated payload and headers |
|
|
927
|
+
| `rawMessage` | `ConsumeMessage` | The raw AMQP message with all metadata (fields, properties, content) |
|
|
1020
928
|
|
|
1021
929
|
#### Returns
|
|
1022
930
|
|
|
@@ -1026,7 +934,11 @@ Returns a `Future<Result<void, HandlerError>>` for explicit error handling.
|
|
|
1026
934
|
|
|
1027
935
|
```typescript
|
|
1028
936
|
const handler: WorkerInferSafeConsumerHandler<typeof contract, 'processOrder'> =
|
|
1029
|
-
(
|
|
937
|
+
({ payload }, rawMessage) => {
|
|
938
|
+
console.log(payload.orderId); // Typed payload
|
|
939
|
+
console.log(rawMessage.fields.deliveryTag); // Raw AMQP message
|
|
940
|
+
return Future.value(Result.Ok(undefined));
|
|
941
|
+
};
|
|
1030
942
|
```
|
|
1031
943
|
|
|
1032
944
|
***
|
|
@@ -1037,25 +949,20 @@ const handler: WorkerInferSafeConsumerHandler<typeof contract, 'processOrder'> =
|
|
|
1037
949
|
type WorkerInferSafeConsumerHandlerEntry<TContract, TName> =
|
|
1038
950
|
| WorkerInferSafeConsumerHandler<TContract, TName>
|
|
1039
951
|
| readonly [WorkerInferSafeConsumerHandler<TContract, TName>, {
|
|
1040
|
-
batchSize?: never;
|
|
1041
|
-
batchTimeout?: never;
|
|
1042
|
-
prefetch?: number;
|
|
1043
|
-
}]
|
|
1044
|
-
| readonly [WorkerInferSafeConsumerBatchHandler<TContract, TName>, {
|
|
1045
|
-
batchSize: number;
|
|
1046
|
-
batchTimeout?: number;
|
|
1047
952
|
prefetch?: number;
|
|
1048
953
|
}];
|
|
1049
954
|
```
|
|
1050
955
|
|
|
1051
|
-
Defined in: [packages/worker/src/types.ts:
|
|
956
|
+
Defined in: [packages/worker/src/types.ts:151](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/types.ts#L151)
|
|
1052
957
|
|
|
1053
958
|
Safe handler entry for a consumer - either a function or a tuple of [handler, options].
|
|
1054
959
|
|
|
1055
|
-
|
|
1056
|
-
1. Simple handler: `(
|
|
1057
|
-
2. Handler with prefetch: `[(
|
|
1058
|
-
|
|
960
|
+
Two patterns are supported:
|
|
961
|
+
1. Simple handler: `({ payload }, rawMessage) => Future.value(Result.Ok(undefined))`
|
|
962
|
+
2. Handler with prefetch: `[({ payload }, rawMessage) => ..., { prefetch: 10 }]`
|
|
963
|
+
|
|
964
|
+
Note: Retry configuration is now defined at the queue level in the contract,
|
|
965
|
+
not at the handler level. See `QueueDefinition.retry` for configuration options.
|
|
1059
966
|
|
|
1060
967
|
#### Type Parameters
|
|
1061
968
|
|
|
@@ -1072,7 +979,7 @@ Three patterns are supported:
|
|
|
1072
979
|
type WorkerInferSafeConsumerHandlers<TContract> = { [K in InferConsumerNames<TContract>]: WorkerInferSafeConsumerHandlerEntry<TContract, K> };
|
|
1073
980
|
```
|
|
1074
981
|
|
|
1075
|
-
Defined in: [packages/worker/src/types.ts:
|
|
982
|
+
Defined in: [packages/worker/src/types.ts:162](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/types.ts#L162)
|
|
1076
983
|
|
|
1077
984
|
Safe consumer handlers for a contract.
|
|
1078
985
|
All handlers return `Future<Result<void, HandlerError>>` for explicit error control.
|
|
@@ -1083,136 +990,6 @@ All handlers return `Future<Result<void, HandlerError>>` for explicit error cont
|
|
|
1083
990
|
| ------ |
|
|
1084
991
|
| `TContract` *extends* `ContractDefinition` |
|
|
1085
992
|
|
|
1086
|
-
***
|
|
1087
|
-
|
|
1088
|
-
### ~~WorkerInferUnsafeConsumerBatchHandler()~~
|
|
1089
|
-
|
|
1090
|
-
```ts
|
|
1091
|
-
type WorkerInferUnsafeConsumerBatchHandler<TContract, TName> = (messages) => Promise<void>;
|
|
1092
|
-
```
|
|
1093
|
-
|
|
1094
|
-
Defined in: [packages/worker/src/types.ts:147](https://github.com/btravers/amqp-contract/blob/f058a24938d9644a82812e57d7995cb683cfd6b5/packages/worker/src/types.ts#L147)
|
|
1095
|
-
|
|
1096
|
-
Unsafe consumer handler type for batch processing.
|
|
1097
|
-
Returns a `Promise<void>` - throws exceptions on error.
|
|
1098
|
-
|
|
1099
|
-
#### Type Parameters
|
|
1100
|
-
|
|
1101
|
-
| Type Parameter |
|
|
1102
|
-
| ------ |
|
|
1103
|
-
| `TContract` *extends* `ContractDefinition` |
|
|
1104
|
-
| `TName` *extends* `InferConsumerNames`\<`TContract`\> |
|
|
1105
|
-
|
|
1106
|
-
#### Parameters
|
|
1107
|
-
|
|
1108
|
-
| Parameter | Type |
|
|
1109
|
-
| ------ | ------ |
|
|
1110
|
-
| `messages` | [`WorkerInferConsumerInput`](#workerinferconsumerinput)\<`TContract`, `TName`\>[] |
|
|
1111
|
-
|
|
1112
|
-
#### Returns
|
|
1113
|
-
|
|
1114
|
-
`Promise`\<`void`\>
|
|
1115
|
-
|
|
1116
|
-
#### Deprecated
|
|
1117
|
-
|
|
1118
|
-
Prefer using safe handlers (WorkerInferSafeConsumerBatchHandler) that return
|
|
1119
|
-
`Future<Result<void, HandlerError>>` for better error handling.
|
|
1120
|
-
|
|
1121
|
-
***
|
|
1122
|
-
|
|
1123
|
-
### ~~WorkerInferUnsafeConsumerHandler()~~
|
|
1124
|
-
|
|
1125
|
-
```ts
|
|
1126
|
-
type WorkerInferUnsafeConsumerHandler<TContract, TName> = (message) => Promise<void>;
|
|
1127
|
-
```
|
|
1128
|
-
|
|
1129
|
-
Defined in: [packages/worker/src/types.ts:135](https://github.com/btravers/amqp-contract/blob/f058a24938d9644a82812e57d7995cb683cfd6b5/packages/worker/src/types.ts#L135)
|
|
1130
|
-
|
|
1131
|
-
Unsafe consumer handler type for a specific consumer.
|
|
1132
|
-
Returns a `Promise<void>` - throws exceptions on error.
|
|
1133
|
-
|
|
1134
|
-
#### Type Parameters
|
|
1135
|
-
|
|
1136
|
-
| Type Parameter |
|
|
1137
|
-
| ------ |
|
|
1138
|
-
| `TContract` *extends* `ContractDefinition` |
|
|
1139
|
-
| `TName` *extends* `InferConsumerNames`\<`TContract`\> |
|
|
1140
|
-
|
|
1141
|
-
#### Parameters
|
|
1142
|
-
|
|
1143
|
-
| Parameter | Type |
|
|
1144
|
-
| ------ | ------ |
|
|
1145
|
-
| `message` | [`WorkerInferConsumerInput`](#workerinferconsumerinput)\<`TContract`, `TName`\> |
|
|
1146
|
-
|
|
1147
|
-
#### Returns
|
|
1148
|
-
|
|
1149
|
-
`Promise`\<`void`\>
|
|
1150
|
-
|
|
1151
|
-
#### Deprecated
|
|
1152
|
-
|
|
1153
|
-
Prefer using safe handlers (WorkerInferSafeConsumerHandler) that return
|
|
1154
|
-
`Future<Result<void, HandlerError>>` for better error handling.
|
|
1155
|
-
|
|
1156
|
-
**Note:** When using unsafe handlers:
|
|
1157
|
-
- All thrown errors are treated as retryable by default (when retry is configured)
|
|
1158
|
-
- Use RetryableError or NonRetryableError to control retry behavior explicitly
|
|
1159
|
-
|
|
1160
|
-
***
|
|
1161
|
-
|
|
1162
|
-
### ~~WorkerInferUnsafeConsumerHandlerEntry~~
|
|
1163
|
-
|
|
1164
|
-
```ts
|
|
1165
|
-
type WorkerInferUnsafeConsumerHandlerEntry<TContract, TName> =
|
|
1166
|
-
| WorkerInferUnsafeConsumerHandler<TContract, TName>
|
|
1167
|
-
| readonly [WorkerInferUnsafeConsumerHandler<TContract, TName>, {
|
|
1168
|
-
batchSize?: never;
|
|
1169
|
-
batchTimeout?: never;
|
|
1170
|
-
prefetch?: number;
|
|
1171
|
-
}]
|
|
1172
|
-
| readonly [WorkerInferUnsafeConsumerBatchHandler<TContract, TName>, {
|
|
1173
|
-
batchSize: number;
|
|
1174
|
-
batchTimeout?: number;
|
|
1175
|
-
prefetch?: number;
|
|
1176
|
-
}];
|
|
1177
|
-
```
|
|
1178
|
-
|
|
1179
|
-
Defined in: [packages/worker/src/types.ts:157](https://github.com/btravers/amqp-contract/blob/f058a24938d9644a82812e57d7995cb683cfd6b5/packages/worker/src/types.ts#L157)
|
|
1180
|
-
|
|
1181
|
-
Unsafe handler entry for a consumer - either a function or a tuple of [handler, options].
|
|
1182
|
-
|
|
1183
|
-
#### Type Parameters
|
|
1184
|
-
|
|
1185
|
-
| Type Parameter |
|
|
1186
|
-
| ------ |
|
|
1187
|
-
| `TContract` *extends* `ContractDefinition` |
|
|
1188
|
-
| `TName` *extends* `InferConsumerNames`\<`TContract`\> |
|
|
1189
|
-
|
|
1190
|
-
#### Deprecated
|
|
1191
|
-
|
|
1192
|
-
Prefer using safe handler entries (WorkerInferSafeConsumerHandlerEntry).
|
|
1193
|
-
|
|
1194
|
-
***
|
|
1195
|
-
|
|
1196
|
-
### ~~WorkerInferUnsafeConsumerHandlers~~
|
|
1197
|
-
|
|
1198
|
-
```ts
|
|
1199
|
-
type WorkerInferUnsafeConsumerHandlers<TContract> = { [K in InferConsumerNames<TContract>]: WorkerInferUnsafeConsumerHandlerEntry<TContract, K> };
|
|
1200
|
-
```
|
|
1201
|
-
|
|
1202
|
-
Defined in: [packages/worker/src/types.ts:176](https://github.com/btravers/amqp-contract/blob/f058a24938d9644a82812e57d7995cb683cfd6b5/packages/worker/src/types.ts#L176)
|
|
1203
|
-
|
|
1204
|
-
Unsafe consumer handlers for a contract.
|
|
1205
|
-
|
|
1206
|
-
#### Type Parameters
|
|
1207
|
-
|
|
1208
|
-
| Type Parameter |
|
|
1209
|
-
| ------ |
|
|
1210
|
-
| `TContract` *extends* `ContractDefinition` |
|
|
1211
|
-
|
|
1212
|
-
#### Deprecated
|
|
1213
|
-
|
|
1214
|
-
Prefer using safe handlers (WorkerInferSafeConsumerHandlers).
|
|
1215
|
-
|
|
1216
993
|
## Functions
|
|
1217
994
|
|
|
1218
995
|
### defineHandler()
|
|
@@ -1226,17 +1003,16 @@ function defineHandler<TContract, TName>(
|
|
|
1226
1003
|
handler): WorkerInferSafeConsumerHandlerEntry<TContract, TName>;
|
|
1227
1004
|
```
|
|
1228
1005
|
|
|
1229
|
-
Defined in: [packages/worker/src/handlers.ts:
|
|
1006
|
+
Defined in: [packages/worker/src/handlers.ts:103](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/handlers.ts#L103)
|
|
1230
1007
|
|
|
1231
1008
|
Define a type-safe handler for a specific consumer in a contract.
|
|
1232
1009
|
|
|
1233
1010
|
**Recommended:** This function creates handlers that return `Future<Result<void, HandlerError>>`,
|
|
1234
1011
|
providing explicit error handling and better control over retry behavior.
|
|
1235
1012
|
|
|
1236
|
-
Supports
|
|
1237
|
-
1. Simple handler: just the function
|
|
1238
|
-
2. Handler with
|
|
1239
|
-
3. Batch handler: [batchHandler, { batchSize: 5, batchTimeout: 1000 }] (REQUIRES batchSize config)
|
|
1013
|
+
Supports two patterns:
|
|
1014
|
+
1. Simple handler: just the function
|
|
1015
|
+
2. Handler with options: [handler, { prefetch: 10 }]
|
|
1240
1016
|
|
|
1241
1017
|
##### Type Parameters
|
|
1242
1018
|
|
|
@@ -1270,8 +1046,8 @@ import { orderContract } from './contract';
|
|
|
1270
1046
|
const processOrderHandler = defineHandler(
|
|
1271
1047
|
orderContract,
|
|
1272
1048
|
'processOrder',
|
|
1273
|
-
(
|
|
1274
|
-
Future.fromPromise(processPayment(
|
|
1049
|
+
({ payload }) =>
|
|
1050
|
+
Future.fromPromise(processPayment(payload))
|
|
1275
1051
|
.mapOk(() => undefined)
|
|
1276
1052
|
.mapError((error) => new RetryableError('Payment failed', error))
|
|
1277
1053
|
);
|
|
@@ -1280,8 +1056,8 @@ const processOrderHandler = defineHandler(
|
|
|
1280
1056
|
const validateOrderHandler = defineHandler(
|
|
1281
1057
|
orderContract,
|
|
1282
1058
|
'validateOrder',
|
|
1283
|
-
(
|
|
1284
|
-
if (
|
|
1059
|
+
({ payload }) => {
|
|
1060
|
+
if (payload.amount < 1) {
|
|
1285
1061
|
// Won't be retried - goes directly to DLQ
|
|
1286
1062
|
return Future.value(Result.Error(new NonRetryableError('Invalid order amount')));
|
|
1287
1063
|
}
|
|
@@ -1300,17 +1076,16 @@ function defineHandler<TContract, TName>(
|
|
|
1300
1076
|
options): WorkerInferSafeConsumerHandlerEntry<TContract, TName>;
|
|
1301
1077
|
```
|
|
1302
1078
|
|
|
1303
|
-
Defined in: [packages/worker/src/handlers.ts:
|
|
1079
|
+
Defined in: [packages/worker/src/handlers.ts:111](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/handlers.ts#L111)
|
|
1304
1080
|
|
|
1305
1081
|
Define a type-safe handler for a specific consumer in a contract.
|
|
1306
1082
|
|
|
1307
1083
|
**Recommended:** This function creates handlers that return `Future<Result<void, HandlerError>>`,
|
|
1308
1084
|
providing explicit error handling and better control over retry behavior.
|
|
1309
1085
|
|
|
1310
|
-
Supports
|
|
1311
|
-
1. Simple handler: just the function
|
|
1312
|
-
2. Handler with
|
|
1313
|
-
3. Batch handler: [batchHandler, { batchSize: 5, batchTimeout: 1000 }] (REQUIRES batchSize config)
|
|
1086
|
+
Supports two patterns:
|
|
1087
|
+
1. Simple handler: just the function
|
|
1088
|
+
2. Handler with options: [handler, { prefetch: 10 }]
|
|
1314
1089
|
|
|
1315
1090
|
##### Type Parameters
|
|
1316
1091
|
|
|
@@ -1326,9 +1101,7 @@ Supports three patterns:
|
|
|
1326
1101
|
| `contract` | `TContract` | The contract definition containing the consumer |
|
|
1327
1102
|
| `consumerName` | `TName` | The name of the consumer from the contract |
|
|
1328
1103
|
| `handler` | [`WorkerInferSafeConsumerHandler`](#workerinfersafeconsumerhandler)\<`TContract`, `TName`\> | The handler function that returns `Future<Result<void, HandlerError>>` |
|
|
1329
|
-
| `options` | \{ `
|
|
1330
|
-
| `options.batchSize?` | `undefined` | - |
|
|
1331
|
-
| `options.batchTimeout?` | `undefined` | - |
|
|
1104
|
+
| `options` | \{ `prefetch?`: `number`; \} | Optional consumer options (prefetch) |
|
|
1332
1105
|
| `options.prefetch?` | `number` | - |
|
|
1333
1106
|
|
|
1334
1107
|
##### Returns
|
|
@@ -1348,8 +1121,8 @@ import { orderContract } from './contract';
|
|
|
1348
1121
|
const processOrderHandler = defineHandler(
|
|
1349
1122
|
orderContract,
|
|
1350
1123
|
'processOrder',
|
|
1351
|
-
(
|
|
1352
|
-
Future.fromPromise(processPayment(
|
|
1124
|
+
({ payload }) =>
|
|
1125
|
+
Future.fromPromise(processPayment(payload))
|
|
1353
1126
|
.mapOk(() => undefined)
|
|
1354
1127
|
.mapError((error) => new RetryableError('Payment failed', error))
|
|
1355
1128
|
);
|
|
@@ -1358,86 +1131,8 @@ const processOrderHandler = defineHandler(
|
|
|
1358
1131
|
const validateOrderHandler = defineHandler(
|
|
1359
1132
|
orderContract,
|
|
1360
1133
|
'validateOrder',
|
|
1361
|
-
(
|
|
1362
|
-
if (
|
|
1363
|
-
// Won't be retried - goes directly to DLQ
|
|
1364
|
-
return Future.value(Result.Error(new NonRetryableError('Invalid order amount')));
|
|
1365
|
-
}
|
|
1366
|
-
return Future.value(Result.Ok(undefined));
|
|
1367
|
-
}
|
|
1368
|
-
);
|
|
1369
|
-
```
|
|
1370
|
-
|
|
1371
|
-
#### Call Signature
|
|
1372
|
-
|
|
1373
|
-
```ts
|
|
1374
|
-
function defineHandler<TContract, TName>(
|
|
1375
|
-
contract,
|
|
1376
|
-
consumerName,
|
|
1377
|
-
handler,
|
|
1378
|
-
options): WorkerInferSafeConsumerHandlerEntry<TContract, TName>;
|
|
1379
|
-
```
|
|
1380
|
-
|
|
1381
|
-
Defined in: [packages/worker/src/handlers.ts:151](https://github.com/btravers/amqp-contract/blob/f058a24938d9644a82812e57d7995cb683cfd6b5/packages/worker/src/handlers.ts#L151)
|
|
1382
|
-
|
|
1383
|
-
Define a type-safe handler for a specific consumer in a contract.
|
|
1384
|
-
|
|
1385
|
-
**Recommended:** This function creates handlers that return `Future<Result<void, HandlerError>>`,
|
|
1386
|
-
providing explicit error handling and better control over retry behavior.
|
|
1387
|
-
|
|
1388
|
-
Supports three patterns:
|
|
1389
|
-
1. Simple handler: just the function (single message handler)
|
|
1390
|
-
2. Handler with prefetch: [handler, { prefetch: 10 }] (single message handler with config)
|
|
1391
|
-
3. Batch handler: [batchHandler, { batchSize: 5, batchTimeout: 1000 }] (REQUIRES batchSize config)
|
|
1392
|
-
|
|
1393
|
-
##### Type Parameters
|
|
1394
|
-
|
|
1395
|
-
| Type Parameter | Description |
|
|
1396
|
-
| ------ | ------ |
|
|
1397
|
-
| `TContract` *extends* `ContractDefinition` | The contract definition type |
|
|
1398
|
-
| `TName` *extends* `string` \| `number` \| `symbol` | The consumer name from the contract |
|
|
1399
|
-
|
|
1400
|
-
##### Parameters
|
|
1401
|
-
|
|
1402
|
-
| Parameter | Type | Description |
|
|
1403
|
-
| ------ | ------ | ------ |
|
|
1404
|
-
| `contract` | `TContract` | The contract definition containing the consumer |
|
|
1405
|
-
| `consumerName` | `TName` | The name of the consumer from the contract |
|
|
1406
|
-
| `handler` | [`WorkerInferSafeConsumerBatchHandler`](#workerinfersafeconsumerbatchhandler)\<`TContract`, `TName`\> | The handler function that returns `Future<Result<void, HandlerError>>` |
|
|
1407
|
-
| `options` | \{ `batchSize`: `number`; `batchTimeout?`: `number`; `prefetch?`: `number`; \} | Optional consumer options (prefetch, batchSize, batchTimeout) |
|
|
1408
|
-
| `options.batchSize` | `number` | - |
|
|
1409
|
-
| `options.batchTimeout?` | `number` | - |
|
|
1410
|
-
| `options.prefetch?` | `number` | - |
|
|
1411
|
-
|
|
1412
|
-
##### Returns
|
|
1413
|
-
|
|
1414
|
-
[`WorkerInferSafeConsumerHandlerEntry`](#workerinfersafeconsumerhandlerentry)\<`TContract`, `TName`\>
|
|
1415
|
-
|
|
1416
|
-
A type-safe handler that can be used with TypedAmqpWorker
|
|
1417
|
-
|
|
1418
|
-
##### Example
|
|
1419
|
-
|
|
1420
|
-
```typescript
|
|
1421
|
-
import { defineHandler, RetryableError, NonRetryableError } from '@amqp-contract/worker';
|
|
1422
|
-
import { Future, Result } from '@swan-io/boxed';
|
|
1423
|
-
import { orderContract } from './contract';
|
|
1424
|
-
|
|
1425
|
-
// Simple handler with explicit error handling using mapError
|
|
1426
|
-
const processOrderHandler = defineHandler(
|
|
1427
|
-
orderContract,
|
|
1428
|
-
'processOrder',
|
|
1429
|
-
(message) =>
|
|
1430
|
-
Future.fromPromise(processPayment(message))
|
|
1431
|
-
.mapOk(() => undefined)
|
|
1432
|
-
.mapError((error) => new RetryableError('Payment failed', error))
|
|
1433
|
-
);
|
|
1434
|
-
|
|
1435
|
-
// Handler with validation (non-retryable error)
|
|
1436
|
-
const validateOrderHandler = defineHandler(
|
|
1437
|
-
orderContract,
|
|
1438
|
-
'validateOrder',
|
|
1439
|
-
(message) => {
|
|
1440
|
-
if (message.amount < 1) {
|
|
1134
|
+
({ payload }) => {
|
|
1135
|
+
if (payload.amount < 1) {
|
|
1441
1136
|
// Won't be retried - goes directly to DLQ
|
|
1442
1137
|
return Future.value(Result.Error(new NonRetryableError('Invalid order amount')));
|
|
1443
1138
|
}
|
|
@@ -1454,7 +1149,7 @@ const validateOrderHandler = defineHandler(
|
|
|
1454
1149
|
function defineHandlers<TContract>(contract, handlers): WorkerInferSafeConsumerHandlers<TContract>;
|
|
1455
1150
|
```
|
|
1456
1151
|
|
|
1457
|
-
Defined in: [packages/worker/src/handlers.ts:
|
|
1152
|
+
Defined in: [packages/worker/src/handlers.ts:166](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/handlers.ts#L166)
|
|
1458
1153
|
|
|
1459
1154
|
Define multiple type-safe handlers for consumers in a contract.
|
|
1460
1155
|
|
|
@@ -1488,270 +1183,13 @@ import { Future } from '@swan-io/boxed';
|
|
|
1488
1183
|
import { orderContract } from './contract';
|
|
1489
1184
|
|
|
1490
1185
|
const handlers = defineHandlers(orderContract, {
|
|
1491
|
-
processOrder: (
|
|
1492
|
-
Future.fromPromise(processPayment(
|
|
1186
|
+
processOrder: ({ payload }) =>
|
|
1187
|
+
Future.fromPromise(processPayment(payload))
|
|
1493
1188
|
.mapOk(() => undefined)
|
|
1494
1189
|
.mapError((error) => new RetryableError('Payment failed', error)),
|
|
1495
|
-
notifyOrder: (
|
|
1496
|
-
Future.fromPromise(sendNotification(
|
|
1190
|
+
notifyOrder: ({ payload }) =>
|
|
1191
|
+
Future.fromPromise(sendNotification(payload))
|
|
1497
1192
|
.mapOk(() => undefined)
|
|
1498
1193
|
.mapError((error) => new RetryableError('Notification failed', error)),
|
|
1499
1194
|
});
|
|
1500
1195
|
```
|
|
1501
|
-
|
|
1502
|
-
***
|
|
1503
|
-
|
|
1504
|
-
### ~~defineUnsafeHandler()~~
|
|
1505
|
-
|
|
1506
|
-
#### Call Signature
|
|
1507
|
-
|
|
1508
|
-
```ts
|
|
1509
|
-
function defineUnsafeHandler<TContract, TName>(
|
|
1510
|
-
contract,
|
|
1511
|
-
consumerName,
|
|
1512
|
-
handler): WorkerInferSafeConsumerHandlerEntry<TContract, TName>;
|
|
1513
|
-
```
|
|
1514
|
-
|
|
1515
|
-
Defined in: [packages/worker/src/handlers.ts:272](https://github.com/btravers/amqp-contract/blob/f058a24938d9644a82812e57d7995cb683cfd6b5/packages/worker/src/handlers.ts#L272)
|
|
1516
|
-
|
|
1517
|
-
Define an unsafe handler for a specific consumer in a contract.
|
|
1518
|
-
|
|
1519
|
-
##### Type Parameters
|
|
1520
|
-
|
|
1521
|
-
| Type Parameter | Description |
|
|
1522
|
-
| ------ | ------ |
|
|
1523
|
-
| `TContract` *extends* `ContractDefinition` | The contract definition type |
|
|
1524
|
-
| `TName` *extends* `string` \| `number` \| `symbol` | The consumer name from the contract |
|
|
1525
|
-
|
|
1526
|
-
##### Parameters
|
|
1527
|
-
|
|
1528
|
-
| Parameter | Type | Description |
|
|
1529
|
-
| ------ | ------ | ------ |
|
|
1530
|
-
| `contract` | `TContract` | The contract definition containing the consumer |
|
|
1531
|
-
| `consumerName` | `TName` | The name of the consumer from the contract |
|
|
1532
|
-
| `handler` | `UnsafeHandler`\<`TContract`, `TName`\> | The async handler function that processes messages |
|
|
1533
|
-
|
|
1534
|
-
##### Returns
|
|
1535
|
-
|
|
1536
|
-
[`WorkerInferSafeConsumerHandlerEntry`](#workerinfersafeconsumerhandlerentry)\<`TContract`, `TName`\>
|
|
1537
|
-
|
|
1538
|
-
A type-safe handler that can be used with TypedAmqpWorker
|
|
1539
|
-
|
|
1540
|
-
##### Deprecated
|
|
1541
|
-
|
|
1542
|
-
Use `defineHandler` instead for explicit error handling with `Future<Result>`.
|
|
1543
|
-
|
|
1544
|
-
**Warning:** Unsafe handlers use exception-based error handling:
|
|
1545
|
-
- All thrown errors are treated as retryable by default
|
|
1546
|
-
- Harder to reason about which errors should be retried
|
|
1547
|
-
- May lead to unexpected retry behavior
|
|
1548
|
-
|
|
1549
|
-
**Note:** Internally, this function wraps the Promise-based handler into a Future-based
|
|
1550
|
-
safe handler for consistent processing in the worker.
|
|
1551
|
-
|
|
1552
|
-
##### Example
|
|
1553
|
-
|
|
1554
|
-
```typescript
|
|
1555
|
-
import { defineUnsafeHandler } from '@amqp-contract/worker';
|
|
1556
|
-
|
|
1557
|
-
// ⚠️ Consider using defineHandler for better error handling
|
|
1558
|
-
const processOrderHandler = defineUnsafeHandler(
|
|
1559
|
-
orderContract,
|
|
1560
|
-
'processOrder',
|
|
1561
|
-
async (message) => {
|
|
1562
|
-
// Throws on error - will be retried
|
|
1563
|
-
await processPayment(message);
|
|
1564
|
-
}
|
|
1565
|
-
);
|
|
1566
|
-
```
|
|
1567
|
-
|
|
1568
|
-
#### Call Signature
|
|
1569
|
-
|
|
1570
|
-
```ts
|
|
1571
|
-
function defineUnsafeHandler<TContract, TName>(
|
|
1572
|
-
contract,
|
|
1573
|
-
consumerName,
|
|
1574
|
-
handler,
|
|
1575
|
-
options): WorkerInferSafeConsumerHandlerEntry<TContract, TName>;
|
|
1576
|
-
```
|
|
1577
|
-
|
|
1578
|
-
Defined in: [packages/worker/src/handlers.ts:280](https://github.com/btravers/amqp-contract/blob/f058a24938d9644a82812e57d7995cb683cfd6b5/packages/worker/src/handlers.ts#L280)
|
|
1579
|
-
|
|
1580
|
-
Define an unsafe handler for a specific consumer in a contract.
|
|
1581
|
-
|
|
1582
|
-
##### Type Parameters
|
|
1583
|
-
|
|
1584
|
-
| Type Parameter | Description |
|
|
1585
|
-
| ------ | ------ |
|
|
1586
|
-
| `TContract` *extends* `ContractDefinition` | The contract definition type |
|
|
1587
|
-
| `TName` *extends* `string` \| `number` \| `symbol` | The consumer name from the contract |
|
|
1588
|
-
|
|
1589
|
-
##### Parameters
|
|
1590
|
-
|
|
1591
|
-
| Parameter | Type | Description |
|
|
1592
|
-
| ------ | ------ | ------ |
|
|
1593
|
-
| `contract` | `TContract` | The contract definition containing the consumer |
|
|
1594
|
-
| `consumerName` | `TName` | The name of the consumer from the contract |
|
|
1595
|
-
| `handler` | `UnsafeHandler`\<`TContract`, `TName`\> | The async handler function that processes messages |
|
|
1596
|
-
| `options` | \{ `batchSize?`: `undefined`; `batchTimeout?`: `undefined`; `prefetch?`: `number`; \} | Optional consumer options (prefetch, batchSize, batchTimeout) |
|
|
1597
|
-
| `options.batchSize?` | `undefined` | - |
|
|
1598
|
-
| `options.batchTimeout?` | `undefined` | - |
|
|
1599
|
-
| `options.prefetch?` | `number` | - |
|
|
1600
|
-
|
|
1601
|
-
##### Returns
|
|
1602
|
-
|
|
1603
|
-
[`WorkerInferSafeConsumerHandlerEntry`](#workerinfersafeconsumerhandlerentry)\<`TContract`, `TName`\>
|
|
1604
|
-
|
|
1605
|
-
A type-safe handler that can be used with TypedAmqpWorker
|
|
1606
|
-
|
|
1607
|
-
##### Deprecated
|
|
1608
|
-
|
|
1609
|
-
Use `defineHandler` instead for explicit error handling with `Future<Result>`.
|
|
1610
|
-
|
|
1611
|
-
**Warning:** Unsafe handlers use exception-based error handling:
|
|
1612
|
-
- All thrown errors are treated as retryable by default
|
|
1613
|
-
- Harder to reason about which errors should be retried
|
|
1614
|
-
- May lead to unexpected retry behavior
|
|
1615
|
-
|
|
1616
|
-
**Note:** Internally, this function wraps the Promise-based handler into a Future-based
|
|
1617
|
-
safe handler for consistent processing in the worker.
|
|
1618
|
-
|
|
1619
|
-
##### Example
|
|
1620
|
-
|
|
1621
|
-
```typescript
|
|
1622
|
-
import { defineUnsafeHandler } from '@amqp-contract/worker';
|
|
1623
|
-
|
|
1624
|
-
// ⚠️ Consider using defineHandler for better error handling
|
|
1625
|
-
const processOrderHandler = defineUnsafeHandler(
|
|
1626
|
-
orderContract,
|
|
1627
|
-
'processOrder',
|
|
1628
|
-
async (message) => {
|
|
1629
|
-
// Throws on error - will be retried
|
|
1630
|
-
await processPayment(message);
|
|
1631
|
-
}
|
|
1632
|
-
);
|
|
1633
|
-
```
|
|
1634
|
-
|
|
1635
|
-
#### Call Signature
|
|
1636
|
-
|
|
1637
|
-
```ts
|
|
1638
|
-
function defineUnsafeHandler<TContract, TName>(
|
|
1639
|
-
contract,
|
|
1640
|
-
consumerName,
|
|
1641
|
-
handler,
|
|
1642
|
-
options): WorkerInferSafeConsumerHandlerEntry<TContract, TName>;
|
|
1643
|
-
```
|
|
1644
|
-
|
|
1645
|
-
Defined in: [packages/worker/src/handlers.ts:289](https://github.com/btravers/amqp-contract/blob/f058a24938d9644a82812e57d7995cb683cfd6b5/packages/worker/src/handlers.ts#L289)
|
|
1646
|
-
|
|
1647
|
-
Define an unsafe handler for a specific consumer in a contract.
|
|
1648
|
-
|
|
1649
|
-
##### Type Parameters
|
|
1650
|
-
|
|
1651
|
-
| Type Parameter | Description |
|
|
1652
|
-
| ------ | ------ |
|
|
1653
|
-
| `TContract` *extends* `ContractDefinition` | The contract definition type |
|
|
1654
|
-
| `TName` *extends* `string` \| `number` \| `symbol` | The consumer name from the contract |
|
|
1655
|
-
|
|
1656
|
-
##### Parameters
|
|
1657
|
-
|
|
1658
|
-
| Parameter | Type | Description |
|
|
1659
|
-
| ------ | ------ | ------ |
|
|
1660
|
-
| `contract` | `TContract` | The contract definition containing the consumer |
|
|
1661
|
-
| `consumerName` | `TName` | The name of the consumer from the contract |
|
|
1662
|
-
| `handler` | `UnsafeBatchHandler`\<`TContract`, `TName`\> | The async handler function that processes messages |
|
|
1663
|
-
| `options` | \{ `batchSize`: `number`; `batchTimeout?`: `number`; `prefetch?`: `number`; \} | Optional consumer options (prefetch, batchSize, batchTimeout) |
|
|
1664
|
-
| `options.batchSize` | `number` | - |
|
|
1665
|
-
| `options.batchTimeout?` | `number` | - |
|
|
1666
|
-
| `options.prefetch?` | `number` | - |
|
|
1667
|
-
|
|
1668
|
-
##### Returns
|
|
1669
|
-
|
|
1670
|
-
[`WorkerInferSafeConsumerHandlerEntry`](#workerinfersafeconsumerhandlerentry)\<`TContract`, `TName`\>
|
|
1671
|
-
|
|
1672
|
-
A type-safe handler that can be used with TypedAmqpWorker
|
|
1673
|
-
|
|
1674
|
-
##### Deprecated
|
|
1675
|
-
|
|
1676
|
-
Use `defineHandler` instead for explicit error handling with `Future<Result>`.
|
|
1677
|
-
|
|
1678
|
-
**Warning:** Unsafe handlers use exception-based error handling:
|
|
1679
|
-
- All thrown errors are treated as retryable by default
|
|
1680
|
-
- Harder to reason about which errors should be retried
|
|
1681
|
-
- May lead to unexpected retry behavior
|
|
1682
|
-
|
|
1683
|
-
**Note:** Internally, this function wraps the Promise-based handler into a Future-based
|
|
1684
|
-
safe handler for consistent processing in the worker.
|
|
1685
|
-
|
|
1686
|
-
##### Example
|
|
1687
|
-
|
|
1688
|
-
```typescript
|
|
1689
|
-
import { defineUnsafeHandler } from '@amqp-contract/worker';
|
|
1690
|
-
|
|
1691
|
-
// ⚠️ Consider using defineHandler for better error handling
|
|
1692
|
-
const processOrderHandler = defineUnsafeHandler(
|
|
1693
|
-
orderContract,
|
|
1694
|
-
'processOrder',
|
|
1695
|
-
async (message) => {
|
|
1696
|
-
// Throws on error - will be retried
|
|
1697
|
-
await processPayment(message);
|
|
1698
|
-
}
|
|
1699
|
-
);
|
|
1700
|
-
```
|
|
1701
|
-
|
|
1702
|
-
***
|
|
1703
|
-
|
|
1704
|
-
### ~~defineUnsafeHandlers()~~
|
|
1705
|
-
|
|
1706
|
-
```ts
|
|
1707
|
-
function defineUnsafeHandlers<TContract>(contract, handlers): WorkerInferSafeConsumerHandlers<TContract>;
|
|
1708
|
-
```
|
|
1709
|
-
|
|
1710
|
-
Defined in: [packages/worker/src/handlers.ts:373](https://github.com/btravers/amqp-contract/blob/f058a24938d9644a82812e57d7995cb683cfd6b5/packages/worker/src/handlers.ts#L373)
|
|
1711
|
-
|
|
1712
|
-
Define multiple unsafe handlers for consumers in a contract.
|
|
1713
|
-
|
|
1714
|
-
#### Type Parameters
|
|
1715
|
-
|
|
1716
|
-
| Type Parameter | Description |
|
|
1717
|
-
| ------ | ------ |
|
|
1718
|
-
| `TContract` *extends* `ContractDefinition` | The contract definition type |
|
|
1719
|
-
|
|
1720
|
-
#### Parameters
|
|
1721
|
-
|
|
1722
|
-
| Parameter | Type | Description |
|
|
1723
|
-
| ------ | ------ | ------ |
|
|
1724
|
-
| `contract` | `TContract` | The contract definition containing the consumers |
|
|
1725
|
-
| `handlers` | `UnsafeHandlers`\<`TContract`\> | An object with async handler functions for each consumer |
|
|
1726
|
-
|
|
1727
|
-
#### Returns
|
|
1728
|
-
|
|
1729
|
-
[`WorkerInferSafeConsumerHandlers`](#workerinfersafeconsumerhandlers)\<`TContract`\>
|
|
1730
|
-
|
|
1731
|
-
A type-safe handlers object that can be used with TypedAmqpWorker
|
|
1732
|
-
|
|
1733
|
-
#### Deprecated
|
|
1734
|
-
|
|
1735
|
-
Use `defineHandlers` instead for explicit error handling with `Future<Result>`.
|
|
1736
|
-
|
|
1737
|
-
**Warning:** Unsafe handlers use exception-based error handling.
|
|
1738
|
-
Consider migrating to safe handlers for better error control.
|
|
1739
|
-
|
|
1740
|
-
**Note:** Internally, this function wraps all Promise-based handlers into Future-based
|
|
1741
|
-
safe handlers for consistent processing in the worker.
|
|
1742
|
-
|
|
1743
|
-
#### Example
|
|
1744
|
-
|
|
1745
|
-
```typescript
|
|
1746
|
-
import { defineUnsafeHandlers } from '@amqp-contract/worker';
|
|
1747
|
-
|
|
1748
|
-
// ⚠️ Consider using defineHandlers for better error handling
|
|
1749
|
-
const handlers = defineUnsafeHandlers(orderContract, {
|
|
1750
|
-
processOrder: async (message) => {
|
|
1751
|
-
await processPayment(message);
|
|
1752
|
-
},
|
|
1753
|
-
notifyOrder: async (message) => {
|
|
1754
|
-
await sendNotification(message);
|
|
1755
|
-
},
|
|
1756
|
-
});
|
|
1757
|
-
```
|