@amqp-contract/contract 0.10.0 → 0.12.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/dist/index.cjs +344 -92
- package/dist/index.d.cts +658 -123
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +658 -123
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +342 -92
- package/dist/index.mjs.map +1 -1
- package/docs/index.md +562 -102
- package/package.json +4 -4
package/docs/index.md
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
type AnySchema = StandardSchemaV1;
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
Defined in: [types.ts:12](https://github.com/btravers/amqp-contract/blob/
|
|
15
|
+
Defined in: [types.ts:12](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L12)
|
|
16
16
|
|
|
17
17
|
Any schema that conforms to Standard Schema v1.
|
|
18
18
|
|
|
@@ -32,7 +32,7 @@ https://github.com/standard-schema/standard-schema
|
|
|
32
32
|
type BaseExchangeDefinition = object;
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
Defined in: [types.ts:
|
|
35
|
+
Defined in: [types.ts:376](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L376)
|
|
36
36
|
|
|
37
37
|
Base definition of an AMQP exchange.
|
|
38
38
|
|
|
@@ -43,11 +43,11 @@ type and routing rules. This type contains properties common to all exchange typ
|
|
|
43
43
|
|
|
44
44
|
| Property | Type | Description | Defined in |
|
|
45
45
|
| ------ | ------ | ------ | ------ |
|
|
46
|
-
| <a id="arguments"></a> `arguments?` | `Record
|
|
47
|
-
| <a id="autodelete"></a> `autoDelete?` | `boolean` | If true, the exchange is deleted when all queues have finished using it. **Default** `false` | [types.ts:
|
|
48
|
-
| <a id="durable"></a> `durable?` | `boolean` | If true, the exchange survives broker restarts. Durable exchanges are persisted to disk. **Default** `false` | [types.ts:
|
|
49
|
-
| <a id="internal"></a> `internal?` | `boolean` | If true, the exchange cannot be directly published to by clients. It can only receive messages from other exchanges via exchange-to-exchange bindings. **Default** `false` | [types.ts:
|
|
50
|
-
| <a id="name"></a> `name` | `string` | The name of the exchange. Must be unique within the RabbitMQ virtual host. | [types.ts:
|
|
46
|
+
| <a id="arguments"></a> `arguments?` | `Record`<`string`, `unknown`> | Additional AMQP arguments for advanced configuration. Common arguments include alternate-exchange for handling unroutable messages. | [types.ts:405](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L405) |
|
|
47
|
+
| <a id="autodelete"></a> `autoDelete?` | `boolean` | If true, the exchange is deleted when all queues have finished using it. **Default** `false` | [types.ts:392](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L392) |
|
|
48
|
+
| <a id="durable"></a> `durable?` | `boolean` | If true, the exchange survives broker restarts. Durable exchanges are persisted to disk. **Default** `false` | [types.ts:386](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L386) |
|
|
49
|
+
| <a id="internal"></a> `internal?` | `boolean` | If true, the exchange cannot be directly published to by clients. It can only receive messages from other exchanges via exchange-to-exchange bindings. **Default** `false` | [types.ts:399](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L399) |
|
|
50
|
+
| <a id="name"></a> `name` | `string` | The name of the exchange. Must be unique within the RabbitMQ virtual host. | [types.ts:380](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L380) |
|
|
51
51
|
|
|
52
52
|
***
|
|
53
53
|
|
|
@@ -59,7 +59,7 @@ type BindingDefinition =
|
|
|
59
59
|
| ExchangeBindingDefinition;
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
Defined in: [types.ts:
|
|
62
|
+
Defined in: [types.ts:815](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L815)
|
|
63
63
|
|
|
64
64
|
Union type of all binding definitions.
|
|
65
65
|
|
|
@@ -75,7 +75,7 @@ A binding can be either:
|
|
|
75
75
|
type BindingPattern<S> = S extends "" ? never : S;
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
Defined in: [builder.ts:
|
|
78
|
+
Defined in: [builder/routing-types.ts:52](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/routing-types.ts#L52)
|
|
79
79
|
|
|
80
80
|
Type-safe binding pattern that validates basic format and wildcards.
|
|
81
81
|
|
|
@@ -104,13 +104,73 @@ type Invalid = BindingPattern<"">; // never (empty string)
|
|
|
104
104
|
|
|
105
105
|
***
|
|
106
106
|
|
|
107
|
+
### ClassicQueueDefinition
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
type ClassicQueueDefinition = BaseQueueDefinition & object;
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Defined in: [types.ts:592](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L592)
|
|
114
|
+
|
|
115
|
+
Definition of a classic queue.
|
|
116
|
+
|
|
117
|
+
Classic queues are the traditional RabbitMQ queue type. Use them when you need
|
|
118
|
+
specific features not supported by quorum queues (e.g., exclusive queues, priority queues).
|
|
119
|
+
|
|
120
|
+
#### Type Declaration
|
|
121
|
+
|
|
122
|
+
| Name | Type | Description | Defined in |
|
|
123
|
+
| ------ | ------ | ------ | ------ |
|
|
124
|
+
| `deliveryLimit?` | `never` | Classic queues do not support delivery limits. Use type: 'quorum' if you need native retry with delivery limits. | [types.ts:602](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L602) |
|
|
125
|
+
| `exclusive?` | `boolean` | If true, the queue can only be used by the declaring connection and is deleted when that connection closes. Exclusive queues are private to the connection. **Default** `false` | [types.ts:609](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L609) |
|
|
126
|
+
| `retry` | `ResolvedTtlBackoffRetryOptions` | Retry configuration for handling failed message processing. Classic queues only support TTL-backoff retry mode (default). When the queue is created, defaults are applied. | [types.ts:617](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L617) |
|
|
127
|
+
| `type` | `"classic"` | Queue type discriminator: classic queue. | [types.ts:596](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L596) |
|
|
128
|
+
|
|
129
|
+
***
|
|
130
|
+
|
|
131
|
+
### ClassicQueueOptions
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
type ClassicQueueOptions = BaseQueueOptions & object;
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Defined in: [types.ts:318](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L318)
|
|
138
|
+
|
|
139
|
+
Options for creating a classic queue.
|
|
140
|
+
|
|
141
|
+
Classic queues support all traditional RabbitMQ features including:
|
|
142
|
+
- `exclusive: true` - For connection-scoped queues
|
|
143
|
+
- `maxPriority` - For priority queues
|
|
144
|
+
- `durable: false` - For non-durable queues
|
|
145
|
+
|
|
146
|
+
#### Type Declaration
|
|
147
|
+
|
|
148
|
+
| Name | Type | Description | Defined in |
|
|
149
|
+
| ------ | ------ | ------ | ------ |
|
|
150
|
+
| `exclusive?` | `boolean` | If true, the queue can only be used by the declaring connection and is deleted when that connection closes. Exclusive queues are private to the connection. **Default** `false` | [types.ts:329](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L329) |
|
|
151
|
+
| `maxPriority?` | `number` | Maximum priority level for priority queue (1-255, recommended: 1-10). Sets x-max-priority argument. Only supported with classic queues. | [types.ts:336](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L336) |
|
|
152
|
+
| `retry?` | [`TtlBackoffRetryOptions`](#ttlbackoffretryoptions) | Retry configuration for handling failed message processing. Classic queues only support TTL-backoff retry mode, which uses wait queues with exponential backoff. For quorum-native retry, use quorum queues instead. **Example** `const orderQueue = defineQueue('order-processing', { type: 'classic', durable: true, deadLetter: { exchange: dlx }, retry: { maxRetries: 5, initialDelayMs: 1000, maxDelayMs: 30000, }, });` | [types.ts:358](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L358) |
|
|
153
|
+
| `type` | `"classic"` | Queue type: classic (for special cases) | [types.ts:322](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L322) |
|
|
154
|
+
|
|
155
|
+
#### Example
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
const priorityQueue = defineQueue('tasks', {
|
|
159
|
+
type: 'classic',
|
|
160
|
+
durable: true,
|
|
161
|
+
maxPriority: 10,
|
|
162
|
+
});
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
***
|
|
166
|
+
|
|
107
167
|
### CompressionAlgorithm
|
|
108
168
|
|
|
109
169
|
```ts
|
|
110
170
|
type CompressionAlgorithm = "gzip" | "deflate";
|
|
111
171
|
```
|
|
112
172
|
|
|
113
|
-
Defined in: [types.ts:
|
|
173
|
+
Defined in: [types.ts:134](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L134)
|
|
114
174
|
|
|
115
175
|
Supported compression algorithms for message payloads.
|
|
116
176
|
|
|
@@ -148,7 +208,7 @@ await client.publish("orderCreated", payload, {
|
|
|
148
208
|
type ConsumerDefinition<TMessage> = object;
|
|
149
209
|
```
|
|
150
210
|
|
|
151
|
-
Defined in: [types.ts:
|
|
211
|
+
Defined in: [types.ts:876](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L876)
|
|
152
212
|
|
|
153
213
|
Definition of a message consumer.
|
|
154
214
|
|
|
@@ -176,8 +236,8 @@ const consumer: ConsumerDefinition = {
|
|
|
176
236
|
|
|
177
237
|
| Property | Type | Description | Defined in |
|
|
178
238
|
| ------ | ------ | ------ | ------ |
|
|
179
|
-
| <a id="message"></a> `message` | `TMessage` | The message definition including the payload schema | [types.ts:
|
|
180
|
-
| <a id="queue"></a> `queue` | [`QueueDefinition`](#queuedefinition) | The queue to consume messages from | [types.ts:
|
|
239
|
+
| <a id="message"></a> `message` | `TMessage` | The message definition including the payload schema | [types.ts:881](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L881) |
|
|
240
|
+
| <a id="queue"></a> `queue` | [`QueueDefinition`](#queuedefinition) | The queue to consume messages from | [types.ts:878](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L878) |
|
|
181
241
|
|
|
182
242
|
***
|
|
183
243
|
|
|
@@ -187,7 +247,7 @@ const consumer: ConsumerDefinition = {
|
|
|
187
247
|
type ConsumerFirstResult<TMessage, TConsumer, TBinding> = object;
|
|
188
248
|
```
|
|
189
249
|
|
|
190
|
-
Defined in: [builder.ts:
|
|
250
|
+
Defined in: [builder/consumer-first.ts:27](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/consumer-first.ts#L27)
|
|
191
251
|
|
|
192
252
|
Consumer-first builder result for fanout and direct exchanges.
|
|
193
253
|
|
|
@@ -199,16 +259,16 @@ a publisher that uses the same message schema and routing key.
|
|
|
199
259
|
| Type Parameter | Description |
|
|
200
260
|
| ------ | ------ |
|
|
201
261
|
| `TMessage` *extends* [`MessageDefinition`](#messagedefinition) | The message definition |
|
|
202
|
-
| `TConsumer` *extends* [`ConsumerDefinition`](#consumerdefinition)
|
|
262
|
+
| `TConsumer` *extends* [`ConsumerDefinition`](#consumerdefinition)<`TMessage`> | The consumer definition |
|
|
203
263
|
| `TBinding` *extends* [`QueueBindingDefinition`](#queuebindingdefinition) | The queue binding definition |
|
|
204
264
|
|
|
205
265
|
#### Properties
|
|
206
266
|
|
|
207
267
|
| Property | Type | Description | Defined in |
|
|
208
268
|
| ------ | ------ | ------ | ------ |
|
|
209
|
-
| <a id="binding"></a> `binding` | `TBinding` | The binding definition connecting the exchange to the queue | [builder.ts:
|
|
210
|
-
| <a id="consumer"></a> `consumer` | `TConsumer` | The consumer definition | [builder.ts:
|
|
211
|
-
| <a id="createpublisher"></a> `createPublisher` | () => `TBinding`\[`"exchange"`\] *extends* [`FanoutExchangeDefinition`](#fanoutexchangedefinition) ? `Extract
|
|
269
|
+
| <a id="binding"></a> `binding` | `TBinding` | The binding definition connecting the exchange to the queue | [builder/consumer-first.ts:35](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/consumer-first.ts#L35) |
|
|
270
|
+
| <a id="consumer"></a> `consumer` | `TConsumer` | The consumer definition | [builder/consumer-first.ts:33](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/consumer-first.ts#L33) |
|
|
271
|
+
| <a id="createpublisher"></a> `createPublisher` | () => `TBinding`\[`"exchange"`\] *extends* [`FanoutExchangeDefinition`](#fanoutexchangedefinition) ? `Extract`<[`PublisherDefinition`](#publisherdefinition)<`TMessage`>, \{ `exchange`: [`FanoutExchangeDefinition`](#fanoutexchangedefinition); \}> : `Extract`<[`PublisherDefinition`](#publisherdefinition)<`TMessage`>, \{ `exchange`: \| [`DirectExchangeDefinition`](#directexchangedefinition) \| [`TopicExchangeDefinition`](#topicexchangedefinition); \}> | Create a publisher that sends messages to this consumer. The publisher will automatically use the same message schema and routing key. | [builder/consumer-first.ts:42](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/consumer-first.ts#L42) |
|
|
212
272
|
|
|
213
273
|
***
|
|
214
274
|
|
|
@@ -218,7 +278,7 @@ a publisher that uses the same message schema and routing key.
|
|
|
218
278
|
type ConsumerFirstResultWithRoutingKey<TMessage, TConsumer, TBinding> = object;
|
|
219
279
|
```
|
|
220
280
|
|
|
221
|
-
Defined in: [builder.ts:
|
|
281
|
+
Defined in: [builder/consumer-first.ts:60](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/consumer-first.ts#L60)
|
|
222
282
|
|
|
223
283
|
Consumer-first builder result for topic exchanges.
|
|
224
284
|
|
|
@@ -230,16 +290,16 @@ a method to create a publisher with a concrete routing key that matches the patt
|
|
|
230
290
|
| Type Parameter | Description |
|
|
231
291
|
| ------ | ------ |
|
|
232
292
|
| `TMessage` *extends* [`MessageDefinition`](#messagedefinition) | The message definition |
|
|
233
|
-
| `TConsumer` *extends* [`ConsumerDefinition`](#consumerdefinition)
|
|
293
|
+
| `TConsumer` *extends* [`ConsumerDefinition`](#consumerdefinition)<`TMessage`> | The consumer definition |
|
|
234
294
|
| `TBinding` *extends* [`QueueBindingDefinition`](#queuebindingdefinition) | The queue binding definition |
|
|
235
295
|
|
|
236
296
|
#### Properties
|
|
237
297
|
|
|
238
298
|
| Property | Type | Description | Defined in |
|
|
239
299
|
| ------ | ------ | ------ | ------ |
|
|
240
|
-
| <a id="binding-1"></a> `binding` | `TBinding` | The binding definition connecting the exchange to the queue | [builder.ts:
|
|
241
|
-
| <a id="consumer-1"></a> `consumer` | `TConsumer` | The consumer definition | [builder.ts:
|
|
242
|
-
| <a id="createpublisher-1"></a> `createPublisher` |
|
|
300
|
+
| <a id="binding-1"></a> `binding` | `TBinding` | The binding definition connecting the exchange to the queue | [builder/consumer-first.ts:68](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/consumer-first.ts#L68) |
|
|
301
|
+
| <a id="consumer-1"></a> `consumer` | `TConsumer` | The consumer definition | [builder/consumer-first.ts:66](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/consumer-first.ts#L66) |
|
|
302
|
+
| <a id="createpublisher-1"></a> `createPublisher` | <`TPublisherRoutingKey`>(`routingKey`) => `Extract`<[`PublisherDefinition`](#publisherdefinition)<`TMessage`>, \{ `exchange`: \| [`DirectExchangeDefinition`](#directexchangedefinition) \| [`TopicExchangeDefinition`](#topicexchangedefinition); \}> | Create a publisher that sends messages to this consumer. For topic exchanges, the routing key can be specified to match the binding pattern. | [builder/consumer-first.ts:76](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/consumer-first.ts#L76) |
|
|
243
303
|
|
|
244
304
|
***
|
|
245
305
|
|
|
@@ -249,7 +309,7 @@ a method to create a publisher with a concrete routing key that matches the patt
|
|
|
249
309
|
type ContractDefinition = object;
|
|
250
310
|
```
|
|
251
311
|
|
|
252
|
-
Defined in: [types.ts:
|
|
312
|
+
Defined in: [types.ts:917](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L917)
|
|
253
313
|
|
|
254
314
|
Complete AMQP contract definition.
|
|
255
315
|
|
|
@@ -288,11 +348,11 @@ const contract: ContractDefinition = {
|
|
|
288
348
|
|
|
289
349
|
| Property | Type | Description | Defined in |
|
|
290
350
|
| ------ | ------ | ------ | ------ |
|
|
291
|
-
| <a id="bindings"></a> `bindings?` | `Record
|
|
292
|
-
| <a id="consumers"></a> `consumers?` | `Record
|
|
293
|
-
| <a id="exchanges"></a> `exchanges?` | `Record
|
|
294
|
-
| <a id="publishers"></a> `publishers?` | `Record
|
|
295
|
-
| <a id="queues"></a> `queues?` | `Record
|
|
351
|
+
| <a id="bindings"></a> `bindings?` | `Record`<`string`, [`BindingDefinition`](#bindingdefinition)> | Named binding definitions. Bindings can be queue-to-exchange or exchange-to-exchange. | [types.ts:937](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L937) |
|
|
352
|
+
| <a id="consumers"></a> `consumers?` | `Record`<`string`, [`ConsumerDefinition`](#consumerdefinition)> | Named consumer definitions. Each key requires a corresponding handler in the TypedAmqpWorker. The handler will be fully typed based on the message schema. | [types.ts:951](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L951) |
|
|
353
|
+
| <a id="exchanges"></a> `exchanges?` | `Record`<`string`, [`ExchangeDefinition`](#exchangedefinition)> | Named exchange definitions. Each key becomes available as a named resource in the contract. | [types.ts:922](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L922) |
|
|
354
|
+
| <a id="publishers"></a> `publishers?` | `Record`<`string`, [`PublisherDefinition`](#publisherdefinition)> | Named publisher definitions. Each key becomes a method on the TypedAmqpClient for publishing messages. The method will be fully typed based on the message schema. | [types.ts:944](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L944) |
|
|
355
|
+
| <a id="queues"></a> `queues?` | `Record`<`string`, [`QueueEntry`](#queueentry)> | Named queue definitions. Each key becomes available as a named resource in the contract. When a queue has TTL-backoff retry configured, pass the `QueueWithTtlBackoffInfrastructure` object returned by `defineQueue`. The wait queue and bindings will be automatically added. | [types.ts:931](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L931) |
|
|
296
356
|
|
|
297
357
|
***
|
|
298
358
|
|
|
@@ -302,7 +362,7 @@ const contract: ContractDefinition = {
|
|
|
302
362
|
type DeadLetterConfig = object;
|
|
303
363
|
```
|
|
304
364
|
|
|
305
|
-
Defined in: [types.ts:
|
|
365
|
+
Defined in: [types.ts:480](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L480)
|
|
306
366
|
|
|
307
367
|
Configuration for dead letter exchange (DLX) on a queue.
|
|
308
368
|
|
|
@@ -314,8 +374,26 @@ or storage.
|
|
|
314
374
|
|
|
315
375
|
| Property | Type | Description | Defined in |
|
|
316
376
|
| ------ | ------ | ------ | ------ |
|
|
317
|
-
| <a id="exchange"></a> `exchange` | [`ExchangeDefinition`](#exchangedefinition) | The exchange to send dead-lettered messages to. This exchange must be declared in the contract. | [types.ts:
|
|
318
|
-
| <a id="routingkey"></a> `routingKey?` | `string` | Optional routing key to use when forwarding messages to the dead letter exchange. If not specified, the original message routing key is used. | [types.ts:
|
|
377
|
+
| <a id="exchange"></a> `exchange` | [`ExchangeDefinition`](#exchangedefinition) | The exchange to send dead-lettered messages to. This exchange must be declared in the contract. | [types.ts:485](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L485) |
|
|
378
|
+
| <a id="routingkey"></a> `routingKey?` | `string` | Optional routing key to use when forwarding messages to the dead letter exchange. If not specified, the original message routing key is used. | [types.ts:491](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L491) |
|
|
379
|
+
|
|
380
|
+
***
|
|
381
|
+
|
|
382
|
+
### DefineQueueOptions
|
|
383
|
+
|
|
384
|
+
```ts
|
|
385
|
+
type DefineQueueOptions =
|
|
386
|
+
| QuorumQueueOptions
|
|
387
|
+
| ClassicQueueOptions;
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
Defined in: [types.ts:368](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L368)
|
|
391
|
+
|
|
392
|
+
Options for defining a queue. Uses a discriminated union based on the `type` property
|
|
393
|
+
to enforce quorum queue constraints at compile time.
|
|
394
|
+
|
|
395
|
+
- Quorum queues (default): Do not support `exclusive` or `maxPriority`
|
|
396
|
+
- Classic queues: Support all options including `exclusive` and `maxPriority`
|
|
319
397
|
|
|
320
398
|
***
|
|
321
399
|
|
|
@@ -325,7 +403,7 @@ or storage.
|
|
|
325
403
|
type DirectExchangeDefinition = BaseExchangeDefinition & object;
|
|
326
404
|
```
|
|
327
405
|
|
|
328
|
-
Defined in: [types.ts:
|
|
406
|
+
Defined in: [types.ts:438](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L438)
|
|
329
407
|
|
|
330
408
|
A direct exchange definition.
|
|
331
409
|
|
|
@@ -336,7 +414,7 @@ This is ideal for point-to-point messaging where each message should go to speci
|
|
|
336
414
|
|
|
337
415
|
| Name | Type | Defined in |
|
|
338
416
|
| ------ | ------ | ------ |
|
|
339
|
-
| `type` | `"direct"` | [types.ts:
|
|
417
|
+
| `type` | `"direct"` | [types.ts:439](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L439) |
|
|
340
418
|
|
|
341
419
|
#### Example
|
|
342
420
|
|
|
@@ -363,7 +441,7 @@ type ExchangeBindingDefinition = object &
|
|
|
363
441
|
};
|
|
364
442
|
```
|
|
365
443
|
|
|
366
|
-
Defined in: [types.ts:
|
|
444
|
+
Defined in: [types.ts:779](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L779)
|
|
367
445
|
|
|
368
446
|
Binding between two exchanges (exchange-to-exchange routing).
|
|
369
447
|
|
|
@@ -374,9 +452,9 @@ This allows for more complex routing topologies.
|
|
|
374
452
|
|
|
375
453
|
| Name | Type | Description | Defined in |
|
|
376
454
|
| ------ | ------ | ------ | ------ |
|
|
377
|
-
| `arguments?` | `Record
|
|
378
|
-
| `destination` | [`ExchangeDefinition`](#exchangedefinition) | The destination exchange that will receive forwarded messages | [types.ts:
|
|
379
|
-
| `type` | `"exchange"` | Discriminator indicating this is an exchange-to-exchange binding | [types.ts:
|
|
455
|
+
| `arguments?` | `Record`<`string`, `unknown`> | Additional AMQP arguments for the binding. | [types.ts:789](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L789) |
|
|
456
|
+
| `destination` | [`ExchangeDefinition`](#exchangedefinition) | The destination exchange that will receive forwarded messages | [types.ts:784](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L784) |
|
|
457
|
+
| `type` | `"exchange"` | Discriminator indicating this is an exchange-to-exchange binding | [types.ts:781](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L781) |
|
|
380
458
|
|
|
381
459
|
#### Example
|
|
382
460
|
|
|
@@ -401,7 +479,7 @@ type ExchangeDefinition =
|
|
|
401
479
|
| TopicExchangeDefinition;
|
|
402
480
|
```
|
|
403
481
|
|
|
404
|
-
Defined in: [types.ts:
|
|
482
|
+
Defined in: [types.ts:468](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L468)
|
|
405
483
|
|
|
406
484
|
Union type of all exchange definitions.
|
|
407
485
|
|
|
@@ -415,7 +493,7 @@ Represents any type of AMQP exchange: fanout, direct, or topic.
|
|
|
415
493
|
type FanoutExchangeDefinition = BaseExchangeDefinition & object;
|
|
416
494
|
```
|
|
417
495
|
|
|
418
|
-
Defined in: [types.ts:
|
|
496
|
+
Defined in: [types.ts:421](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L421)
|
|
419
497
|
|
|
420
498
|
A fanout exchange definition.
|
|
421
499
|
|
|
@@ -426,7 +504,7 @@ This is the simplest exchange type for pub/sub messaging patterns.
|
|
|
426
504
|
|
|
427
505
|
| Name | Type | Defined in |
|
|
428
506
|
| ------ | ------ | ------ |
|
|
429
|
-
| `type` | `"fanout"` | [types.ts:
|
|
507
|
+
| `type` | `"fanout"` | [types.ts:422](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L422) |
|
|
430
508
|
|
|
431
509
|
#### Example
|
|
432
510
|
|
|
@@ -444,7 +522,7 @@ const logsExchange: FanoutExchangeDefinition = defineExchange('logs', 'fanout',
|
|
|
444
522
|
type InferConsumerNames<TContract> = TContract["consumers"] extends Record<string, unknown> ? keyof TContract["consumers"] : never;
|
|
445
523
|
```
|
|
446
524
|
|
|
447
|
-
Defined in: [types.ts:
|
|
525
|
+
Defined in: [types.ts:987](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L987)
|
|
448
526
|
|
|
449
527
|
Extract consumer names from a contract.
|
|
450
528
|
|
|
@@ -476,7 +554,7 @@ type ConsumerNames = InferConsumerNames<typeof myContract>;
|
|
|
476
554
|
type InferPublisherNames<TContract> = TContract["publishers"] extends Record<string, unknown> ? keyof TContract["publishers"] : never;
|
|
477
555
|
```
|
|
478
556
|
|
|
479
|
-
Defined in: [types.ts:
|
|
557
|
+
Defined in: [types.ts:969](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L969)
|
|
480
558
|
|
|
481
559
|
Extract publisher names from a contract.
|
|
482
560
|
|
|
@@ -508,7 +586,7 @@ type PublisherNames = InferPublisherNames<typeof myContract>;
|
|
|
508
586
|
type MatchingRoutingKey<Pattern, Key> = RoutingKey<Key> extends never ? never : BindingPattern<Pattern> extends never ? never : MatchesPattern<Key, Pattern> extends true ? Key : never;
|
|
509
587
|
```
|
|
510
588
|
|
|
511
|
-
Defined in: [builder.ts:
|
|
589
|
+
Defined in: [builder/routing-types.ts:114](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/routing-types.ts#L114)
|
|
512
590
|
|
|
513
591
|
Validate that a routing key matches a binding pattern.
|
|
514
592
|
|
|
@@ -540,7 +618,7 @@ type InvalidKey = MatchingRoutingKey<"order.*", "user.created">; // never
|
|
|
540
618
|
type MessageDefinition<TPayload, THeaders> = object;
|
|
541
619
|
```
|
|
542
620
|
|
|
543
|
-
Defined in: [types.ts:
|
|
621
|
+
Defined in: [types.ts:695](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L695)
|
|
544
622
|
|
|
545
623
|
Definition of a message with typed payload and optional headers.
|
|
546
624
|
|
|
@@ -549,16 +627,16 @@ Definition of a message with typed payload and optional headers.
|
|
|
549
627
|
| Type Parameter | Default type | Description |
|
|
550
628
|
| ------ | ------ | ------ |
|
|
551
629
|
| `TPayload` *extends* [`AnySchema`](#anyschema) | [`AnySchema`](#anyschema) | The Standard Schema v1 compatible schema for the message payload |
|
|
552
|
-
| `THeaders` *extends* `StandardSchemaV1
|
|
630
|
+
| `THeaders` *extends* \| `StandardSchemaV1`<`Record`<`string`, `unknown`>> \| `undefined` | `undefined` | The Standard Schema v1 compatible schema for the message headers (optional) |
|
|
553
631
|
|
|
554
632
|
#### Properties
|
|
555
633
|
|
|
556
634
|
| Property | Type | Description | Defined in |
|
|
557
635
|
| ------ | ------ | ------ | ------ |
|
|
558
|
-
| <a id="description"></a> `description?` | `string` | Detailed description of the message for documentation purposes. Used in AsyncAPI specification generation. | [types.ts:
|
|
559
|
-
| <a id="headers"></a> `headers?` | `THeaders` | Optional headers schema for validating message metadata. Must be a Standard Schema v1 compatible schema. | [types.ts:
|
|
560
|
-
| <a id="payload"></a> `payload` | `TPayload` | The payload schema for validating message content. Must be a Standard Schema v1 compatible schema (Zod, Valibot, ArkType, etc.). | [types.ts:
|
|
561
|
-
| <a id="summary"></a> `summary?` | `string` | Brief description of the message for documentation purposes. Used in AsyncAPI specification generation. | [types.ts:
|
|
636
|
+
| <a id="description"></a> `description?` | `string` | Detailed description of the message for documentation purposes. Used in AsyncAPI specification generation. | [types.ts:721](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L721) |
|
|
637
|
+
| <a id="headers"></a> `headers?` | `THeaders` | Optional headers schema for validating message metadata. Must be a Standard Schema v1 compatible schema. | [types.ts:709](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L709) |
|
|
638
|
+
| <a id="payload"></a> `payload` | `TPayload` | The payload schema for validating message content. Must be a Standard Schema v1 compatible schema (Zod, Valibot, ArkType, etc.). | [types.ts:703](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L703) |
|
|
639
|
+
| <a id="summary"></a> `summary?` | `string` | Brief description of the message for documentation purposes. Used in AsyncAPI specification generation. | [types.ts:715](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L715) |
|
|
562
640
|
|
|
563
641
|
***
|
|
564
642
|
|
|
@@ -577,7 +655,7 @@ type PublisherDefinition<TMessage> = object &
|
|
|
577
655
|
};
|
|
578
656
|
```
|
|
579
657
|
|
|
580
|
-
Defined in: [types.ts:
|
|
658
|
+
Defined in: [types.ts:837](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L837)
|
|
581
659
|
|
|
582
660
|
Definition of a message publisher.
|
|
583
661
|
|
|
@@ -591,7 +669,7 @@ algorithm when calling the publish method.
|
|
|
591
669
|
|
|
592
670
|
| Name | Type | Description | Defined in |
|
|
593
671
|
| ------ | ------ | ------ | ------ |
|
|
594
|
-
| `message` | `TMessage` | The message definition including the payload schema | [types.ts:
|
|
672
|
+
| `message` | `TMessage` | The message definition including the payload schema | [types.ts:839](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L839) |
|
|
595
673
|
|
|
596
674
|
#### Type Parameters
|
|
597
675
|
|
|
@@ -617,7 +695,7 @@ const publisher: PublisherDefinition = {
|
|
|
617
695
|
type PublisherFirstResult<TMessage, TPublisher> = object;
|
|
618
696
|
```
|
|
619
697
|
|
|
620
|
-
Defined in: [builder.ts:
|
|
698
|
+
Defined in: [builder/publisher-first.ts:29](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/publisher-first.ts#L29)
|
|
621
699
|
|
|
622
700
|
Publisher-first builder result for fanout and direct exchanges.
|
|
623
701
|
|
|
@@ -632,14 +710,14 @@ emit events without knowing which queues will consume them.
|
|
|
632
710
|
| Type Parameter | Description |
|
|
633
711
|
| ------ | ------ |
|
|
634
712
|
| `TMessage` *extends* [`MessageDefinition`](#messagedefinition) | The message definition |
|
|
635
|
-
| `TPublisher` *extends* [`PublisherDefinition`](#publisherdefinition)
|
|
713
|
+
| `TPublisher` *extends* [`PublisherDefinition`](#publisherdefinition)<`TMessage`> | The publisher definition |
|
|
636
714
|
|
|
637
715
|
#### Properties
|
|
638
716
|
|
|
639
717
|
| Property | Type | Description | Defined in |
|
|
640
718
|
| ------ | ------ | ------ | ------ |
|
|
641
|
-
| <a id="createconsumer"></a> `createConsumer` | (`queue`) => `object` | Create a consumer that receives messages from this publisher. The consumer will automatically use the same message schema and a binding will be created with the same routing key. | [builder.ts:
|
|
642
|
-
| <a id="publisher"></a> `publisher` | `TPublisher` | The publisher definition | [builder.ts:
|
|
719
|
+
| <a id="createconsumer"></a> `createConsumer` | (`queue`) => `object` | Create a consumer that receives messages from this publisher. The consumer will automatically use the same message schema and a binding will be created with the same routing key. | [builder/publisher-first.ts:43](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/publisher-first.ts#L43) |
|
|
720
|
+
| <a id="publisher"></a> `publisher` | `TPublisher` | The publisher definition | [builder/publisher-first.ts:34](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/publisher-first.ts#L34) |
|
|
643
721
|
|
|
644
722
|
***
|
|
645
723
|
|
|
@@ -649,7 +727,7 @@ emit events without knowing which queues will consume them.
|
|
|
649
727
|
type PublisherFirstResultWithRoutingKey<TMessage, TPublisher, TRoutingKey> = object;
|
|
650
728
|
```
|
|
651
729
|
|
|
652
|
-
Defined in: [builder.ts:
|
|
730
|
+
Defined in: [builder/publisher-first.ts:59](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/publisher-first.ts#L59)
|
|
653
731
|
|
|
654
732
|
Publisher-first builder result for topic exchanges.
|
|
655
733
|
|
|
@@ -661,15 +739,15 @@ to create consumers that can use routing key patterns matching the publisher's k
|
|
|
661
739
|
| Type Parameter | Description |
|
|
662
740
|
| ------ | ------ |
|
|
663
741
|
| `TMessage` *extends* [`MessageDefinition`](#messagedefinition) | The message definition |
|
|
664
|
-
| `TPublisher` *extends* [`PublisherDefinition`](#publisherdefinition)
|
|
742
|
+
| `TPublisher` *extends* [`PublisherDefinition`](#publisherdefinition)<`TMessage`> | The publisher definition |
|
|
665
743
|
| `TRoutingKey` *extends* `string` | The literal routing key type from the publisher (for documentation purposes) |
|
|
666
744
|
|
|
667
745
|
#### Properties
|
|
668
746
|
|
|
669
747
|
| Property | Type | Description | Defined in |
|
|
670
748
|
| ------ | ------ | ------ | ------ |
|
|
671
|
-
| <a id="createconsumer-1"></a> `createConsumer` |
|
|
672
|
-
| <a id="publisher-1"></a> `publisher` | `TPublisher` | The publisher definition | [builder.ts:
|
|
749
|
+
| <a id="createconsumer-1"></a> `createConsumer` | <`TConsumerRoutingKey`>(`queue`, `routingKey?`) => `object` | Create a consumer that receives messages from this publisher. For topic exchanges, the routing key pattern can be specified for the binding. | [builder/publisher-first.ts:74](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/publisher-first.ts#L74) |
|
|
750
|
+
| <a id="publisher-1"></a> `publisher` | `TPublisher` | The publisher definition | [builder/publisher-first.ts:65](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/publisher-first.ts#L65) |
|
|
673
751
|
|
|
674
752
|
***
|
|
675
753
|
|
|
@@ -688,7 +766,7 @@ type QueueBindingDefinition = object &
|
|
|
688
766
|
};
|
|
689
767
|
```
|
|
690
768
|
|
|
691
|
-
Defined in: [types.ts:
|
|
769
|
+
Defined in: [types.ts:731](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L731)
|
|
692
770
|
|
|
693
771
|
Binding between a queue and an exchange.
|
|
694
772
|
|
|
@@ -700,35 +778,240 @@ For fanout exchanges, no routing key is needed as all messages are broadcast.
|
|
|
700
778
|
|
|
701
779
|
| Name | Type | Description | Defined in |
|
|
702
780
|
| ------ | ------ | ------ | ------ |
|
|
703
|
-
| `arguments?` | `Record
|
|
704
|
-
| `queue` | [`QueueDefinition`](#queuedefinition) | The queue that will receive messages | [types.ts:
|
|
705
|
-
| `type` | `"queue"` | Discriminator indicating this is a queue-to-exchange binding | [types.ts:
|
|
781
|
+
| `arguments?` | `Record`<`string`, `unknown`> | Additional AMQP arguments for the binding. Can be used for advanced routing scenarios with the headers exchange type. | [types.ts:742](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L742) |
|
|
782
|
+
| `queue` | [`QueueDefinition`](#queuedefinition) | The queue that will receive messages | [types.ts:736](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L736) |
|
|
783
|
+
| `type` | `"queue"` | Discriminator indicating this is a queue-to-exchange binding | [types.ts:733](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L733) |
|
|
706
784
|
|
|
707
785
|
***
|
|
708
786
|
|
|
709
787
|
### QueueDefinition
|
|
710
788
|
|
|
711
789
|
```ts
|
|
712
|
-
type QueueDefinition =
|
|
790
|
+
type QueueDefinition =
|
|
791
|
+
| QuorumQueueDefinition
|
|
792
|
+
| ClassicQueueDefinition;
|
|
713
793
|
```
|
|
714
794
|
|
|
715
|
-
Defined in: [types.ts:
|
|
795
|
+
Defined in: [types.ts:629](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L629)
|
|
716
796
|
|
|
717
797
|
Definition of an AMQP queue.
|
|
718
798
|
|
|
719
|
-
A
|
|
720
|
-
|
|
799
|
+
A discriminated union based on queue type:
|
|
800
|
+
- `QuorumQueueDefinition`: For quorum queues (type: "quorum")
|
|
801
|
+
- `ClassicQueueDefinition`: For classic queues (type: "classic")
|
|
802
|
+
|
|
803
|
+
Use `queue.type` as the discriminator to narrow the type.
|
|
804
|
+
|
|
805
|
+
***
|
|
806
|
+
|
|
807
|
+
### QueueEntry
|
|
808
|
+
|
|
809
|
+
```ts
|
|
810
|
+
type QueueEntry =
|
|
811
|
+
| QueueDefinition
|
|
812
|
+
| QueueWithTtlBackoffInfrastructure;
|
|
813
|
+
```
|
|
814
|
+
|
|
815
|
+
Defined in: [types.ts:687](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L687)
|
|
816
|
+
|
|
817
|
+
A queue entry that can be passed to `defineContract`.
|
|
818
|
+
|
|
819
|
+
Can be either a plain queue definition or a queue with TTL-backoff infrastructure.
|
|
820
|
+
|
|
821
|
+
***
|
|
822
|
+
|
|
823
|
+
### QueueType
|
|
824
|
+
|
|
825
|
+
```ts
|
|
826
|
+
type QueueType = "quorum" | "classic";
|
|
827
|
+
```
|
|
828
|
+
|
|
829
|
+
Defined in: [types.ts:163](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L163)
|
|
830
|
+
|
|
831
|
+
Supported queue types in RabbitMQ.
|
|
832
|
+
|
|
833
|
+
- `quorum`: Quorum queues (default, recommended) - Provide better durability and high-availability
|
|
834
|
+
using the Raft consensus algorithm. Best for most production use cases.
|
|
835
|
+
- `classic`: Classic queues - The traditional RabbitMQ queue type. Use only when you need
|
|
836
|
+
specific features not supported by quorum queues (e.g., non-durable queues, priority queues).
|
|
837
|
+
|
|
838
|
+
Note: Quorum queues require `durable: true` and do not support `exclusive: true`.
|
|
839
|
+
When using quorum queues, `durable` is automatically set to `true`.
|
|
840
|
+
|
|
841
|
+
#### See
|
|
842
|
+
|
|
843
|
+
https://www.rabbitmq.com/docs/quorum-queues
|
|
844
|
+
|
|
845
|
+
#### Example
|
|
846
|
+
|
|
847
|
+
```typescript
|
|
848
|
+
// Create a quorum queue (default, recommended)
|
|
849
|
+
const orderQueue = defineQueue('order-processing', {
|
|
850
|
+
type: 'quorum', // This is the default
|
|
851
|
+
});
|
|
852
|
+
|
|
853
|
+
// Create a classic queue (for special cases)
|
|
854
|
+
const tempQueue = defineQueue('temp-queue', {
|
|
855
|
+
type: 'classic',
|
|
856
|
+
durable: false, // Only supported with classic queues
|
|
857
|
+
});
|
|
858
|
+
```
|
|
859
|
+
|
|
860
|
+
***
|
|
861
|
+
|
|
862
|
+
### QueueWithTtlBackoffInfrastructure
|
|
863
|
+
|
|
864
|
+
```ts
|
|
865
|
+
type QueueWithTtlBackoffInfrastructure = object;
|
|
866
|
+
```
|
|
867
|
+
|
|
868
|
+
Defined in: [types.ts:654](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L654)
|
|
869
|
+
|
|
870
|
+
A queue with automatically generated TTL-backoff retry infrastructure.
|
|
871
|
+
|
|
872
|
+
This type is returned by `defineQueue` when TTL-backoff retry is configured
|
|
873
|
+
with a dead letter exchange. When passed to `defineContract`, the wait queue
|
|
874
|
+
and bindings are automatically added to the contract.
|
|
875
|
+
|
|
876
|
+
#### Example
|
|
877
|
+
|
|
878
|
+
```typescript
|
|
879
|
+
const dlx = defineExchange('orders-dlx', 'direct', { durable: true });
|
|
880
|
+
const queue = defineQueue('order-processing', {
|
|
881
|
+
deadLetter: { exchange: dlx },
|
|
882
|
+
retry: { mode: 'ttl-backoff', maxRetries: 5 },
|
|
883
|
+
});
|
|
884
|
+
// queue is QueueWithTtlBackoffInfrastructure
|
|
885
|
+
|
|
886
|
+
const contract = defineContract({
|
|
887
|
+
exchanges: { dlx },
|
|
888
|
+
queues: { orderProcessing: queue }, // Automatically adds wait queue
|
|
889
|
+
// ... bindings are automatically generated
|
|
890
|
+
});
|
|
891
|
+
```
|
|
721
892
|
|
|
722
893
|
#### Properties
|
|
723
894
|
|
|
724
895
|
| Property | Type | Description | Defined in |
|
|
725
896
|
| ------ | ------ | ------ | ------ |
|
|
726
|
-
| <a id="
|
|
727
|
-
| <a id="
|
|
728
|
-
| <a id="
|
|
729
|
-
| <a id="
|
|
730
|
-
|
|
731
|
-
|
|
897
|
+
| <a id="mainqueueretrybinding"></a> `mainQueueRetryBinding` | [`QueueBindingDefinition`](#queuebindingdefinition) | Binding that routes retried messages back to the main queue. | [types.ts:679](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L679) |
|
|
898
|
+
| <a id="queue-1"></a> `queue` | [`QueueDefinition`](#queuedefinition) | The main queue definition. | [types.ts:664](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L664) |
|
|
899
|
+
| <a id="waitqueue"></a> `waitQueue` | [`QueueDefinition`](#queuedefinition) | The wait queue for holding messages during backoff delay. | [types.ts:669](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L669) |
|
|
900
|
+
| <a id="waitqueuebinding"></a> `waitQueueBinding` | [`QueueBindingDefinition`](#queuebindingdefinition) | Binding that routes failed messages to the wait queue. | [types.ts:674](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L674) |
|
|
901
|
+
|
|
902
|
+
***
|
|
903
|
+
|
|
904
|
+
### QuorumNativeRetryOptions
|
|
905
|
+
|
|
906
|
+
```ts
|
|
907
|
+
type QuorumNativeRetryOptions = object;
|
|
908
|
+
```
|
|
909
|
+
|
|
910
|
+
Defined in: [types.ts:72](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L72)
|
|
911
|
+
|
|
912
|
+
Quorum-Native retry options using RabbitMQ's native delivery limit feature.
|
|
913
|
+
|
|
914
|
+
Uses quorum queue's `x-delivery-limit` feature. Messages are requeued immediately
|
|
915
|
+
with `nack(requeue=true)`, and RabbitMQ tracks delivery count via `x-delivery-count`
|
|
916
|
+
header. When the count exceeds the queue's `deliveryLimit`, the message is
|
|
917
|
+
automatically dead-lettered.
|
|
918
|
+
|
|
919
|
+
**Benefits:** Simpler architecture, no wait queues needed, no head-of-queue blocking.
|
|
920
|
+
**Limitation:** Immediate retries only (no exponential backoff).
|
|
921
|
+
|
|
922
|
+
#### See
|
|
923
|
+
|
|
924
|
+
https://www.rabbitmq.com/docs/quorum-queues#poison-message-handling
|
|
925
|
+
|
|
926
|
+
#### Properties
|
|
927
|
+
|
|
928
|
+
| Property | Type | Description | Defined in |
|
|
929
|
+
| ------ | ------ | ------ | ------ |
|
|
930
|
+
| <a id="mode"></a> `mode` | `"quorum-native"` | Quorum-Native mode uses RabbitMQ's native delivery limit feature. Requires the queue to be a quorum queue with `deliveryLimit` configured. | [types.ts:77](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L77) |
|
|
931
|
+
|
|
932
|
+
***
|
|
933
|
+
|
|
934
|
+
### QuorumQueueDefinition
|
|
935
|
+
|
|
936
|
+
```ts
|
|
937
|
+
type QuorumQueueDefinition = BaseQueueDefinition & object;
|
|
938
|
+
```
|
|
939
|
+
|
|
940
|
+
Defined in: [types.ts:542](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L542)
|
|
941
|
+
|
|
942
|
+
Definition of a quorum queue.
|
|
943
|
+
|
|
944
|
+
Quorum queues provide better durability and high-availability using the Raft consensus algorithm.
|
|
945
|
+
They support native retry handling via `deliveryLimit` and both TTL-backoff and quorum-native retry modes.
|
|
946
|
+
|
|
947
|
+
#### Type Declaration
|
|
948
|
+
|
|
949
|
+
| Name | Type | Description | Defined in |
|
|
950
|
+
| ------ | ------ | ------ | ------ |
|
|
951
|
+
| `deliveryLimit?` | `number` | Maximum number of delivery attempts before the message is dead-lettered. This is a quorum queue-specific feature. When a message is rejected (nacked) and requeued, RabbitMQ increments the `x-delivery-count` header. When this count reaches the delivery limit, the message is automatically dead-lettered (if DLX is configured) or dropped. **Minimum** 1 - Must be a positive integer (1 or greater) **See** https://www.rabbitmq.com/docs/quorum-queues#poison-message-handling | [types.ts:572](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L572) |
|
|
952
|
+
| `exclusive?` | `never` | Quorum queues do not support exclusive mode. Use type: 'classic' if you need exclusive queues. | [types.ts:552](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L552) |
|
|
953
|
+
| `maxPriority?` | `never` | Quorum queues do not support priority queues. Use type: 'classic' if you need priority queues. | [types.ts:558](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L558) |
|
|
954
|
+
| `retry` | [`ResolvedRetryOptions`](#resolvedretryoptions) | Retry configuration for handling failed message processing. Quorum queues support both: - `ttl-backoff`: Uses wait queues with exponential backoff (default) - `quorum-native`: Uses RabbitMQ's native delivery limit feature When the queue is created, defaults are applied for TTL-backoff options. | [types.ts:583](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L583) |
|
|
955
|
+
| `type` | `"quorum"` | Queue type discriminator: quorum queue. | [types.ts:546](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L546) |
|
|
956
|
+
|
|
957
|
+
***
|
|
958
|
+
|
|
959
|
+
### QuorumQueueOptions
|
|
960
|
+
|
|
961
|
+
```ts
|
|
962
|
+
type QuorumQueueOptions = BaseQueueOptions & object;
|
|
963
|
+
```
|
|
964
|
+
|
|
965
|
+
Defined in: [types.ts:214](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L214)
|
|
966
|
+
|
|
967
|
+
Options for creating a quorum queue.
|
|
968
|
+
|
|
969
|
+
Quorum queues do not support:
|
|
970
|
+
- `exclusive` - Use classic queues for exclusive access
|
|
971
|
+
- `maxPriority` - Use classic queues for priority queues
|
|
972
|
+
|
|
973
|
+
Quorum queues provide native retry support via `deliveryLimit`:
|
|
974
|
+
- RabbitMQ tracks delivery count automatically via `x-delivery-count` header
|
|
975
|
+
- When the limit is exceeded, messages are dead-lettered (if DLX is configured)
|
|
976
|
+
- This is simpler than TTL-based retry and avoids head-of-queue blocking issues
|
|
977
|
+
|
|
978
|
+
#### Type Declaration
|
|
979
|
+
|
|
980
|
+
| Name | Type | Description | Defined in |
|
|
981
|
+
| ------ | ------ | ------ | ------ |
|
|
982
|
+
| `deliveryLimit?` | `number` | Maximum number of delivery attempts before the message is dead-lettered. When a message is rejected (nacked) and requeued, RabbitMQ increments the `x-delivery-count` header. When this count reaches the delivery limit, the message is automatically dead-lettered (if DLX is configured) or dropped. This is a quorum queue-specific feature that provides native retry handling without the complexity of TTL-based wait queues. **Benefits over TTL-based retry:** - Simpler architecture (no wait queues needed) - No head-of-queue blocking issues (TTL only works at queue head) - Native RabbitMQ feature with atomic guarantees **Minimum** 1 - Must be a positive integer (1 or greater) **See** https://www.rabbitmq.com/docs/quorum-queues#poison-message-handling **Example** `const orderQueue = defineQueue('order-processing', { type: 'quorum', deliveryLimit: 5, // Allow up to 5 delivery attempts deadLetter: { exchange: dlx, routingKey: 'order.failed', }, });` | [types.ts:263](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L263) |
|
|
983
|
+
| `exclusive?` | `never` | Quorum queues do not support exclusive mode. Use type: 'classic' if you need exclusive queues. | [types.ts:224](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L224) |
|
|
984
|
+
| `maxPriority?` | `never` | Quorum queues do not support priority queues. Use type: 'classic' if you need priority queues. | [types.ts:230](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L230) |
|
|
985
|
+
| `retry?` | \| [`TtlBackoffRetryOptions`](#ttlbackoffretryoptions) \| [`QuorumNativeRetryOptions`](#quorumnativeretryoptions) | Retry configuration for handling failed message processing. Determines how the worker handles retries for consumers using this queue: - `"ttl-backoff"` (default): Uses wait queues with exponential backoff - `"quorum-native"`: Uses RabbitMQ's native delivery limit feature When using `"ttl-backoff"` mode, the core package will automatically create a wait queue (`{queueName}-wait`) and the necessary bindings. **Example** `// TTL-backoff mode with custom options const orderQueue = defineQueue('order-processing', { type: 'quorum', deadLetter: { exchange: dlx }, retry: { mode: 'ttl-backoff', maxRetries: 5, initialDelayMs: 1000, maxDelayMs: 30000, }, }); // Quorum-native mode const orderQueue = defineQueue('order-processing', { type: 'quorum', deliveryLimit: 5, deadLetter: { exchange: dlx }, retry: { mode: 'quorum-native' }, });` | [types.ts:298](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L298) |
|
|
986
|
+
| `type?` | `"quorum"` | Queue type: quorum (default, recommended) | [types.ts:218](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L218) |
|
|
987
|
+
|
|
988
|
+
#### Example
|
|
989
|
+
|
|
990
|
+
```typescript
|
|
991
|
+
const orderQueue = defineQueue('orders', {
|
|
992
|
+
type: 'quorum',
|
|
993
|
+
deadLetter: { exchange: dlx },
|
|
994
|
+
deliveryLimit: 3, // Message dead-lettered after 3 delivery attempts
|
|
995
|
+
});
|
|
996
|
+
```
|
|
997
|
+
|
|
998
|
+
***
|
|
999
|
+
|
|
1000
|
+
### ResolvedRetryOptions
|
|
1001
|
+
|
|
1002
|
+
```ts
|
|
1003
|
+
type ResolvedRetryOptions =
|
|
1004
|
+
| ResolvedTtlBackoffRetryOptions
|
|
1005
|
+
| QuorumNativeRetryOptions;
|
|
1006
|
+
```
|
|
1007
|
+
|
|
1008
|
+
Defined in: [types.ts:104](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L104)
|
|
1009
|
+
|
|
1010
|
+
Resolved retry configuration stored in queue definitions.
|
|
1011
|
+
|
|
1012
|
+
This is a discriminated union based on the `mode` field:
|
|
1013
|
+
- `ttl-backoff`: Has all TTL-backoff options with defaults applied
|
|
1014
|
+
- `quorum-native`: No additional options (uses RabbitMQ native retry)
|
|
732
1015
|
|
|
733
1016
|
***
|
|
734
1017
|
|
|
@@ -738,7 +1021,7 @@ to receive messages based on routing rules.
|
|
|
738
1021
|
type RoutingKey<S> = S extends "" ? never : S extends `${string}*${string}` | `${string}#${string}` ? never : S;
|
|
739
1022
|
```
|
|
740
1023
|
|
|
741
|
-
Defined in: [builder.ts:
|
|
1024
|
+
Defined in: [builder/routing-types.ts:25](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/routing-types.ts#L25)
|
|
742
1025
|
|
|
743
1026
|
Type-safe routing key that validates basic format.
|
|
744
1027
|
|
|
@@ -772,7 +1055,7 @@ type Invalid2 = RoutingKey<"">; // never (empty string)
|
|
|
772
1055
|
type TopicExchangeDefinition = BaseExchangeDefinition & object;
|
|
773
1056
|
```
|
|
774
1057
|
|
|
775
|
-
Defined in: [types.ts:
|
|
1058
|
+
Defined in: [types.ts:459](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L459)
|
|
776
1059
|
|
|
777
1060
|
A topic exchange definition.
|
|
778
1061
|
|
|
@@ -786,7 +1069,7 @@ Words are separated by dots (e.g., `order.created.high-value`).
|
|
|
786
1069
|
|
|
787
1070
|
| Name | Type | Defined in |
|
|
788
1071
|
| ------ | ------ | ------ |
|
|
789
|
-
| `type` | `"topic"` | [types.ts:
|
|
1072
|
+
| `type` | `"topic"` | [types.ts:460](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L460) |
|
|
790
1073
|
|
|
791
1074
|
#### Example
|
|
792
1075
|
|
|
@@ -797,6 +1080,57 @@ const ordersExchange: TopicExchangeDefinition = defineExchange('orders', 'topic'
|
|
|
797
1080
|
// Can be bound with patterns like 'order.*' or 'order.#'
|
|
798
1081
|
```
|
|
799
1082
|
|
|
1083
|
+
***
|
|
1084
|
+
|
|
1085
|
+
### TtlBackoffRetryInfrastructure
|
|
1086
|
+
|
|
1087
|
+
```ts
|
|
1088
|
+
type TtlBackoffRetryInfrastructure = object;
|
|
1089
|
+
```
|
|
1090
|
+
|
|
1091
|
+
Defined in: [builder/ttl-backoff.ts:10](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/ttl-backoff.ts#L10)
|
|
1092
|
+
|
|
1093
|
+
Result type for TTL-backoff retry infrastructure builder.
|
|
1094
|
+
|
|
1095
|
+
Contains the wait queue and bindings needed for TTL-backoff retry.
|
|
1096
|
+
|
|
1097
|
+
#### Properties
|
|
1098
|
+
|
|
1099
|
+
| Property | Type | Description | Defined in |
|
|
1100
|
+
| ------ | ------ | ------ | ------ |
|
|
1101
|
+
| <a id="mainqueueretrybinding-1"></a> `mainQueueRetryBinding` | [`QueueBindingDefinition`](#queuebindingdefinition) | Binding that routes retried messages back to the main queue. | [builder/ttl-backoff.ts:23](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/ttl-backoff.ts#L23) |
|
|
1102
|
+
| <a id="waitqueue-1"></a> `waitQueue` | [`QueueDefinition`](#queuedefinition) | The wait queue for holding messages during backoff delay. This is a classic queue with a dead letter exchange pointing back to the main queue. | [builder/ttl-backoff.ts:15](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/ttl-backoff.ts#L15) |
|
|
1103
|
+
| <a id="waitqueuebinding-1"></a> `waitQueueBinding` | [`QueueBindingDefinition`](#queuebindingdefinition) | Binding that routes failed messages to the wait queue. | [builder/ttl-backoff.ts:19](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/ttl-backoff.ts#L19) |
|
|
1104
|
+
|
|
1105
|
+
***
|
|
1106
|
+
|
|
1107
|
+
### TtlBackoffRetryOptions
|
|
1108
|
+
|
|
1109
|
+
```ts
|
|
1110
|
+
type TtlBackoffRetryOptions = object;
|
|
1111
|
+
```
|
|
1112
|
+
|
|
1113
|
+
Defined in: [types.ts:27](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L27)
|
|
1114
|
+
|
|
1115
|
+
TTL-Backoff retry options for exponential backoff with configurable delays.
|
|
1116
|
+
|
|
1117
|
+
Uses TTL + wait queue pattern. Messages are published to a wait queue with
|
|
1118
|
+
per-message TTL, then dead-lettered back to the main queue after the TTL expires.
|
|
1119
|
+
|
|
1120
|
+
**Benefits:** Configurable delays with exponential backoff and jitter.
|
|
1121
|
+
**Limitation:** More complex, potential head-of-queue blocking with mixed TTLs.
|
|
1122
|
+
|
|
1123
|
+
#### Properties
|
|
1124
|
+
|
|
1125
|
+
| Property | Type | Description | Defined in |
|
|
1126
|
+
| ------ | ------ | ------ | ------ |
|
|
1127
|
+
| <a id="backoffmultiplier"></a> `backoffMultiplier?` | `number` | Exponential backoff multiplier. **Default** `2` | [types.ts:51](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L51) |
|
|
1128
|
+
| <a id="initialdelayms"></a> `initialDelayMs?` | `number` | Initial delay in ms before first retry. **Default** `1000` | [types.ts:41](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L41) |
|
|
1129
|
+
| <a id="jitter"></a> `jitter?` | `boolean` | Add jitter to prevent thundering herd. **Default** `true` | [types.ts:56](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L56) |
|
|
1130
|
+
| <a id="maxdelayms"></a> `maxDelayMs?` | `number` | Maximum delay in ms between retries. **Default** `30000` | [types.ts:46](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L46) |
|
|
1131
|
+
| <a id="maxretries"></a> `maxRetries?` | `number` | Maximum retry attempts before sending to DLQ. **Default** `3` | [types.ts:36](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L36) |
|
|
1132
|
+
| <a id="mode-1"></a> `mode` | `"ttl-backoff"` | TTL-Backoff mode uses wait queues with per-message TTL for exponential backoff. | [types.ts:31](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/types.ts#L31) |
|
|
1133
|
+
|
|
800
1134
|
## Functions
|
|
801
1135
|
|
|
802
1136
|
### defineConsumer()
|
|
@@ -805,10 +1139,10 @@ const ordersExchange: TopicExchangeDefinition = defineExchange('orders', 'topic'
|
|
|
805
1139
|
function defineConsumer<TMessage>(
|
|
806
1140
|
queue,
|
|
807
1141
|
message,
|
|
808
|
-
options?): ConsumerDefinition<TMessage>;
|
|
1142
|
+
options?): ConsumerDefinition<TMessage>;
|
|
809
1143
|
```
|
|
810
1144
|
|
|
811
|
-
Defined in: [builder.ts:
|
|
1145
|
+
Defined in: [builder/consumer.ts:46](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/consumer.ts#L46)
|
|
812
1146
|
|
|
813
1147
|
Define a message consumer.
|
|
814
1148
|
|
|
@@ -828,13 +1162,13 @@ with this consumer, it will process messages from the queue according to the sch
|
|
|
828
1162
|
|
|
829
1163
|
| Parameter | Type | Description |
|
|
830
1164
|
| ------ | ------ | ------ |
|
|
831
|
-
| `queue` | [`
|
|
1165
|
+
| `queue` | [`QueueEntry`](#queueentry) | The queue definition to consume from |
|
|
832
1166
|
| `message` | `TMessage` | The message definition with payload schema |
|
|
833
|
-
| `options?` | `Omit
|
|
1167
|
+
| `options?` | `Omit`<[`ConsumerDefinition`](#consumerdefinition)<`TMessage`>, `"queue"` \| `"message"`> | Optional consumer configuration |
|
|
834
1168
|
|
|
835
1169
|
#### Returns
|
|
836
1170
|
|
|
837
|
-
[`ConsumerDefinition`](#consumerdefinition)
|
|
1171
|
+
[`ConsumerDefinition`](#consumerdefinition)<`TMessage`>
|
|
838
1172
|
|
|
839
1173
|
A consumer definition with inferred message types
|
|
840
1174
|
|
|
@@ -875,7 +1209,7 @@ const processOrderConsumer = defineConsumer(orderQueue, orderMessage);
|
|
|
875
1209
|
function defineContract<TContract>(definition): TContract;
|
|
876
1210
|
```
|
|
877
1211
|
|
|
878
|
-
Defined in: [builder.ts:
|
|
1212
|
+
Defined in: [builder/contract.ts:73](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/contract.ts#L73)
|
|
879
1213
|
|
|
880
1214
|
Define an AMQP contract.
|
|
881
1215
|
|
|
@@ -964,7 +1298,7 @@ export const contract = defineContract({
|
|
|
964
1298
|
function defineMessage<TPayload, THeaders>(payload, options?): MessageDefinition<TPayload, THeaders>;
|
|
965
1299
|
```
|
|
966
1300
|
|
|
967
|
-
Defined in: [builder.ts:
|
|
1301
|
+
Defined in: [builder/message.ts:39](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/message.ts#L39)
|
|
968
1302
|
|
|
969
1303
|
Define a message definition with payload and optional headers/metadata.
|
|
970
1304
|
|
|
@@ -977,7 +1311,7 @@ The schemas are used for automatic validation when publishing or consuming messa
|
|
|
977
1311
|
| Type Parameter | Default type |
|
|
978
1312
|
| ------ | ------ |
|
|
979
1313
|
| `TPayload` *extends* [`AnySchema`](#anyschema) | - |
|
|
980
|
-
| `THeaders` *extends* \| `StandardSchemaV1
|
|
1314
|
+
| `THeaders` *extends* \| `StandardSchemaV1`<`Record`<`string`, `unknown`>, `Record`<`string`, `unknown`>> \| `undefined` | `undefined` |
|
|
981
1315
|
|
|
982
1316
|
#### Parameters
|
|
983
1317
|
|
|
@@ -991,7 +1325,7 @@ The schemas are used for automatic validation when publishing or consuming messa
|
|
|
991
1325
|
|
|
992
1326
|
#### Returns
|
|
993
1327
|
|
|
994
|
-
[`MessageDefinition`](#messagedefinition)
|
|
1328
|
+
[`MessageDefinition`](#messagedefinition)<`TPayload`, `THeaders`>
|
|
995
1329
|
|
|
996
1330
|
A message definition with inferred types
|
|
997
1331
|
|
|
@@ -1022,47 +1356,46 @@ const orderMessage = defineMessage(
|
|
|
1022
1356
|
### defineQueue()
|
|
1023
1357
|
|
|
1024
1358
|
```ts
|
|
1025
|
-
function defineQueue(name, options?):
|
|
1359
|
+
function defineQueue(name, options?):
|
|
1360
|
+
| QueueDefinition
|
|
1361
|
+
| QueueWithTtlBackoffInfrastructure;
|
|
1026
1362
|
```
|
|
1027
1363
|
|
|
1028
|
-
Defined in: [builder.ts:
|
|
1364
|
+
Defined in: [builder/queue.ts:180](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/queue.ts#L180)
|
|
1029
1365
|
|
|
1030
1366
|
Define an AMQP queue.
|
|
1031
1367
|
|
|
1032
1368
|
A queue stores messages until they are consumed by workers. Queues can be bound to exchanges
|
|
1033
1369
|
to receive messages based on routing rules.
|
|
1034
1370
|
|
|
1371
|
+
By default, queues are created as quorum queues which provide better durability and
|
|
1372
|
+
high-availability. Use `type: 'classic'` for special cases like non-durable queues
|
|
1373
|
+
or priority queues.
|
|
1374
|
+
|
|
1035
1375
|
#### Parameters
|
|
1036
1376
|
|
|
1037
1377
|
| Parameter | Type | Description |
|
|
1038
1378
|
| ------ | ------ | ------ |
|
|
1039
1379
|
| `name` | `string` | The name of the queue |
|
|
1040
|
-
| `options?` |
|
|
1380
|
+
| `options?` | [`DefineQueueOptions`](#definequeueoptions) | Optional queue configuration |
|
|
1041
1381
|
|
|
1042
1382
|
#### Returns
|
|
1043
1383
|
|
|
1044
|
-
[`QueueDefinition`](#queuedefinition)
|
|
1384
|
+
\| [`QueueDefinition`](#queuedefinition)
|
|
1385
|
+
\| [`QueueWithTtlBackoffInfrastructure`](#queuewithttlbackoffinfrastructure)
|
|
1045
1386
|
|
|
1046
1387
|
A queue definition
|
|
1047
1388
|
|
|
1048
1389
|
#### Example
|
|
1049
1390
|
|
|
1050
1391
|
```typescript
|
|
1051
|
-
//
|
|
1052
|
-
const orderQueue = defineQueue('order-processing'
|
|
1053
|
-
durable: true,
|
|
1054
|
-
});
|
|
1055
|
-
|
|
1056
|
-
// Priority queue with max priority of 10
|
|
1057
|
-
const taskQueue = defineQueue('urgent-tasks', {
|
|
1058
|
-
durable: true,
|
|
1059
|
-
maxPriority: 10,
|
|
1060
|
-
});
|
|
1392
|
+
// Quorum queue (default, recommended for production)
|
|
1393
|
+
const orderQueue = defineQueue('order-processing');
|
|
1061
1394
|
|
|
1062
|
-
//
|
|
1395
|
+
// Explicit quorum queue with dead letter exchange
|
|
1063
1396
|
const dlx = defineExchange('orders-dlx', 'topic', { durable: true });
|
|
1064
1397
|
const orderQueueWithDLX = defineQueue('order-processing', {
|
|
1065
|
-
|
|
1398
|
+
type: 'quorum',
|
|
1066
1399
|
deadLetter: {
|
|
1067
1400
|
exchange: dlx,
|
|
1068
1401
|
routingKey: 'order.failed'
|
|
@@ -1071,4 +1404,131 @@ const orderQueueWithDLX = defineQueue('order-processing', {
|
|
|
1071
1404
|
'x-message-ttl': 86400000, // 24 hours
|
|
1072
1405
|
}
|
|
1073
1406
|
});
|
|
1407
|
+
|
|
1408
|
+
// Classic queue (for special cases)
|
|
1409
|
+
const tempQueue = defineQueue('temp-queue', {
|
|
1410
|
+
type: 'classic',
|
|
1411
|
+
durable: false,
|
|
1412
|
+
autoDelete: true,
|
|
1413
|
+
});
|
|
1414
|
+
|
|
1415
|
+
// Priority queue (requires classic type)
|
|
1416
|
+
const taskQueue = defineQueue('urgent-tasks', {
|
|
1417
|
+
type: 'classic',
|
|
1418
|
+
durable: true,
|
|
1419
|
+
maxPriority: 10,
|
|
1420
|
+
});
|
|
1421
|
+
|
|
1422
|
+
// Queue with TTL-backoff retry (returns infrastructure automatically)
|
|
1423
|
+
const dlx = defineExchange('orders-dlx', 'direct', { durable: true });
|
|
1424
|
+
const orderQueue = defineQueue('order-processing', {
|
|
1425
|
+
deadLetter: { exchange: dlx },
|
|
1426
|
+
retry: { mode: 'ttl-backoff', maxRetries: 5 },
|
|
1427
|
+
});
|
|
1428
|
+
// orderQueue is QueueWithTtlBackoffInfrastructure, pass directly to defineContract
|
|
1429
|
+
```
|
|
1430
|
+
|
|
1431
|
+
***
|
|
1432
|
+
|
|
1433
|
+
### defineTtlBackoffRetryInfrastructure()
|
|
1434
|
+
|
|
1435
|
+
```ts
|
|
1436
|
+
function defineTtlBackoffRetryInfrastructure(queueEntry, options?): TtlBackoffRetryInfrastructure;
|
|
1437
|
+
```
|
|
1438
|
+
|
|
1439
|
+
Defined in: [builder/ttl-backoff.ts:76](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/ttl-backoff.ts#L76)
|
|
1440
|
+
|
|
1441
|
+
Create TTL-backoff retry infrastructure for a queue.
|
|
1442
|
+
|
|
1443
|
+
This builder helper generates the wait queue and bindings needed for TTL-backoff retry.
|
|
1444
|
+
The generated infrastructure can be spread into a contract definition.
|
|
1445
|
+
|
|
1446
|
+
TTL-backoff retry works by:
|
|
1447
|
+
1. Failed messages are sent to the DLX with routing key `{queueName}-wait`
|
|
1448
|
+
2. The wait queue receives these messages and holds them for a TTL period
|
|
1449
|
+
3. After TTL expires, messages are dead-lettered back to the DLX with routing key `{queueName}`
|
|
1450
|
+
4. The main queue receives the retried message via its binding to the DLX
|
|
1451
|
+
|
|
1452
|
+
#### Parameters
|
|
1453
|
+
|
|
1454
|
+
| Parameter | Type | Description |
|
|
1455
|
+
| ------ | ------ | ------ |
|
|
1456
|
+
| `queueEntry` | [`QueueEntry`](#queueentry) | - |
|
|
1457
|
+
| `options?` | \{ `waitQueueDurable?`: `boolean`; \} | Optional configuration for the wait queue |
|
|
1458
|
+
| `options.waitQueueDurable?` | `boolean` | Whether the wait queue should be durable (default: same as main queue) |
|
|
1459
|
+
|
|
1460
|
+
#### Returns
|
|
1461
|
+
|
|
1462
|
+
[`TtlBackoffRetryInfrastructure`](#ttlbackoffretryinfrastructure)
|
|
1463
|
+
|
|
1464
|
+
TTL-backoff retry infrastructure containing wait queue and bindings
|
|
1465
|
+
|
|
1466
|
+
#### Throws
|
|
1467
|
+
|
|
1468
|
+
If the queue does not have a dead letter exchange configured
|
|
1469
|
+
|
|
1470
|
+
#### Example
|
|
1471
|
+
|
|
1472
|
+
```typescript
|
|
1473
|
+
const dlx = defineExchange('orders-dlx', 'direct', { durable: true });
|
|
1474
|
+
const orderQueue = defineQueue('order-processing', {
|
|
1475
|
+
type: 'quorum',
|
|
1476
|
+
deadLetter: { exchange: dlx },
|
|
1477
|
+
retry: {
|
|
1478
|
+
mode: 'ttl-backoff',
|
|
1479
|
+
maxRetries: 5,
|
|
1480
|
+
initialDelayMs: 1000,
|
|
1481
|
+
},
|
|
1482
|
+
});
|
|
1483
|
+
|
|
1484
|
+
// Generate TTL-backoff infrastructure
|
|
1485
|
+
const retryInfra = defineTtlBackoffRetryInfrastructure(orderQueue);
|
|
1486
|
+
|
|
1487
|
+
// Spread into contract
|
|
1488
|
+
const contract = defineContract({
|
|
1489
|
+
exchanges: { dlx },
|
|
1490
|
+
queues: {
|
|
1491
|
+
orderProcessing: orderQueue,
|
|
1492
|
+
orderProcessingWait: retryInfra.waitQueue,
|
|
1493
|
+
},
|
|
1494
|
+
bindings: {
|
|
1495
|
+
...// your other bindings
|
|
1496
|
+
orderWaitBinding: retryInfra.waitQueueBinding,
|
|
1497
|
+
orderRetryBinding: retryInfra.mainQueueRetryBinding,
|
|
1498
|
+
},
|
|
1499
|
+
// ... publishers and consumers
|
|
1500
|
+
});
|
|
1501
|
+
```
|
|
1502
|
+
|
|
1503
|
+
***
|
|
1504
|
+
|
|
1505
|
+
### extractQueue()
|
|
1506
|
+
|
|
1507
|
+
```ts
|
|
1508
|
+
function extractQueue(entry): QueueDefinition;
|
|
1509
|
+
```
|
|
1510
|
+
|
|
1511
|
+
Defined in: [builder/queue.ts:62](https://github.com/btravers/amqp-contract/blob/c50b9d5f661ce899d34d7eebcfafa47844bd1087/packages/contract/src/builder/queue.ts#L62)
|
|
1512
|
+
|
|
1513
|
+
Extract the plain QueueDefinition from a QueueEntry.
|
|
1514
|
+
If the entry is a QueueWithTtlBackoffInfrastructure, returns the inner queue.
|
|
1515
|
+
Otherwise, returns the entry as-is.
|
|
1516
|
+
|
|
1517
|
+
#### Parameters
|
|
1518
|
+
|
|
1519
|
+
| Parameter | Type | Description |
|
|
1520
|
+
| ------ | ------ | ------ |
|
|
1521
|
+
| `entry` | [`QueueEntry`](#queueentry) | The queue entry (either plain QueueDefinition or QueueWithTtlBackoffInfrastructure) |
|
|
1522
|
+
|
|
1523
|
+
#### Returns
|
|
1524
|
+
|
|
1525
|
+
[`QueueDefinition`](#queuedefinition)
|
|
1526
|
+
|
|
1527
|
+
The plain QueueDefinition
|
|
1528
|
+
|
|
1529
|
+
#### Example
|
|
1530
|
+
|
|
1531
|
+
```typescript
|
|
1532
|
+
const queue = defineQueue('orders', { retry: { mode: 'ttl-backoff' }, deadLetter: { exchange: dlx } });
|
|
1533
|
+
const plainQueue = extractQueue(queue); // Returns the inner QueueDefinition
|
|
1074
1534
|
```
|