@entifix/amqp 0.10.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { WiringRegistry } from '@entifix/business';
|
|
2
2
|
import { ShutdownRegistryTag, WiringRegistryTag } from '@entifix/business';
|
|
3
3
|
import { type EventBus, EventBusTag, type Subscription } from '@entifix/transactions';
|
|
4
|
-
import { Effect, Layer } from 'effect';
|
|
4
|
+
import { Duration, Effect, Layer } from 'effect';
|
|
5
5
|
import { AmqpChannelTag, type AmqpConnector } from '../amqp-connection/amqp-connection.js';
|
|
6
6
|
/**
|
|
7
7
|
* The queue a subscription binds.
|
|
@@ -21,6 +21,27 @@ import { AmqpChannelTag, type AmqpConnector } from '../amqp-connection/amqp-conn
|
|
|
21
21
|
* three saved characters.
|
|
22
22
|
*/
|
|
23
23
|
export declare const queueNameFor: (subscription: Subscription) => string;
|
|
24
|
+
/**
|
|
25
|
+
* The adapter's own count of the attempts a message has failed, carried on the
|
|
26
|
+
* copy it republishes (#130).
|
|
27
|
+
*
|
|
28
|
+
* The broker cannot be trusted with it. RabbitMQ 4 does not count a requeued
|
|
29
|
+
* `basic.nack` toward a quorum queue's `x-delivery-limit` — measured on 4.3.5:
|
|
30
|
+
* a queue limited to 2 delivered one message 8 times and never set
|
|
31
|
+
* `x-delivery-count` — so a transient failure that never cleared was
|
|
32
|
+
* redelivered without a ceiling and without a pause. `x-delivery-limit` stays
|
|
33
|
+
* on the queue, where it still bounds the redeliveries a crashed consumer
|
|
34
|
+
* causes, which the broker does count.
|
|
35
|
+
*/
|
|
36
|
+
export declare const ATTEMPTS_HEADER = "x-entifix-attempts";
|
|
37
|
+
/** How long a transient failure waits before its copy goes back on the queue. */
|
|
38
|
+
export type RedeliveryBackoff = (attempt: number) => Duration.Duration;
|
|
39
|
+
/**
|
|
40
|
+
* Doubling from 100 ms, capped at two seconds. The wait holds the delivery —
|
|
41
|
+
* the queue is `prefetch(1)`, so it pauses this consumer — which is the point:
|
|
42
|
+
* a dependency that is down is not helped by asking it again at once.
|
|
43
|
+
*/
|
|
44
|
+
export declare const DEFAULT_REDELIVERY_BACKOFF: RedeliveryBackoff;
|
|
24
45
|
/**
|
|
25
46
|
* RabbitMQ-backed {@link EventBus}. Events go out as `event` envelopes on the
|
|
26
47
|
* shared topic exchange — the adapter owns the wire framing, so the port stays
|
|
@@ -48,7 +69,9 @@ export declare const queueNameFor: (subscription: Subscription) => string;
|
|
|
48
69
|
* runs them — and putting it on `EventBus` would make every implementation of
|
|
49
70
|
* a framework-free port carry a shutdown concern it has no deliveries to drain.
|
|
50
71
|
*/
|
|
51
|
-
export declare const makeAmqpEventBus: (connector: AmqpConnector, wiring: WiringRegistry
|
|
72
|
+
export declare const makeAmqpEventBus: (connector: AmqpConnector, wiring: WiringRegistry, options?: {
|
|
73
|
+
readonly redeliveryBackoff?: RedeliveryBackoff;
|
|
74
|
+
}) => {
|
|
52
75
|
bus: EventBus;
|
|
53
76
|
drainDeliveries: Effect.Effect<void>;
|
|
54
77
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amqp-event-bus.d.ts","sourceRoot":"","sources":["../../src/adapters/amqp-event-bus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAO3E,OAAO,EACL,KAAK,QAAQ,EACb,WAAW,EACX,KAAK,YAAY,
|
|
1
|
+
{"version":3,"file":"amqp-event-bus.d.ts","sourceRoot":"","sources":["../../src/adapters/amqp-event-bus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAO3E,OAAO,EACL,KAAK,QAAQ,EACb,WAAW,EACX,KAAK,YAAY,EAClB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEjD,OAAO,EACL,cAAc,EACd,KAAK,aAAa,EAGnB,MAAM,uCAAuC,CAAC;AAuE/C;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,YAAY,GAAI,cAAc,YAAY,KAAG,MAG1B,CAAC;AAsDjC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,uBAAuB,CAAC;AASpD,iFAAiF;AACjF,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,QAAQ,CAAC,QAAQ,CAAC;AAEvE;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,EAAE,iBACmB,CAAC;AAoF7D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,gBAAgB,GAC3B,WAAW,aAAa,EACxB,QAAQ,cAAc,EACtB,UAAS;IAAE,QAAQ,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,CAAA;CAAO,KAC/D;IAAE,GAAG,EAAE,QAAQ,CAAC;IAAC,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;CAqKvD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,2FAuB7B,CAAC"}
|
|
@@ -19,9 +19,10 @@ import { recordConsumed, recordFailed, recordPublished, recordPublishFailure } f
|
|
|
19
19
|
* ([ADR 0013](../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)):
|
|
20
20
|
* an answer redelivered is the same answer, so every business failure is
|
|
21
21
|
* poison, and so is `protocol` — bytes that did not decode will not decode on
|
|
22
|
-
* the fifth try. The transient categories are redelivered, bounded by
|
|
23
|
-
* `
|
|
24
|
-
* wrong is not evidence that retrying is
|
|
22
|
+
* the fifth try. The transient categories are redelivered, bounded by the
|
|
23
|
+
* subscription's `maxAttempts` as the adapter counts them, and so is anything
|
|
24
|
+
* uncategorised: not knowing what went wrong is not evidence that retrying is
|
|
25
|
+
* pointless.
|
|
25
26
|
*/ const classify = (error)=>isFailure(error) ? {
|
|
26
27
|
kind: error.family === 'business' || error.category === 'protocol' ? 'poison' : 'transient',
|
|
27
28
|
code: error.code,
|
|
@@ -58,9 +59,11 @@ import { recordConsumed, recordFailed, recordPublished, recordPublishFailure } f
|
|
|
58
59
|
*
|
|
59
60
|
* A **work** queue is durable and quorum-backed, so it survives the consumer's
|
|
60
61
|
* restart and accumulates while it is gone — the hop the outbox relay's
|
|
61
|
-
* durability chain was missing. Its retry ceiling is
|
|
62
|
-
*
|
|
63
|
-
*
|
|
62
|
+
* durability chain was missing. Its retry ceiling is the subscription's
|
|
63
|
+
* `maxAttempts`, counted by the adapter in {@link ATTEMPTS_HEADER} because the
|
|
64
|
+
* broker does not count a requeued nack (#130). The same number is the queue's
|
|
65
|
+
* `x-delivery-limit`, which bounds what the broker *does* count — a redelivery
|
|
66
|
+
* after a consumer crash.
|
|
64
67
|
*
|
|
65
68
|
* The quarantine is declared **first**: a message dead-lettered the instant the
|
|
66
69
|
* work queue exists must have somewhere to land, and a `direct` exchange with
|
|
@@ -100,43 +103,85 @@ import { recordConsumed, recordFailed, recordPublished, recordPublishFailure } f
|
|
|
100
103
|
return queue;
|
|
101
104
|
};
|
|
102
105
|
/**
|
|
103
|
-
*
|
|
106
|
+
* The adapter's own count of the attempts a message has failed, carried on the
|
|
107
|
+
* copy it republishes (#130).
|
|
104
108
|
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
|
|
109
|
+
* The broker cannot be trusted with it. RabbitMQ 4 does not count a requeued
|
|
110
|
+
* `basic.nack` toward a quorum queue's `x-delivery-limit` — measured on 4.3.5:
|
|
111
|
+
* a queue limited to 2 delivered one message 8 times and never set
|
|
112
|
+
* `x-delivery-count` — so a transient failure that never cleared was
|
|
113
|
+
* redelivered without a ceiling and without a pause. `x-delivery-limit` stays
|
|
114
|
+
* on the queue, where it still bounds the redeliveries a crashed consumer
|
|
115
|
+
* causes, which the broker does count.
|
|
116
|
+
*/ export const ATTEMPTS_HEADER = 'x-entifix-attempts';
|
|
117
|
+
const attemptsSoFar = (message)=>{
|
|
118
|
+
var _message_properties_headers, _message_properties;
|
|
119
|
+
const value = (_message_properties = message.properties) == null ? void 0 : (_message_properties_headers = _message_properties.headers) == null ? void 0 : _message_properties_headers[ATTEMPTS_HEADER];
|
|
120
|
+
return typeof value === 'number' && Number.isInteger(value) && value > 0 ? value : 0;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Doubling from 100 ms, capped at two seconds. The wait holds the delivery —
|
|
124
|
+
* the queue is `prefetch(1)`, so it pauses this consumer — which is the point:
|
|
125
|
+
* a dependency that is down is not helped by asking it again at once.
|
|
126
|
+
*/ export const DEFAULT_REDELIVERY_BACKOFF = (attempt)=>Duration.millis(Math.min(100 * 2 ** (attempt - 1), 2000));
|
|
127
|
+
/**
|
|
110
128
|
* Settles a delivery that failed.
|
|
111
129
|
*
|
|
112
|
-
* Poison on a `work` queue
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
130
|
+
* Poison on a `work` queue — and a transient failure that has spent the
|
|
131
|
+
* subscription's `maxAttempts` — is republished to the dead-letter exchange
|
|
132
|
+
* **with its reason**: `x-failure-code`, `x-failure-category` and the attempts
|
|
133
|
+
* spent. It is then acked rather than nacked, because a nack cannot carry
|
|
134
|
+
* headers, and a quarantine of messages nobody can say anything about is a
|
|
135
|
+
* queue an operator has to replay blind. If that publish is refused the nack
|
|
136
|
+
* still quarantines it, reasonless.
|
|
117
137
|
*
|
|
118
|
-
* A transient failure
|
|
119
|
-
* queue
|
|
120
|
-
|
|
121
|
-
|
|
138
|
+
* A transient failure under the ceiling waits its backoff, goes back on its own
|
|
139
|
+
* queue as a copy carrying the attempt count, and the original is acked. If
|
|
140
|
+
* that publish is refused it is nacked for the broker to redeliver, which is
|
|
141
|
+
* the old behaviour and still better than losing it. A `broadcast` queue has no
|
|
142
|
+
* quarantine and no ceiling, so its failures are dropped.
|
|
143
|
+
*/ const settleFailure = (channel, message, queue, subscription, failure, backoff)=>{
|
|
144
|
+
if (subscription.mode === 'broadcast') {
|
|
145
|
+
return Effect.sync(()=>channel.nack(message, false, false));
|
|
146
|
+
}
|
|
147
|
+
const attempts = failure.kind === 'transient' ? attemptsSoFar(message) + 1 : 0;
|
|
148
|
+
if (failure.kind === 'poison' || attempts >= subscription.maxAttempts) {
|
|
149
|
+
return Effect.sync(()=>quarantine(channel, message, queue, failure, attempts));
|
|
150
|
+
}
|
|
151
|
+
const wait = backoff(attempts);
|
|
152
|
+
return (Duration.isZero(wait) ? Effect.void : Effect.sleep(wait)).pipe(Effect.andThen(Effect.sync(()=>{
|
|
122
153
|
try {
|
|
123
154
|
var _message_properties;
|
|
124
|
-
channel.publish(
|
|
155
|
+
channel.publish('', queue, message.content, _extends({}, message.properties, {
|
|
125
156
|
persistent: true,
|
|
126
157
|
headers: _extends({}, (_message_properties = message.properties) == null ? void 0 : _message_properties.headers, {
|
|
127
|
-
|
|
128
|
-
'x-failure-category': failure.category
|
|
158
|
+
[ATTEMPTS_HEADER]: attempts
|
|
129
159
|
})
|
|
130
160
|
}));
|
|
131
161
|
channel.ack(message);
|
|
132
|
-
return;
|
|
133
162
|
} catch (unused) {
|
|
134
|
-
|
|
163
|
+
channel.nack(message, false, true);
|
|
135
164
|
}
|
|
165
|
+
})));
|
|
166
|
+
};
|
|
167
|
+
const quarantine = (channel, message, queue, failure, attempts)=>{
|
|
168
|
+
try {
|
|
169
|
+
var _message_properties;
|
|
170
|
+
channel.publish(EVENTS_DLX, queue, message.content, _extends({}, message.properties, {
|
|
171
|
+
persistent: true,
|
|
172
|
+
headers: _extends({}, (_message_properties = message.properties) == null ? void 0 : _message_properties.headers, {
|
|
173
|
+
'x-failure-code': failure.code,
|
|
174
|
+
'x-failure-category': failure.category
|
|
175
|
+
}, attempts > 0 ? {
|
|
176
|
+
[ATTEMPTS_HEADER]: attempts
|
|
177
|
+
} : {})
|
|
178
|
+
}));
|
|
179
|
+
channel.ack(message);
|
|
180
|
+
} catch (unused) {
|
|
181
|
+
// Quarantined without its reason beats not quarantined.
|
|
182
|
+
channel.nack(message, false, false);
|
|
136
183
|
}
|
|
137
|
-
channel.nack(message, false, requeues(failure, mode));
|
|
138
184
|
};
|
|
139
|
-
const requeues = (failure, mode)=>failure.kind === 'transient' && mode === 'work';
|
|
140
185
|
/**
|
|
141
186
|
* RabbitMQ-backed {@link EventBus}. Events go out as `event` envelopes on the
|
|
142
187
|
* shared topic exchange — the adapter owns the wire framing, so the port stays
|
|
@@ -163,7 +208,9 @@ const requeues = (failure, mode)=>failure.kind === 'transient' && mode === 'work
|
|
|
163
208
|
* waiting for in-flight handlers is an adapter fact — it is this module that
|
|
164
209
|
* runs them — and putting it on `EventBus` would make every implementation of
|
|
165
210
|
* a framework-free port carry a shutdown concern it has no deliveries to drain.
|
|
166
|
-
*/ export const makeAmqpEventBus = (connector, wiring)=>{
|
|
211
|
+
*/ export const makeAmqpEventBus = (connector, wiring, options = {})=>{
|
|
212
|
+
var _options_redeliveryBackoff;
|
|
213
|
+
const backoff = (_options_redeliveryBackoff = options.redeliveryBackoff) != null ? _options_redeliveryBackoff : DEFAULT_REDELIVERY_BACKOFF;
|
|
167
214
|
/**
|
|
168
215
|
* Handlers started and not yet settled.
|
|
169
216
|
*
|
|
@@ -235,7 +282,7 @@ const requeues = (failure, mode)=>failure.kind === 'transient' && mode === 'work
|
|
|
235
282
|
// is the *only* thing that can tell a malformed one from a bad
|
|
236
283
|
// afternoon at the database — and it says so by failing with
|
|
237
284
|
// a business or `protocol` failure, which quarantines at once
|
|
238
|
-
// instead of spending `
|
|
285
|
+
// instead of spending `maxAttempts` on every message
|
|
239
286
|
// behind it. Measured on `catalog.published`: a payload the
|
|
240
287
|
// contract rejected used to take five deliveries to quarantine.
|
|
241
288
|
Effect.flatMap((event)=>handler(event).pipe(Effect.mapError(classify))));
|
|
@@ -250,7 +297,7 @@ const requeues = (failure, mode)=>failure.kind === 'transient' && mode === 'work
|
|
|
250
297
|
// inside the observability layer.
|
|
251
298
|
Effect.matchEffect({
|
|
252
299
|
onSuccess: ()=>recordConsumed(tags).pipe(Effect.andThen(Effect.sync(()=>channel.ack(message)))),
|
|
253
|
-
onFailure: (failure)=>recordFailed(tags, failure.kind).pipe(Effect.andThen(
|
|
300
|
+
onFailure: (failure)=>recordFailed(tags, failure.kind).pipe(Effect.andThen(settleFailure(channel, message, queue, subscription, failure, backoff)))
|
|
254
301
|
}))).finally(()=>{
|
|
255
302
|
inFlight -= 1;
|
|
256
303
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/adapters/amqp-event-bus.ts"],"sourcesContent":["import type { WiringRegistry } from '@entifix/business';\nimport { ShutdownRegistryTag, WiringRegistryTag } from '@entifix/business';\nimport {\n isFailure,\n makeEventEnvelope,\n readEventEnvelope,\n Unavailable,\n} from '@entifix/core';\nimport {\n type EventBus,\n EventBusTag,\n type Subscription,\n type SubscriptionMode,\n} from '@entifix/transactions';\nimport type { Channel, ConsumeMessage } from 'amqplib';\nimport { Duration, Effect, Layer } from 'effect';\n\nimport {\n AmqpChannelTag,\n type AmqpConnector,\n EVENTS_DLX,\n EVENTS_EXCHANGE,\n} from '../amqp-connection/amqp-connection.js';\nimport {\n recordConsumed,\n recordFailed,\n recordPublished,\n recordPublishFailure,\n type SubscriptionTags,\n} from './bus-metrics.js';\n\n/** Appended to a work queue's name to make the queue that holds its failures. */\nconst QUARANTINE_SUFFIX = '.quarantine';\n\n/**\n * How often the shutdown drain re-checks whether the handlers have finished.\n *\n * A poll rather than a latch because a delivery is started from amqplib's own\n * callback, outside any fiber this module holds; the drain's own bound is the\n * shutdown hook's, so this interval only decides how promptly the process\n * notices it is free to go.\n */\nconst DELIVERY_POLL = Duration.millis(25);\n\n/**\n * Why a delivery did not succeed, which is the whole of the nack decision.\n *\n * `transient` is a handler that threw — a dependency briefly gone, a timeout —\n * and is worth another delivery. `poison` is a payload this process cannot\n * read, and is worth **none**: a message that cannot be deserialized never\n * becomes deserializable, so retrying it only spends the delivery budget of the\n * messages queued behind it. Conflating the two is what the adapter once did,\n * on a queue that discarded both.\n *\n * A *business* failure is neither, and never reaches here: that message was\n * handled successfully and produced its own `failed` event.\n */\ninterface DeliveryFailure {\n readonly kind: 'transient' | 'poison';\n /** The failure's code and category, carried onto a quarantined message. */\n readonly code: string;\n readonly category: string;\n}\n\n/**\n * The poison rule, by category and never by class\n * ([ADR 0013](../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)):\n * an answer redelivered is the same answer, so every business failure is\n * poison, and so is `protocol` — bytes that did not decode will not decode on\n * the fifth try. The transient categories are redelivered, bounded by\n * `x-delivery-limit`, and so is anything uncategorised: not knowing what went\n * wrong is not evidence that retrying is pointless.\n */\nconst classify = (error: unknown): DeliveryFailure =>\n isFailure(error)\n ? {\n kind:\n error.family === 'business' || error.category === 'protocol'\n ? 'poison'\n : 'transient',\n code: error.code,\n category: error.category,\n }\n : { kind: 'transient', code: 'internal', category: 'internal' };\n\n/** A payload that is not JSON: the sender's fault, decided before any handler. */\nconst UNREADABLE: DeliveryFailure = {\n kind: 'poison',\n code: 'invalidEnvelope',\n category: 'invalid',\n};\n\n/**\n * The queue a subscription binds.\n *\n * `<subscribing slice>.<pattern>`, so the name says who is owed the messages in\n * it — readable in the broker's own UI, which is where someone looks when a\n * queue has depth. The slice is the *subscriber's*, never the publisher's:\n * `EventSourceTag` names the emitter, and one deployment hosts several slices\n * (a host may co-deploy two slices in one process), so\n * deriving from it would file a consumer's queue under whoever happened to\n * publish from the same process.\n *\n * `*` and `#` are spelled out because AMQP 0-9-1 restricts a queue name to\n * letters, digits, hyphen, underscore, period and colon. RabbitMQ is lenient in\n * practice, but the name also has to survive being a URL path segment in the\n * management API, and `%2A` in an operator's address bar is a poor trade for\n * three saved characters.\n */\nexport const queueNameFor = (subscription: Subscription): string =>\n `${subscription.slice}.${subscription.pattern\n .replaceAll('*', '_star_')\n .replaceAll('#', '_hash_')}`;\n\n/**\n * Declares the queue a subscription consumes and returns its name.\n *\n * A **work** queue is durable and quorum-backed, so it survives the consumer's\n * restart and accumulates while it is gone — the hop the outbox relay's\n * durability chain was missing. Its retry ceiling is `x-delivery-limit`, a queue argument\n * rather than logic every consumer reimplements, so it also counts a\n * redelivery after a crash.\n *\n * The quarantine is declared **first**: a message dead-lettered the instant the\n * work queue exists must have somewhere to land, and a `direct` exchange with\n * no matching binding drops what it routes.\n *\n * `x-delivery-limit` is immutable once a queue exists. Re-declaring with a\n * different `maxAttempts` fails `PRECONDITION_FAILED` and closes the channel,\n * and there is no safe automatic recovery — so changing the ceiling means\n * deleting the queue, which locally is `pnpm run <app>:dev:reset`.\n */\nconst declareQueue = async (\n channel: Channel,\n subscription: Subscription,\n): Promise<string> => {\n if (subscription.mode === 'broadcast') {\n // Connection-scoped and retained by nobody, which is right only when the\n // replicas differ from one another, as a per-connection push does.\n const { queue } = await channel.assertQueue('', { exclusive: true });\n return queue;\n }\n\n const queue = queueNameFor(subscription);\n const quarantine = `${queue}${QUARANTINE_SUFFIX}`;\n\n await channel.assertQueue(quarantine, {\n durable: true,\n arguments: { 'x-queue-type': 'quorum' },\n });\n await channel.bindQueue(quarantine, EVENTS_DLX, queue);\n await channel.assertQueue(queue, {\n durable: true,\n arguments: {\n 'x-queue-type': 'quorum',\n 'x-delivery-limit': subscription.maxAttempts,\n 'x-dead-letter-exchange': EVENTS_DLX,\n 'x-dead-letter-routing-key': queue,\n },\n });\n\n return queue;\n};\n\n/**\n * Whether a failed delivery should go back on the queue.\n *\n * Only a transient failure on a **work** queue: there the broker counts the\n * redelivery against `x-delivery-limit` and dead-letters at the ceiling, so a\n * requeue is bounded. A broadcast queue has neither a ceiling nor a dead-letter\n * path, so requeueing there is an unbounded loop.\n */\n/**\n * Settles a delivery that failed.\n *\n * Poison on a `work` queue is republished to the dead-letter exchange **with\n * its reason** — `x-failure-code` and `x-failure-category` — and then acked,\n * rather than nacked: a nack cannot carry headers, and a quarantine of\n * messages nobody can say anything about is a queue an operator has to replay\n * blind. If that publish is refused the nack still quarantines it, reasonless.\n *\n * A transient failure is nacked for the broker to redeliver; a `broadcast`\n * queue has no quarantine, so its failures are dropped.\n */\nconst settleFailure = (\n channel: Channel,\n message: ConsumeMessage,\n queue: string,\n mode: SubscriptionMode,\n failure: DeliveryFailure,\n): void => {\n if (failure.kind === 'poison' && mode === 'work') {\n try {\n channel.publish(EVENTS_DLX, queue, message.content, {\n ...message.properties,\n persistent: true,\n headers: {\n ...message.properties?.headers,\n 'x-failure-code': failure.code,\n 'x-failure-category': failure.category,\n },\n });\n channel.ack(message);\n return;\n } catch {\n // Fall through: quarantined without its reason beats not quarantined.\n }\n }\n channel.nack(message, false, requeues(failure, mode));\n};\n\nconst requeues = (failure: DeliveryFailure, mode: SubscriptionMode): boolean =>\n failure.kind === 'transient' && mode === 'work';\n\n/**\n * RabbitMQ-backed {@link EventBus}. Events go out as `event` envelopes on the\n * shared topic exchange — the adapter owns the wire framing, so the port stays\n * event-typed.\n *\n * **The event's own name is the routing key**, which is what lets a subscriber\n * bind the exact pattern it declared in `tools/slices/*.slice.ts`.\n *\n * The queue a subscriber binds is its own choice of shape. A `work`\n * subscription gets a named durable queue that replicas share and that keeps\n * accumulating while the consumer is down; a `broadcast` one gets an exclusive\n * queue, where every replica sees every event and nothing\n * survives a restart. Choosing broadcast for a workload that is work is how an\n * event published during a rollout is dropped by the broker while the outbox\n * has already recorded it sent.\n *\n * Both methods go through the {@link AmqpConnector} rather than holding a\n * channel, because a channel does not survive the broker restarting. `publish`\n * asks for a live one per call, and `subscribe` registers its setup so the\n * connector can re-run it against the new channel after a reconnect. A durable\n * queue outlives that reconnect; the consumer bound to it does not.\n *\n * It returns the bus **and** its `drainDeliveries`, rather than only the port:\n * waiting for in-flight handlers is an adapter fact — it is this module that\n * runs them — and putting it on `EventBus` would make every implementation of\n * a framework-free port carry a shutdown concern it has no deliveries to drain.\n */\nexport const makeAmqpEventBus = (\n connector: AmqpConnector,\n wiring: WiringRegistry,\n): { bus: EventBus; drainDeliveries: Effect.Effect<void> } => {\n /**\n * Handlers started and not yet settled.\n *\n * Nothing tracked them before, so a SIGTERM killed them mid-flight and the\n * broker redelivered whatever was unacked — safe only while every consumer\n * happens to be idempotent, which is the assumption the command inbox stops\n * making.\n */\n let inFlight = 0;\n\n const bus: EventBus = {\n publish: event =>\n Effect.tryPromise({\n try: () =>\n connector.withChannel(async channel => {\n channel.publish(\n EVENTS_EXCHANGE,\n event.name,\n Buffer.from(JSON.stringify(makeEventEnvelope(event))),\n { persistent: true },\n );\n }),\n catch: error => new Unavailable({ dependency: 'amqp' }),\n // Recorded **after** the publish succeeds, so `GET /api/$service` reports\n // what this process actually put on the exchange. Recording the intent\n // instead would make the declared-vs-observed diff pass on a service whose\n // every publish is failing.\n }).pipe(\n Effect.tap(() =>\n wiring\n .recordPublish(event.name)\n .pipe(Effect.andThen(recordPublished(event.name))),\n ),\n // Counted here and not in the `catch` above, which only builds the\n // error: a rising publish-failure rate against a flat published rate\n // is what a broker outage looks like from the publisher's side, and\n // the outbox's own backlog is the confirmation.\n Effect.tapError(() => recordPublishFailure(event.name)),\n ),\n\n subscribe: (subscription, handler) =>\n Effect.tryPromise({\n try: () =>\n connector.addConsumer(async channel => {\n // One unacked message at a time: events for a transaction are then\n // folded serially (never concurrently), so an `accepted`/`completed`\n // pair can't race into two upserts.\n await channel.prefetch(1);\n const queue = await declareQueue(channel, subscription);\n await channel.bindQueue(\n queue,\n EVENTS_EXCHANGE,\n subscription.pattern,\n );\n // What the process **bound**, recorded at the point it bound it. The\n // registry deduplicates, so re-running this setup after a reconnect\n // does not double the entry.\n await Effect.runPromise(\n wiring.recordSubscription({\n slice: subscription.slice,\n pattern: subscription.pattern,\n mode: subscription.mode,\n queue,\n }),\n );\n // Resolved once per binding rather than per delivery: `queue` is the\n // durable name for a `work` subscription and the broker's generated\n // one for a `broadcast` queue, so it is only knowable here.\n const tags: SubscriptionTags = {\n queue,\n slice: subscription.slice,\n mode: subscription.mode,\n };\n const { consumerTag } = await channel.consume(\n queue,\n (message: ConsumeMessage | null) => {\n if (message === null) {\n return;\n }\n\n // Reading the payload and running the handler are separated on\n // purpose: they fail for different reasons and earn different\n // treatment. `JSON.parse` is inside the Effect because it throws\n // *synchronously* — outside, it escaped into amqplib's callback and\n // the message was never even nacked.\n const settle = Effect.try({\n try: () => JSON.parse(message.content.toString()) as unknown,\n catch: (): DeliveryFailure => UNREADABLE,\n }).pipe(\n Effect.flatMap(parsed =>\n readEventEnvelope(parsed).pipe(Effect.mapError(classify)),\n ),\n // The handler carries no requirements (the subscriber closes over\n // its store), so it runs standalone.\n //\n // ⚠️ A handler's failure is classified by its category, not\n // treated as transient across the board. The transport\n // validates `meta` and deliberately not `data` (inventing an\n // opinion about a payload is how the bus would start knowing\n // about domains), so a consumer that decodes its own payload\n // is the *only* thing that can tell a malformed one from a bad\n // afternoon at the database — and it says so by failing with\n // a business or `protocol` failure, which quarantines at once\n // instead of spending `x-delivery-limit` on every message\n // behind it. Measured on `catalog.published`: a payload the\n // contract rejected used to take five deliveries to quarantine.\n Effect.flatMap(event =>\n handler(event).pipe(Effect.mapError(classify)),\n ),\n );\n\n // Counted around the whole settle, so a shutdown waits for the ack\n // as well as the handler: cancelling a consumer stops *new*\n // deliveries and says nothing about this one.\n inFlight += 1;\n void Effect.runPromise(\n settle.pipe(\n // Effect's metric registry is a process-wide singleton, so an\n // increment inside this detached `runPromise` reaches the same\n // producer `NodeSdk` exports from. That is the only reason a\n // metric works here at all — nothing about this fiber is\n // inside the observability layer.\n Effect.matchEffect({\n onSuccess: () =>\n recordConsumed(tags).pipe(\n Effect.andThen(\n Effect.sync(() => channel.ack(message)),\n ),\n ),\n onFailure: failure =>\n recordFailed(tags, failure.kind).pipe(\n Effect.andThen(\n Effect.sync(() =>\n settleFailure(\n channel,\n message,\n queue,\n subscription.mode,\n failure,\n ),\n ),\n ),\n ),\n }),\n ),\n ).finally(() => {\n inFlight -= 1;\n });\n },\n );\n return [consumerTag];\n }),\n catch: error => new Unavailable({ dependency: 'amqp' }),\n }),\n };\n\n return {\n bus,\n drainDeliveries: Effect.gen(function* () {\n while (inFlight > 0) {\n yield* Effect.sleep(DELIVERY_POLL);\n }\n }),\n };\n};\n\n/**\n * Provides {@link EventBusTag} from an {@link AmqpChannelTag}.\n *\n * It also takes {@link WiringRegistryTag}, which `makeServerLayer` provides once\n * per service — so the bus and `GET /api/$service` share one instance, and the\n * document reports the bindings this very process made.\n */\nexport const AmqpEventBusLayer = Layer.effect(\n EventBusTag,\n Effect.gen(function* () {\n const connector = yield* AmqpChannelTag;\n const wiring = yield* WiringRegistryTag;\n const shutdown = yield* ShutdownRegistryTag;\n const { bus, drainDeliveries } = makeAmqpEventBus(connector, wiring);\n\n // `stop-intake`, and both halves are it: cancelling stops the broker\n // handing over anything new, then the drain waits for the deliveries\n // already in progress. Registered here rather than in a service's `main.ts`\n // for the reason every registry in this repo exists — a service that gains\n // a bus gains its drain, with nothing to remember.\n yield* shutdown.register({\n name: 'amqp-consumers',\n phase: 'stop-intake',\n run: Effect.promise(() => connector.cancelConsumers()).pipe(\n Effect.andThen(drainDeliveries),\n ),\n });\n\n return bus;\n }),\n);\n"],"names":["ShutdownRegistryTag","WiringRegistryTag","isFailure","makeEventEnvelope","readEventEnvelope","Unavailable","EventBusTag","Duration","Effect","Layer","AmqpChannelTag","EVENTS_DLX","EVENTS_EXCHANGE","recordConsumed","recordFailed","recordPublished","recordPublishFailure","QUARANTINE_SUFFIX","DELIVERY_POLL","millis","classify","error","kind","family","category","code","UNREADABLE","queueNameFor","subscription","slice","pattern","replaceAll","declareQueue","channel","mode","queue","assertQueue","exclusive","quarantine","durable","arguments","bindQueue","maxAttempts","settleFailure","message","failure","publish","content","properties","persistent","headers","ack","nack","requeues","makeAmqpEventBus","connector","wiring","inFlight","bus","event","tryPromise","try","withChannel","name","Buffer","from","JSON","stringify","catch","dependency","pipe","tap","recordPublish","andThen","tapError","subscribe","handler","addConsumer","prefetch","runPromise","recordSubscription","tags","consumerTag","consume","settle","parse","toString","flatMap","parsed","mapError","matchEffect","onSuccess","sync","onFailure","finally","drainDeliveries","gen","sleep","AmqpEventBusLayer","effect","shutdown","register","phase","run","promise","cancelConsumers"],"mappings":";AACA,SAASA,mBAAmB,EAAEC,iBAAiB,QAAQ,oBAAoB;AAC3E,SACEC,SAAS,EACTC,iBAAiB,EACjBC,iBAAiB,EACjBC,WAAW,QACN,gBAAgB;AACvB,SAEEC,WAAW,QAGN,wBAAwB;AAE/B,SAASC,QAAQ,EAAEC,MAAM,EAAEC,KAAK,QAAQ,SAAS;AAEjD,SACEC,cAAc,EAEdC,UAAU,EACVC,eAAe,QACV,wCAAwC;AAC/C,SACEC,cAAc,EACdC,YAAY,EACZC,eAAe,EACfC,oBAAoB,QAEf,mBAAmB;AAE1B,+EAA+E,GAC/E,MAAMC,oBAAoB;AAE1B;;;;;;;CAOC,GACD,MAAMC,gBAAgBX,SAASY,MAAM,CAAC;AAsBtC;;;;;;;;CAQC,GACD,MAAMC,WAAW,CAACC,QAChBnB,UAAUmB,SACN;QACEC,MACED,MAAME,MAAM,KAAK,cAAcF,MAAMG,QAAQ,KAAK,aAC9C,WACA;QACNC,MAAMJ,MAAMI,IAAI;QAChBD,UAAUH,MAAMG,QAAQ;IAC1B,IACA;QAAEF,MAAM;QAAaG,MAAM;QAAYD,UAAU;IAAW;AAElE,gFAAgF,GAChF,MAAME,aAA8B;IAClCJ,MAAM;IACNG,MAAM;IACND,UAAU;AACZ;AAEA;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,MAAMG,eAAe,CAACC,eAC3B,GAAGA,aAAaC,KAAK,CAAC,CAAC,EAAED,aAAaE,OAAO,CAC1CC,UAAU,CAAC,KAAK,U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WAAW,IACT9E,eAAeoE,MAAMX,IAAI,CACvB9D,OAAOiE,OAAO,CACZjE,OAAOoF,IAAI,CAAC,IAAM3D,QAAQkB,GAAG,CAACP;gCAGpCiD,WAAWhD,CAAAA,UACT/B,aAAamE,MAAMpC,QAAQvB,IAAI,EAAEgD,IAAI,CACnC9D,OAAOiE,OAAO,CACZjE,OAAOoF,IAAI,CAAC,IACVjD,cACEV,SACAW,SACAT,OACAP,aAAaM,IAAI,EACjBW;4BAKZ,KAEFiD,OAAO,CAAC;gCACRrC,YAAY;4BACd;wBACF;wBAEF,OAAO;4BAACyB;yBAAY;oBACtB;gBACFd,OAAO/C,CAAAA,QAAS,IAAIhB,YAAY;wBAAEgE,YAAY;oBAAO;YACvD;IACJ;IAEA,OAAO;QACLX;QACAqC,iBAAiBvF,OAAOwF,GAAG,CAAC;YAC1B,MAAOvC,WAAW,EAAG;gBACnB,OAAOjD,OAAOyF,KAAK,CAAC/E;YACtB;QACF;IACF;AACF,EAAE;AAEF;;;;;;CAMC,GACD,OAAO,MAAMgF,oBAAoBzF,MAAM0F,MAAM,CAC3C7F,aACAE,OAAOwF,GAAG,CAAC;IACT,MAAMzC,YAAY,OAAO7C;IACzB,MAAM8C,SAAS,OAAOvD;IACtB,MAAMmG,WAAW,OAAOpG;IACxB,MAAM,EAAE0D,GAAG,EAAEqC,eAAe,EAAE,GAAGzC,iBAAiBC,WAAWC;IAE7D,qEAAqE;IACrE,qEAAqE;IACrE,4EAA4E;IAC5E,2EAA2E;IAC3E,mDAAmD;IACnD,OAAO4C,SAASC,QAAQ,CAAC;QACvBtC,MAAM;QACNuC,OAAO;QACPC,KAAK/F,OAAOgG,OAAO,CAAC,IAAMjD,UAAUkD,eAAe,IAAInC,IAAI,CACzD9D,OAAOiE,OAAO,CAACsB;IAEnB;IAEA,OAAOrC;AACT,IACA"}
|
|
1
|
+
{"version":3,"sources":["../../src/adapters/amqp-event-bus.ts"],"sourcesContent":["import type { WiringRegistry } from '@entifix/business';\nimport { ShutdownRegistryTag, WiringRegistryTag } from '@entifix/business';\nimport {\n isFailure,\n makeEventEnvelope,\n readEventEnvelope,\n Unavailable,\n} from '@entifix/core';\nimport {\n type EventBus,\n EventBusTag,\n type Subscription,\n} from '@entifix/transactions';\nimport type { Channel, ConsumeMessage } from 'amqplib';\nimport { Duration, Effect, Layer } from 'effect';\n\nimport {\n AmqpChannelTag,\n type AmqpConnector,\n EVENTS_DLX,\n EVENTS_EXCHANGE,\n} from '../amqp-connection/amqp-connection.js';\nimport {\n recordConsumed,\n recordFailed,\n recordPublished,\n recordPublishFailure,\n type SubscriptionTags,\n} from './bus-metrics.js';\n\n/** Appended to a work queue's name to make the queue that holds its failures. */\nconst QUARANTINE_SUFFIX = '.quarantine';\n\n/**\n * How often the shutdown drain re-checks whether the handlers have finished.\n *\n * A poll rather than a latch because a delivery is started from amqplib's own\n * callback, outside any fiber this module holds; the drain's own bound is the\n * shutdown hook's, so this interval only decides how promptly the process\n * notices it is free to go.\n */\nconst DELIVERY_POLL = Duration.millis(25);\n\n/**\n * Why a delivery did not succeed, which is the whole of the nack decision.\n *\n * `transient` is a handler that threw — a dependency briefly gone, a timeout —\n * and is worth another delivery. `poison` is a payload this process cannot\n * read, and is worth **none**: a message that cannot be deserialized never\n * becomes deserializable, so retrying it only spends the delivery budget of the\n * messages queued behind it. Conflating the two is what the adapter once did,\n * on a queue that discarded both.\n *\n * A *business* failure is neither, and never reaches here: that message was\n * handled successfully and produced its own `failed` event.\n */\ninterface DeliveryFailure {\n readonly kind: 'transient' | 'poison';\n /** The failure's code and category, carried onto a quarantined message. */\n readonly code: string;\n readonly category: string;\n}\n\n/**\n * The poison rule, by category and never by class\n * ([ADR 0013](../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)):\n * an answer redelivered is the same answer, so every business failure is\n * poison, and so is `protocol` — bytes that did not decode will not decode on\n * the fifth try. The transient categories are redelivered, bounded by the\n * subscription's `maxAttempts` as the adapter counts them, and so is anything\n * uncategorised: not knowing what went wrong is not evidence that retrying is\n * pointless.\n */\nconst classify = (error: unknown): DeliveryFailure =>\n isFailure(error)\n ? {\n kind:\n error.family === 'business' || error.category === 'protocol'\n ? 'poison'\n : 'transient',\n code: error.code,\n category: error.category,\n }\n : { kind: 'transient', code: 'internal', category: 'internal' };\n\n/** A payload that is not JSON: the sender's fault, decided before any handler. */\nconst UNREADABLE: DeliveryFailure = {\n kind: 'poison',\n code: 'invalidEnvelope',\n category: 'invalid',\n};\n\n/**\n * The queue a subscription binds.\n *\n * `<subscribing slice>.<pattern>`, so the name says who is owed the messages in\n * it — readable in the broker's own UI, which is where someone looks when a\n * queue has depth. The slice is the *subscriber's*, never the publisher's:\n * `EventSourceTag` names the emitter, and one deployment hosts several slices\n * (a host may co-deploy two slices in one process), so\n * deriving from it would file a consumer's queue under whoever happened to\n * publish from the same process.\n *\n * `*` and `#` are spelled out because AMQP 0-9-1 restricts a queue name to\n * letters, digits, hyphen, underscore, period and colon. RabbitMQ is lenient in\n * practice, but the name also has to survive being a URL path segment in the\n * management API, and `%2A` in an operator's address bar is a poor trade for\n * three saved characters.\n */\nexport const queueNameFor = (subscription: Subscription): string =>\n `${subscription.slice}.${subscription.pattern\n .replaceAll('*', '_star_')\n .replaceAll('#', '_hash_')}`;\n\n/**\n * Declares the queue a subscription consumes and returns its name.\n *\n * A **work** queue is durable and quorum-backed, so it survives the consumer's\n * restart and accumulates while it is gone — the hop the outbox relay's\n * durability chain was missing. Its retry ceiling is the subscription's\n * `maxAttempts`, counted by the adapter in {@link ATTEMPTS_HEADER} because the\n * broker does not count a requeued nack (#130). The same number is the queue's\n * `x-delivery-limit`, which bounds what the broker *does* count — a redelivery\n * after a consumer crash.\n *\n * The quarantine is declared **first**: a message dead-lettered the instant the\n * work queue exists must have somewhere to land, and a `direct` exchange with\n * no matching binding drops what it routes.\n *\n * `x-delivery-limit` is immutable once a queue exists. Re-declaring with a\n * different `maxAttempts` fails `PRECONDITION_FAILED` and closes the channel,\n * and there is no safe automatic recovery — so changing the ceiling means\n * deleting the queue, which locally is `pnpm run <app>:dev:reset`.\n */\nconst declareQueue = async (\n channel: Channel,\n subscription: Subscription,\n): Promise<string> => {\n if (subscription.mode === 'broadcast') {\n // Connection-scoped and retained by nobody, which is right only when the\n // replicas differ from one another, as a per-connection push does.\n const { queue } = await channel.assertQueue('', { exclusive: true });\n return queue;\n }\n\n const queue = queueNameFor(subscription);\n const quarantine = `${queue}${QUARANTINE_SUFFIX}`;\n\n await channel.assertQueue(quarantine, {\n durable: true,\n arguments: { 'x-queue-type': 'quorum' },\n });\n await channel.bindQueue(quarantine, EVENTS_DLX, queue);\n await channel.assertQueue(queue, {\n durable: true,\n arguments: {\n 'x-queue-type': 'quorum',\n 'x-delivery-limit': subscription.maxAttempts,\n 'x-dead-letter-exchange': EVENTS_DLX,\n 'x-dead-letter-routing-key': queue,\n },\n });\n\n return queue;\n};\n\n/**\n * The adapter's own count of the attempts a message has failed, carried on the\n * copy it republishes (#130).\n *\n * The broker cannot be trusted with it. RabbitMQ 4 does not count a requeued\n * `basic.nack` toward a quorum queue's `x-delivery-limit` — measured on 4.3.5:\n * a queue limited to 2 delivered one message 8 times and never set\n * `x-delivery-count` — so a transient failure that never cleared was\n * redelivered without a ceiling and without a pause. `x-delivery-limit` stays\n * on the queue, where it still bounds the redeliveries a crashed consumer\n * causes, which the broker does count.\n */\nexport const ATTEMPTS_HEADER = 'x-entifix-attempts';\n\nconst attemptsSoFar = (message: ConsumeMessage): number => {\n const value: unknown = message.properties?.headers?.[ATTEMPTS_HEADER];\n return typeof value === 'number' && Number.isInteger(value) && value > 0\n ? value\n : 0;\n};\n\n/** How long a transient failure waits before its copy goes back on the queue. */\nexport type RedeliveryBackoff = (attempt: number) => Duration.Duration;\n\n/**\n * Doubling from 100 ms, capped at two seconds. The wait holds the delivery —\n * the queue is `prefetch(1)`, so it pauses this consumer — which is the point:\n * a dependency that is down is not helped by asking it again at once.\n */\nexport const DEFAULT_REDELIVERY_BACKOFF: RedeliveryBackoff = attempt =>\n Duration.millis(Math.min(100 * 2 ** (attempt - 1), 2_000));\n\n/**\n * Settles a delivery that failed.\n *\n * Poison on a `work` queue — and a transient failure that has spent the\n * subscription's `maxAttempts` — is republished to the dead-letter exchange\n * **with its reason**: `x-failure-code`, `x-failure-category` and the attempts\n * spent. It is then acked rather than nacked, because a nack cannot carry\n * headers, and a quarantine of messages nobody can say anything about is a\n * queue an operator has to replay blind. If that publish is refused the nack\n * still quarantines it, reasonless.\n *\n * A transient failure under the ceiling waits its backoff, goes back on its own\n * queue as a copy carrying the attempt count, and the original is acked. If\n * that publish is refused it is nacked for the broker to redeliver, which is\n * the old behaviour and still better than losing it. A `broadcast` queue has no\n * quarantine and no ceiling, so its failures are dropped.\n */\nconst settleFailure = (\n channel: Channel,\n message: ConsumeMessage,\n queue: string,\n subscription: Subscription,\n failure: DeliveryFailure,\n backoff: RedeliveryBackoff,\n): Effect.Effect<void> => {\n if (subscription.mode === 'broadcast') {\n return Effect.sync(() => channel.nack(message, false, false));\n }\n const attempts =\n failure.kind === 'transient' ? attemptsSoFar(message) + 1 : 0;\n if (failure.kind === 'poison' || attempts >= subscription.maxAttempts) {\n return Effect.sync(() =>\n quarantine(channel, message, queue, failure, attempts),\n );\n }\n const wait = backoff(attempts);\n return (Duration.isZero(wait) ? Effect.void : Effect.sleep(wait)).pipe(\n Effect.andThen(\n Effect.sync(() => {\n try {\n channel.publish('', queue, message.content, {\n ...message.properties,\n persistent: true,\n headers: {\n ...message.properties?.headers,\n [ATTEMPTS_HEADER]: attempts,\n },\n });\n channel.ack(message);\n } catch {\n channel.nack(message, false, true);\n }\n }),\n ),\n );\n};\n\nconst quarantine = (\n channel: Channel,\n message: ConsumeMessage,\n queue: string,\n failure: DeliveryFailure,\n attempts: number,\n): void => {\n try {\n channel.publish(EVENTS_DLX, queue, message.content, {\n ...message.properties,\n persistent: true,\n headers: {\n ...message.properties?.headers,\n 'x-failure-code': failure.code,\n 'x-failure-category': failure.category,\n ...(attempts > 0 ? { [ATTEMPTS_HEADER]: attempts } : {}),\n },\n });\n channel.ack(message);\n } catch {\n // Quarantined without its reason beats not quarantined.\n channel.nack(message, false, false);\n }\n};\n\n/**\n * RabbitMQ-backed {@link EventBus}. Events go out as `event` envelopes on the\n * shared topic exchange — the adapter owns the wire framing, so the port stays\n * event-typed.\n *\n * **The event's own name is the routing key**, which is what lets a subscriber\n * bind the exact pattern it declared in `tools/slices/*.slice.ts`.\n *\n * The queue a subscriber binds is its own choice of shape. A `work`\n * subscription gets a named durable queue that replicas share and that keeps\n * accumulating while the consumer is down; a `broadcast` one gets an exclusive\n * queue, where every replica sees every event and nothing\n * survives a restart. Choosing broadcast for a workload that is work is how an\n * event published during a rollout is dropped by the broker while the outbox\n * has already recorded it sent.\n *\n * Both methods go through the {@link AmqpConnector} rather than holding a\n * channel, because a channel does not survive the broker restarting. `publish`\n * asks for a live one per call, and `subscribe` registers its setup so the\n * connector can re-run it against the new channel after a reconnect. A durable\n * queue outlives that reconnect; the consumer bound to it does not.\n *\n * It returns the bus **and** its `drainDeliveries`, rather than only the port:\n * waiting for in-flight handlers is an adapter fact — it is this module that\n * runs them — and putting it on `EventBus` would make every implementation of\n * a framework-free port carry a shutdown concern it has no deliveries to drain.\n */\nexport const makeAmqpEventBus = (\n connector: AmqpConnector,\n wiring: WiringRegistry,\n options: { readonly redeliveryBackoff?: RedeliveryBackoff } = {},\n): { bus: EventBus; drainDeliveries: Effect.Effect<void> } => {\n const backoff = options.redeliveryBackoff ?? DEFAULT_REDELIVERY_BACKOFF;\n /**\n * Handlers started and not yet settled.\n *\n * Nothing tracked them before, so a SIGTERM killed them mid-flight and the\n * broker redelivered whatever was unacked — safe only while every consumer\n * happens to be idempotent, which is the assumption the command inbox stops\n * making.\n */\n let inFlight = 0;\n\n const bus: EventBus = {\n publish: event =>\n Effect.tryPromise({\n try: () =>\n connector.withChannel(async channel => {\n channel.publish(\n EVENTS_EXCHANGE,\n event.name,\n Buffer.from(JSON.stringify(makeEventEnvelope(event))),\n { persistent: true },\n );\n }),\n catch: error => new Unavailable({ dependency: 'amqp' }),\n // Recorded **after** the publish succeeds, so `GET /api/$service` reports\n // what this process actually put on the exchange. Recording the intent\n // instead would make the declared-vs-observed diff pass on a service whose\n // every publish is failing.\n }).pipe(\n Effect.tap(() =>\n wiring\n .recordPublish(event.name)\n .pipe(Effect.andThen(recordPublished(event.name))),\n ),\n // Counted here and not in the `catch` above, which only builds the\n // error: a rising publish-failure rate against a flat published rate\n // is what a broker outage looks like from the publisher's side, and\n // the outbox's own backlog is the confirmation.\n Effect.tapError(() => recordPublishFailure(event.name)),\n ),\n\n subscribe: (subscription, handler) =>\n Effect.tryPromise({\n try: () =>\n connector.addConsumer(async channel => {\n // One unacked message at a time: events for a transaction are then\n // folded serially (never concurrently), so an `accepted`/`completed`\n // pair can't race into two upserts.\n await channel.prefetch(1);\n const queue = await declareQueue(channel, subscription);\n await channel.bindQueue(\n queue,\n EVENTS_EXCHANGE,\n subscription.pattern,\n );\n // What the process **bound**, recorded at the point it bound it. The\n // registry deduplicates, so re-running this setup after a reconnect\n // does not double the entry.\n await Effect.runPromise(\n wiring.recordSubscription({\n slice: subscription.slice,\n pattern: subscription.pattern,\n mode: subscription.mode,\n queue,\n }),\n );\n // Resolved once per binding rather than per delivery: `queue` is the\n // durable name for a `work` subscription and the broker's generated\n // one for a `broadcast` queue, so it is only knowable here.\n const tags: SubscriptionTags = {\n queue,\n slice: subscription.slice,\n mode: subscription.mode,\n };\n const { consumerTag } = await channel.consume(\n queue,\n (message: ConsumeMessage | null) => {\n if (message === null) {\n return;\n }\n\n // Reading the payload and running the handler are separated on\n // purpose: they fail for different reasons and earn different\n // treatment. `JSON.parse` is inside the Effect because it throws\n // *synchronously* — outside, it escaped into amqplib's callback and\n // the message was never even nacked.\n const settle = Effect.try({\n try: () => JSON.parse(message.content.toString()) as unknown,\n catch: (): DeliveryFailure => UNREADABLE,\n }).pipe(\n Effect.flatMap(parsed =>\n readEventEnvelope(parsed).pipe(Effect.mapError(classify)),\n ),\n // The handler carries no requirements (the subscriber closes over\n // its store), so it runs standalone.\n //\n // ⚠️ A handler's failure is classified by its category, not\n // treated as transient across the board. The transport\n // validates `meta` and deliberately not `data` (inventing an\n // opinion about a payload is how the bus would start knowing\n // about domains), so a consumer that decodes its own payload\n // is the *only* thing that can tell a malformed one from a bad\n // afternoon at the database — and it says so by failing with\n // a business or `protocol` failure, which quarantines at once\n // instead of spending `maxAttempts` on every message\n // behind it. Measured on `catalog.published`: a payload the\n // contract rejected used to take five deliveries to quarantine.\n Effect.flatMap(event =>\n handler(event).pipe(Effect.mapError(classify)),\n ),\n );\n\n // Counted around the whole settle, so a shutdown waits for the ack\n // as well as the handler: cancelling a consumer stops *new*\n // deliveries and says nothing about this one.\n inFlight += 1;\n void Effect.runPromise(\n settle.pipe(\n // Effect's metric registry is a process-wide singleton, so an\n // increment inside this detached `runPromise` reaches the same\n // producer `NodeSdk` exports from. That is the only reason a\n // metric works here at all — nothing about this fiber is\n // inside the observability layer.\n Effect.matchEffect({\n onSuccess: () =>\n recordConsumed(tags).pipe(\n Effect.andThen(\n Effect.sync(() => channel.ack(message)),\n ),\n ),\n onFailure: failure =>\n recordFailed(tags, failure.kind).pipe(\n Effect.andThen(\n settleFailure(\n channel,\n message,\n queue,\n subscription,\n failure,\n backoff,\n ),\n ),\n ),\n }),\n ),\n ).finally(() => {\n inFlight -= 1;\n });\n },\n );\n return [consumerTag];\n }),\n catch: error => new Unavailable({ dependency: 'amqp' }),\n }),\n };\n\n return {\n bus,\n drainDeliveries: Effect.gen(function* () {\n while (inFlight > 0) {\n yield* Effect.sleep(DELIVERY_POLL);\n }\n }),\n };\n};\n\n/**\n * Provides {@link EventBusTag} from an {@link AmqpChannelTag}.\n *\n * It also takes {@link WiringRegistryTag}, which `makeServerLayer` provides once\n * per service — so the bus and `GET /api/$service` share one instance, and the\n * document reports the bindings this very process made.\n */\nexport const AmqpEventBusLayer = Layer.effect(\n EventBusTag,\n Effect.gen(function* () {\n const connector = yield* AmqpChannelTag;\n const wiring = yield* WiringRegistryTag;\n const shutdown = yield* ShutdownRegistryTag;\n const { bus, drainDeliveries } = makeAmqpEventBus(connector, wiring);\n\n // `stop-intake`, and both halves are it: cancelling stops the broker\n // handing over anything new, then the drain waits for the deliveries\n // already in progress. Registered here rather than in a service's `main.ts`\n // for the reason every registry in this repo exists — a service that gains\n // a bus gains its drain, with nothing to remember.\n yield* shutdown.register({\n name: 'amqp-consumers',\n phase: 'stop-intake',\n run: Effect.promise(() => connector.cancelConsumers()).pipe(\n Effect.andThen(drainDeliveries),\n ),\n });\n\n return bus;\n }),\n);\n"],"names":["ShutdownRegistryTag","WiringRegistryTag","isFailure","makeEventEnvelope","readEventEnvelope","Unavailable","EventBusTag","Duration","Effect","Layer","AmqpChannelTag","EVENTS_DLX","EVENTS_EXCHANGE","recordConsumed","recordFailed","recordPublished","recordPublishFailure","QUARANTINE_SUFFIX","DELIVERY_POLL","millis","classify","error","kind","family","category","code","UNREADABLE","queueNameFor","subscription","slice","pattern","replaceAll","declareQueue","channel","mode","queue","assertQueue","exclusive","quarantine","durable","arguments","bindQueue","maxAttempts","ATTEMPTS_HEADER","attemptsSoFar","message","value","properties","headers","Number","isInteger","DEFAULT_REDELIVERY_BACKOFF","attempt","Math","min","settleFailure","failure","backoff","sync","nack","attempts","wait","isZero","void","sleep","pipe","andThen","publish","content","persistent","ack","makeAmqpEventBus","connector","wiring","options","redeliveryBackoff","inFlight","bus","event","tryPromise","try","withChannel","name","Buffer","from","JSON","stringify","catch","dependency","tap","recordPublish","tapError","subscribe","handler","addConsumer","prefetch","runPromise","recordSubscription","tags","consumerTag","consume","settle","parse","toString","flatMap","parsed","mapError","matchEffect","onSuccess","onFailure","finally","drainDeliveries","gen","AmqpEventBusLayer","effect","shutdown","register","phase","run","promise","cancelConsumers"],"mappings":";AACA,SAASA,mBAAmB,EAAEC,iBAAiB,QAAQ,oBAAoB;AAC3E,SACEC,SAAS,EACTC,iBAAiB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AY,SACAV,OACAP,cACA4B,SACAC;4BAIV,KAEFqD,OAAO,CAAC;gCACRlC,YAAY;4BACd;wBACF;wBAEF,OAAO;4BAACuB;yBAAY;oBACtB;gBACFZ,OAAOlE,CAAAA,QAAS,IAAIhB,YAAY;wBAAEmF,YAAY;oBAAO;YACvD;IACJ;IAEA,OAAO;QACLX;QACAkC,iBAAiBvG,OAAOwG,GAAG,CAAC;YAC1B,MAAOpC,WAAW,EAAG;gBACnB,OAAOpE,OAAOwD,KAAK,CAAC9C;YACtB;QACF;IACF;AACF,EAAE;AAEF;;;;;;CAMC,GACD,OAAO,MAAM+F,oBAAoBxG,MAAMyG,MAAM,CAC3C5G,aACAE,OAAOwG,GAAG,CAAC;IACT,MAAMxC,YAAY,OAAO9D;IACzB,MAAM+D,SAAS,OAAOxE;IACtB,MAAMkH,WAAW,OAAOnH;IACxB,MAAM,EAAE6E,GAAG,EAAEkC,eAAe,EAAE,GAAGxC,iBAAiBC,WAAWC;IAE7D,qEAAqE;IACrE,qEAAqE;IACrE,4EAA4E;IAC5E,2EAA2E;IAC3E,mDAAmD;IACnD,OAAO0C,SAASC,QAAQ,CAAC;QACvBlC,MAAM;QACNmC,OAAO;QACPC,KAAK9G,OAAO+G,OAAO,CAAC,IAAM/C,UAAUgD,eAAe,IAAIvD,IAAI,CACzDzD,OAAO0D,OAAO,CAAC6C;IAEnB;IAEA,OAAOlC;AACT,IACA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entifix/amqp",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "RabbitMQ connection and health probe, and an optional event bus for @entifix/transactions with retry and quarantine.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -57,18 +57,18 @@
|
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@swc/helpers": "0.5.23",
|
|
59
59
|
"amqplib": "2.2.0",
|
|
60
|
-
"@entifix/business": "0.10.
|
|
61
|
-
"@entifix/core": "0.10.
|
|
60
|
+
"@entifix/business": "0.10.1",
|
|
61
|
+
"@entifix/core": "0.10.1"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@types/amqplib": "0.10.8",
|
|
65
65
|
"effect": "4.0.6",
|
|
66
|
-
"@entifix/
|
|
67
|
-
"@entifix/
|
|
66
|
+
"@entifix/testing-unit": "0.10.1",
|
|
67
|
+
"@entifix/transactions": "0.10.1"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
70
|
"effect": "^4.0.6",
|
|
71
|
-
"@entifix/transactions": "0.10.
|
|
71
|
+
"@entifix/transactions": "0.10.1"
|
|
72
72
|
},
|
|
73
73
|
"peerDependenciesMeta": {
|
|
74
74
|
"@entifix/transactions": {
|