@ddd-ts-kit/kafka 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +397 -2
- package/dist/codec/decode.d.ts +4 -0
- package/dist/codec/decode.d.ts.map +1 -0
- package/dist/codec/decode.js +39 -0
- package/dist/codec/decode.js.map +1 -0
- package/dist/codec/encode.d.ts +9 -0
- package/dist/codec/encode.d.ts.map +1 -0
- package/dist/codec/encode.js +22 -0
- package/dist/codec/encode.js.map +1 -0
- package/dist/codec/headers.d.ts +13 -0
- package/dist/codec/headers.d.ts.map +1 -0
- package/dist/codec/headers.js +13 -0
- package/dist/codec/headers.js.map +1 -0
- package/dist/codec/incoming-record.d.ts +8 -0
- package/dist/codec/incoming-record.d.ts.map +1 -0
- package/dist/codec/incoming-record.js +2 -0
- package/dist/codec/incoming-record.js.map +1 -0
- package/dist/codec/outgoing-record.d.ts +7 -0
- package/dist/codec/outgoing-record.d.ts.map +1 -0
- package/dist/codec/outgoing-record.js +2 -0
- package/dist/codec/outgoing-record.js.map +1 -0
- package/dist/codec/republication.d.ts +5 -0
- package/dist/codec/republication.d.ts.map +1 -0
- package/dist/codec/republication.js +8 -0
- package/dist/codec/republication.js.map +1 -0
- package/dist/codec/routing.d.ts +7 -0
- package/dist/codec/routing.d.ts.map +1 -0
- package/dist/codec/routing.js +2 -0
- package/dist/codec/routing.js.map +1 -0
- package/dist/codec/source-of.d.ts +4 -0
- package/dist/codec/source-of.d.ts.map +1 -0
- package/dist/codec/source-of.js +5 -0
- package/dist/codec/source-of.js.map +1 -0
- package/dist/codec/text-header.d.ts +4 -0
- package/dist/codec/text-header.d.ts.map +1 -0
- package/dist/codec/text-header.js +7 -0
- package/dist/codec/text-header.js.map +1 -0
- package/dist/connection/broker-link.d.ts +44 -0
- package/dist/connection/broker-link.d.ts.map +1 -0
- package/dist/connection/broker-link.js +145 -0
- package/dist/connection/broker-link.js.map +1 -0
- package/dist/connection/cluster-of.d.ts +8 -0
- package/dist/connection/cluster-of.d.ts.map +1 -0
- package/dist/connection/cluster-of.js +16 -0
- package/dist/connection/cluster-of.js.map +1 -0
- package/dist/connection/rebalance.d.ts +7 -0
- package/dist/connection/rebalance.d.ts.map +1 -0
- package/dist/connection/rebalance.js +2 -0
- package/dist/connection/rebalance.js.map +1 -0
- package/dist/consumption/attempts.d.ts +16 -0
- package/dist/consumption/attempts.d.ts.map +1 -0
- package/dist/consumption/attempts.js +23 -0
- package/dist/consumption/attempts.js.map +1 -0
- package/dist/consumption/backoff.d.ts +12 -0
- package/dist/consumption/backoff.d.ts.map +1 -0
- package/dist/consumption/backoff.js +20 -0
- package/dist/consumption/backoff.js.map +1 -0
- package/dist/consumption/consumption.d.ts +18 -0
- package/dist/consumption/consumption.d.ts.map +1 -0
- package/dist/consumption/consumption.js +33 -0
- package/dist/consumption/consumption.js.map +1 -0
- package/dist/consumption/delivery-postponed.d.ts +9 -0
- package/dist/consumption/delivery-postponed.d.ts.map +1 -0
- package/dist/consumption/delivery-postponed.js +12 -0
- package/dist/consumption/delivery-postponed.js.map +1 -0
- package/dist/consumption/failure-of.d.ts +7 -0
- package/dist/consumption/failure-of.d.ts.map +1 -0
- package/dist/consumption/failure-of.js +18 -0
- package/dist/consumption/failure-of.js.map +1 -0
- package/dist/consumption/group-consumer.d.ts +60 -0
- package/dist/consumption/group-consumer.d.ts.map +1 -0
- package/dist/consumption/group-consumer.js +145 -0
- package/dist/consumption/group-consumer.js.map +1 -0
- package/dist/consumption/poison-message.d.ts +3 -0
- package/dist/consumption/poison-message.d.ts.map +1 -0
- package/dist/consumption/poison-message.js +3 -0
- package/dist/consumption/poison-message.js.map +1 -0
- package/dist/consumption/postpone.d.ts +9 -0
- package/dist/consumption/postpone.d.ts.map +1 -0
- package/dist/consumption/postpone.js +30 -0
- package/dist/consumption/postpone.js.map +1 -0
- package/dist/consumption/record-handling.d.ts +58 -0
- package/dist/consumption/record-handling.d.ts.map +1 -0
- package/dist/consumption/record-handling.js +183 -0
- package/dist/consumption/record-handling.js.map +1 -0
- package/dist/consumption/timers.d.ts +7 -0
- package/dist/consumption/timers.d.ts.map +1 -0
- package/dist/consumption/timers.js +17 -0
- package/dist/consumption/timers.js.map +1 -0
- package/dist/errors/broker-unavailable-error.d.ts +8 -0
- package/dist/errors/broker-unavailable-error.d.ts.map +1 -0
- package/dist/errors/broker-unavailable-error.js +12 -0
- package/dist/errors/broker-unavailable-error.js.map +1 -0
- package/dist/errors/consumer-name-required-error.d.ts +5 -0
- package/dist/errors/consumer-name-required-error.d.ts.map +1 -0
- package/dist/errors/consumer-name-required-error.js +8 -0
- package/dist/errors/consumer-name-required-error.js.map +1 -0
- package/dist/errors/event-bus-closed-error.d.ts +5 -0
- package/dist/errors/event-bus-closed-error.d.ts.map +1 -0
- package/dist/errors/event-bus-closed-error.js +8 -0
- package/dist/errors/event-bus-closed-error.js.map +1 -0
- package/dist/errors/failure-code.d.ts +6 -0
- package/dist/errors/failure-code.d.ts.map +1 -0
- package/dist/errors/failure-code.js +15 -0
- package/dist/errors/failure-code.js.map +1 -0
- package/dist/errors/publish-not-acknowledged-error.d.ts +14 -0
- package/dist/errors/publish-not-acknowledged-error.d.ts.map +1 -0
- package/dist/errors/publish-not-acknowledged-error.js +18 -0
- package/dist/errors/publish-not-acknowledged-error.js.map +1 -0
- package/dist/errors/reason-of.d.ts +3 -0
- package/dist/errors/reason-of.d.ts.map +1 -0
- package/dist/errors/reason-of.js +11 -0
- package/dist/errors/reason-of.js.map +1 -0
- package/dist/errors/within.d.ts +3 -0
- package/dist/errors/within.d.ts.map +1 -0
- package/dist/errors/within.js +17 -0
- package/dist/errors/within.js.map +1 -0
- package/dist/ignore.d.ts +3 -0
- package/dist/ignore.d.ts.map +1 -0
- package/dist/ignore.js +5 -0
- package/dist/ignore.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/kafka-event-bus.d.ts +58 -0
- package/dist/kafka-event-bus.d.ts.map +1 -0
- package/dist/kafka-event-bus.js +147 -0
- package/dist/kafka-event-bus.js.map +1 -0
- package/dist/messaging-system.d.ts +3 -0
- package/dist/messaging-system.d.ts.map +1 -0
- package/dist/messaging-system.js +3 -0
- package/dist/messaging-system.js.map +1 -0
- package/dist/options/kafka-delivery.d.ts +15 -0
- package/dist/options/kafka-delivery.d.ts.map +1 -0
- package/dist/options/kafka-delivery.js +2 -0
- package/dist/options/kafka-delivery.js.map +1 -0
- package/dist/options/kafka-event-bus-options.d.ts +42 -0
- package/dist/options/kafka-event-bus-options.d.ts.map +1 -0
- package/dist/options/kafka-event-bus-options.js +2 -0
- package/dist/options/kafka-event-bus-options.js.map +1 -0
- package/dist/options/kafka-failure.d.ts +19 -0
- package/dist/options/kafka-failure.d.ts.map +1 -0
- package/dist/options/kafka-failure.js +2 -0
- package/dist/options/kafka-failure.js.map +1 -0
- package/dist/options/reconnect-options.d.ts +9 -0
- package/dist/options/reconnect-options.d.ts.map +1 -0
- package/dist/options/reconnect-options.js +2 -0
- package/dist/options/reconnect-options.js.map +1 -0
- package/dist/options/retry-options.d.ts +7 -0
- package/dist/options/retry-options.d.ts.map +1 -0
- package/dist/options/retry-options.js +2 -0
- package/dist/options/retry-options.js.map +1 -0
- package/dist/options/settings-of.d.ts +4 -0
- package/dist/options/settings-of.d.ts.map +1 -0
- package/dist/options/settings-of.js +47 -0
- package/dist/options/settings-of.js.map +1 -0
- package/dist/options/settings.d.ts +27 -0
- package/dist/options/settings.d.ts.map +1 -0
- package/dist/options/settings.js +2 -0
- package/dist/options/settings.js.map +1 -0
- package/dist/options/topic-options.d.ts +9 -0
- package/dist/options/topic-options.d.ts.map +1 -0
- package/dist/options/topic-options.js +2 -0
- package/dist/options/topic-options.js.map +1 -0
- package/dist/publication/publications.d.ts +30 -0
- package/dist/publication/publications.d.ts.map +1 -0
- package/dist/publication/publications.js +83 -0
- package/dist/publication/publications.js.map +1 -0
- package/dist/replay/dead-letter-replay.d.ts +31 -0
- package/dist/replay/dead-letter-replay.d.ts.map +1 -0
- package/dist/replay/dead-letter-replay.js +97 -0
- package/dist/replay/dead-letter-replay.js.map +1 -0
- package/dist/secrecy/conceal.d.ts +8 -0
- package/dist/secrecy/conceal.d.ts.map +1 -0
- package/dist/secrecy/conceal.js +12 -0
- package/dist/secrecy/conceal.js.map +1 -0
- package/dist/topology/consumer-binding.d.ts +6 -0
- package/dist/topology/consumer-binding.d.ts.map +1 -0
- package/dist/topology/consumer-binding.js +2 -0
- package/dist/topology/consumer-binding.js.map +1 -0
- package/dist/topology/dead-topic-of.d.ts +3 -0
- package/dist/topology/dead-topic-of.d.ts.map +1 -0
- package/dist/topology/dead-topic-of.js +5 -0
- package/dist/topology/dead-topic-of.js.map +1 -0
- package/dist/topology/describe-topic.d.ts +5 -0
- package/dist/topology/describe-topic.d.ts.map +1 -0
- package/dist/topology/describe-topic.js +5 -0
- package/dist/topology/describe-topic.js.map +1 -0
- package/dist/topology/group-description.d.ts +5 -0
- package/dist/topology/group-description.d.ts.map +1 -0
- package/dist/topology/group-description.js +2 -0
- package/dist/topology/group-description.js.map +1 -0
- package/dist/topology/kafka-topology.d.ts +8 -0
- package/dist/topology/kafka-topology.d.ts.map +1 -0
- package/dist/topology/kafka-topology.js +2 -0
- package/dist/topology/kafka-topology.js.map +1 -0
- package/dist/topology/replay-group-of.d.ts +3 -0
- package/dist/topology/replay-group-of.d.ts.map +1 -0
- package/dist/topology/replay-group-of.js +5 -0
- package/dist/topology/replay-group-of.js.map +1 -0
- package/dist/topology/topic-description.d.ts +10 -0
- package/dist/topology/topic-description.d.ts.map +1 -0
- package/dist/topology/topic-description.js +2 -0
- package/dist/topology/topic-description.js.map +1 -0
- package/dist/topology/topology-of.d.ts +5 -0
- package/dist/topology/topology-of.d.ts.map +1 -0
- package/dist/topology/topology-of.js +25 -0
- package/dist/topology/topology-of.js.map +1 -0
- package/dist/topology/topology-settings.d.ts +7 -0
- package/dist/topology/topology-settings.d.ts.map +1 -0
- package/dist/topology/topology-settings.js +2 -0
- package/dist/topology/topology-settings.js.map +1 -0
- package/package.json +37 -4
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { reasonOf } from '../errors/reason-of.js';
|
|
2
|
+
import { ignore } from '../ignore.js';
|
|
3
|
+
import { topologyOf } from '../topology/topology-of.js';
|
|
4
|
+
import { Backoff } from './backoff.js';
|
|
5
|
+
import { postpone } from './postpone.js';
|
|
6
|
+
import { RecordHandling } from './record-handling.js';
|
|
7
|
+
import { Timers } from './timers.js';
|
|
8
|
+
/**
|
|
9
|
+
* One consuming context: a member of the consumer group named after it. It joins the group,
|
|
10
|
+
* subscribes to the topics of its event types as they are added, starts again after a delay
|
|
11
|
+
* when the cluster fails it, and hands each record it reads to its `RecordHandling`.
|
|
12
|
+
*/
|
|
13
|
+
export class GroupConsumer {
|
|
14
|
+
name;
|
|
15
|
+
dependencies;
|
|
16
|
+
topics = new Set();
|
|
17
|
+
subscribed = new Set();
|
|
18
|
+
timers = new Timers();
|
|
19
|
+
backoff;
|
|
20
|
+
records;
|
|
21
|
+
client;
|
|
22
|
+
running = false;
|
|
23
|
+
work = Promise.resolve();
|
|
24
|
+
joined = Promise.resolve();
|
|
25
|
+
join = ignore;
|
|
26
|
+
draining = false;
|
|
27
|
+
constructor(name, dependencies) {
|
|
28
|
+
this.name = name;
|
|
29
|
+
this.dependencies = dependencies;
|
|
30
|
+
const { publications, settings } = dependencies;
|
|
31
|
+
this.backoff = new Backoff(settings.reconnect);
|
|
32
|
+
this.records = new RecordHandling(name, {
|
|
33
|
+
publications,
|
|
34
|
+
retry: settings.retry,
|
|
35
|
+
backoff: this.backoff,
|
|
36
|
+
timers: this.timers,
|
|
37
|
+
commit: async (position) => {
|
|
38
|
+
await this.client?.commitOffsets([position]);
|
|
39
|
+
},
|
|
40
|
+
onFailure: settings.onFailure,
|
|
41
|
+
onDelivery: settings.onDelivery,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
get inFlight() {
|
|
45
|
+
return this.records.inFlight;
|
|
46
|
+
}
|
|
47
|
+
get partitionsAssigned() {
|
|
48
|
+
return this.client?.assignment().length ?? 0;
|
|
49
|
+
}
|
|
50
|
+
types() {
|
|
51
|
+
return this.records.types();
|
|
52
|
+
}
|
|
53
|
+
add(type, handler) {
|
|
54
|
+
const subscription = this.records.add(type, handler);
|
|
55
|
+
this.topics.add(this.dependencies.settings.topology.topicOf(type));
|
|
56
|
+
this.synchronize();
|
|
57
|
+
return subscription;
|
|
58
|
+
}
|
|
59
|
+
/** Resolves once the group has its partitions for the subscriptions made so far, or failed to. */
|
|
60
|
+
async started() {
|
|
61
|
+
await this.work;
|
|
62
|
+
await this.joined;
|
|
63
|
+
}
|
|
64
|
+
/** Stops reading, lets the handlers in progress finish and commit, leaves the group. */
|
|
65
|
+
async drain() {
|
|
66
|
+
this.draining = true;
|
|
67
|
+
this.timers.cancel();
|
|
68
|
+
this.records.abandonWaiting();
|
|
69
|
+
await this.work;
|
|
70
|
+
// The client stays until it has left: the handlers in progress still commit through it.
|
|
71
|
+
await this.client?.disconnect().catch(ignore);
|
|
72
|
+
this.client = undefined;
|
|
73
|
+
}
|
|
74
|
+
synchronize() {
|
|
75
|
+
this.work = this.work.then(() => this.subscribePending());
|
|
76
|
+
}
|
|
77
|
+
async subscribePending() {
|
|
78
|
+
const pending = [...this.topics].filter((topic) => !this.subscribed.has(topic));
|
|
79
|
+
if (this.draining || pending.length === 0) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
await this.dependencies.link.declare(this.topology().topics);
|
|
84
|
+
const client = await this.connected();
|
|
85
|
+
this.joined = new Promise((resolve) => {
|
|
86
|
+
this.join = resolve;
|
|
87
|
+
});
|
|
88
|
+
await client.subscribe({ topics: pending });
|
|
89
|
+
await this.run(client);
|
|
90
|
+
pending.forEach((topic) => this.subscribed.add(topic));
|
|
91
|
+
this.backoff.reset();
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
this.restartLater(reasonOf(error));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
topology() {
|
|
98
|
+
const bindings = this.types().map((type) => ({ consumer: this.name, type }));
|
|
99
|
+
return topologyOf({ ...this.dependencies.settings.topology, publishedTypes: [] }, bindings);
|
|
100
|
+
}
|
|
101
|
+
async connected() {
|
|
102
|
+
const { link } = this.dependencies;
|
|
103
|
+
this.client ??= await link.connected(link.consumer(this.name, (rebalance) => {
|
|
104
|
+
this.rebalanced(rebalance);
|
|
105
|
+
}));
|
|
106
|
+
return this.client;
|
|
107
|
+
}
|
|
108
|
+
rebalanced({ assigned, partitions }) {
|
|
109
|
+
if (assigned) {
|
|
110
|
+
this.join();
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
this.records.forget(partitions);
|
|
114
|
+
}
|
|
115
|
+
async run(client) {
|
|
116
|
+
if (this.running) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
this.running = true;
|
|
120
|
+
await client.run({
|
|
121
|
+
partitionsConsumedConcurrently: this.dependencies.settings.concurrency,
|
|
122
|
+
eachMessage: (delivery) => this.deliver(delivery),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
async deliver(delivery) {
|
|
126
|
+
if (this.draining) {
|
|
127
|
+
postpone(delivery, ignore);
|
|
128
|
+
}
|
|
129
|
+
await this.records.deliver(delivery);
|
|
130
|
+
}
|
|
131
|
+
restartLater(code) {
|
|
132
|
+
this.dependencies.settings.onFailure({ kind: 'connection', code });
|
|
133
|
+
const client = this.client;
|
|
134
|
+
this.client = undefined;
|
|
135
|
+
this.running = false;
|
|
136
|
+
this.subscribed.clear();
|
|
137
|
+
void client?.disconnect().catch(ignore);
|
|
138
|
+
this.join();
|
|
139
|
+
this.timers.later(() => {
|
|
140
|
+
this.synchronize();
|
|
141
|
+
}, this.backoff.delayMs);
|
|
142
|
+
this.backoff.failed();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=group-consumer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group-consumer.js","sourceRoot":"","sources":["../../src/consumption/group-consumer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAOtC,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAExD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAiBrC;;;;GAIG;AACH,MAAM,OAAO,aAAa;IAwBb,IAAI;IACI,YAAY;IAxBd,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;IAE3B,UAAU,GAAG,IAAI,GAAG,EAAU,CAAC;IAE/B,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;IAEtB,OAAO,CAAU;IAEjB,OAAO,CAAiB;IAEjC,MAAM,CAA+B;IAErC,OAAO,GAAG,KAAK,CAAC;IAEhB,IAAI,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IAExC,MAAM,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IAE1C,IAAI,GAAe,MAAM,CAAC;IAE1B,QAAQ,GAAG,KAAK,CAAC;IAEzB,YACW,IAAY,EACJ,YAA+B;oBADvC,IAAI;4BACI,YAAY;QAE7B,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,GAAG,YAAY,CAAC;QAEhD,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAE/C,IAAI,CAAC,OAAO,GAAG,IAAI,cAAc,CAAC,IAAI,EAAE;YACtC,YAAY;YACZ,K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AAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poison-message.js","sourceRoot":"","sources":["../../src/consumption/poison-message.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { KafkaJS } from '@confluentinc/kafka-javascript';
|
|
2
|
+
type Delivery = KafkaJS.EachMessagePayload;
|
|
3
|
+
/**
|
|
4
|
+
* Pauses the partition of the record and hands `release` the way to resume it. Throwing is
|
|
5
|
+
* how the client is told to read the record again instead of moving to the next one.
|
|
6
|
+
*/
|
|
7
|
+
export declare function postpone(delivery: Delivery, release: (resume: () => void) => void): never;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=postpone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postpone.d.ts","sourceRoot":"","sources":["../../src/consumption/postpone.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAI9D,KAAK,QAAQ,GAAG,OAAO,CAAC,kBAAkB,CAAC;AAE3C;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,IAAI,KAAK,IAAI,GAAG,KAAK,CAGzF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ignore } from '../ignore.js';
|
|
2
|
+
import { DeliveryPostponed } from './delivery-postponed.js';
|
|
3
|
+
/**
|
|
4
|
+
* Pauses the partition of the record and hands `release` the way to resume it. Throwing is
|
|
5
|
+
* how the client is told to read the record again instead of moving to the next one.
|
|
6
|
+
*/
|
|
7
|
+
export function postpone(delivery, release) {
|
|
8
|
+
release(quietly(pausing(delivery)));
|
|
9
|
+
throw new DeliveryPostponed();
|
|
10
|
+
}
|
|
11
|
+
// Pausing or resuming a partition the group took back throws: the new owner reads the record.
|
|
12
|
+
function pausing(delivery) {
|
|
13
|
+
try {
|
|
14
|
+
return delivery.pause();
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return ignore;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function quietly(act) {
|
|
21
|
+
return () => {
|
|
22
|
+
try {
|
|
23
|
+
act();
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=postpone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postpone.js","sourceRoot":"","sources":["../../src/consumption/postpone.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAI5D;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,QAAkB,EAAE,OAAqC;IAChF,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACpC,MAAM,IAAI,iBAAiB,EAAE,CAAC;AAChC,CAAC;AAED,8FAA8F;AAC9F,SAAS,OAAO,CAAC,QAAkB;IACjC,IAAI,CAAC;QACH,OAAO,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC;IAChB,CAAC;AACH,CAAC;AAED,SAAS,OAAO,CAAC,GAAe;IAC9B,OAAO,GAAG,EAAE;QACV,IAAI,CAAC;YACH,GAAG,EAAE,CAAC;QACR,CAAC;QAAC,MAAM,CAAC;YACP,OAAO;QACT,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { KafkaJS } from '@confluentinc/kafka-javascript';
|
|
2
|
+
import type { IntegrationEventCallback, Subscription } from '@ddd-ts-kit/kernel';
|
|
3
|
+
import type { KafkaDelivery } from '../options/kafka-delivery.js';
|
|
4
|
+
import type { KafkaFailure } from '../options/kafka-failure.js';
|
|
5
|
+
import type { RetryOptions } from '../options/retry-options.js';
|
|
6
|
+
import type { Publications } from '../publication/publications.js';
|
|
7
|
+
import type { Backoff } from './backoff.js';
|
|
8
|
+
import type { Timers } from './timers.js';
|
|
9
|
+
export interface RecordHandlingDependencies {
|
|
10
|
+
readonly publications: Publications;
|
|
11
|
+
readonly retry: Required<RetryOptions>;
|
|
12
|
+
readonly backoff: Backoff;
|
|
13
|
+
readonly timers: Timers;
|
|
14
|
+
/** Commits the offset that follows a record, through the client of the group. */
|
|
15
|
+
readonly commit: (position: KafkaJS.TopicPartitionOffset) => Promise<void>;
|
|
16
|
+
readonly onFailure: (failure: KafkaFailure) => void;
|
|
17
|
+
readonly onDelivery: (delivery: KafkaDelivery) => void;
|
|
18
|
+
}
|
|
19
|
+
type Delivery = KafkaJS.EachMessagePayload;
|
|
20
|
+
/**
|
|
21
|
+
* What a consuming context does with one record. An offset is committed once every handler
|
|
22
|
+
* of the record resolved, never before. A record whose handler fails keeps its place: its
|
|
23
|
+
* partition is paused for the delay and the record is read again, so the records of a key
|
|
24
|
+
* stay in order, and after the last attempt it is copied to the dead-letter topic and the
|
|
25
|
+
* partition moves on.
|
|
26
|
+
*/
|
|
27
|
+
export declare class RecordHandling {
|
|
28
|
+
private readonly consumer;
|
|
29
|
+
private readonly dependencies;
|
|
30
|
+
private readonly handlers;
|
|
31
|
+
private readonly attempts;
|
|
32
|
+
private readonly waitingForHandlers;
|
|
33
|
+
private handling;
|
|
34
|
+
constructor(consumer: string, dependencies: RecordHandlingDependencies);
|
|
35
|
+
get inFlight(): number;
|
|
36
|
+
types(): string[];
|
|
37
|
+
add(type: string, handler: IntegrationEventCallback): Subscription;
|
|
38
|
+
/** The group took these partitions back: their next owner counts the attempts again. */
|
|
39
|
+
forget(partitions: readonly KafkaJS.TopicPartition[]): void;
|
|
40
|
+
/** The records that wait for a handler stay where they are: the consumer is going away. */
|
|
41
|
+
abandonWaiting(): void;
|
|
42
|
+
deliver(delivery: Delivery): Promise<void>;
|
|
43
|
+
private resumeWaiting;
|
|
44
|
+
private process;
|
|
45
|
+
/** A replayed dead letter is on the topic for the one consumer that had given up on it. */
|
|
46
|
+
private isForAnotherConsumer;
|
|
47
|
+
private handle;
|
|
48
|
+
private deliveryOf;
|
|
49
|
+
private retryOrBury;
|
|
50
|
+
private buryPoison;
|
|
51
|
+
/** Acknowledged copy to the dead-letter topic first, commit second: never lost in between. */
|
|
52
|
+
private bury;
|
|
53
|
+
private commit;
|
|
54
|
+
private postponeAfter;
|
|
55
|
+
private settled;
|
|
56
|
+
}
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=record-handling.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record-handling.d.ts","sourceRoot":"","sources":["../../src/consumption/record-handling.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,KAAK,EAAmC,wBAAwB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAalH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAGnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAI5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACvC,QAAQ,CAAC,OA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;YAUJ,WAAW;YAyBX,UAAU;IASxB,8FAA8F;YAChF,IAAI;YAaJ,MAAM;IAepB,OAAO,CAAC,aAAa;IAarB,OAAO,CAAC,OAAO;CAMhB"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { decode } from '../codec/decode.js';
|
|
2
|
+
import { ATTEMPT_HEADER, DEAD_REASON_HEADER, ERROR_CODE_HEADER, REPLAY_FOR_HEADER, SOURCE_HEADER, } from '../codec/headers.js';
|
|
3
|
+
import { republication } from '../codec/republication.js';
|
|
4
|
+
import { sourceOf } from '../codec/source-of.js';
|
|
5
|
+
import { textHeader } from '../codec/text-header.js';
|
|
6
|
+
import { reasonOf } from '../errors/reason-of.js';
|
|
7
|
+
import { MESSAGING_SYSTEM } from '../messaging-system.js';
|
|
8
|
+
import { deadTopicOf } from '../topology/dead-topic-of.js';
|
|
9
|
+
import { Attempts } from './attempts.js';
|
|
10
|
+
import { failureOf } from './failure-of.js';
|
|
11
|
+
import { POISON_MESSAGE } from './poison-message.js';
|
|
12
|
+
import { postpone } from './postpone.js';
|
|
13
|
+
/**
|
|
14
|
+
* What a consuming context does with one record. An offset is committed once every handler
|
|
15
|
+
* of the record resolved, never before. A record whose handler fails keeps its place: its
|
|
16
|
+
* partition is paused for the delay and the record is read again, so the records of a key
|
|
17
|
+
* stay in order, and after the last attempt it is copied to the dead-letter topic and the
|
|
18
|
+
* partition moves on.
|
|
19
|
+
*/
|
|
20
|
+
export class RecordHandling {
|
|
21
|
+
consumer;
|
|
22
|
+
dependencies;
|
|
23
|
+
handlers = new Map();
|
|
24
|
+
attempts = new Attempts();
|
|
25
|
+
waitingForHandlers = new Set();
|
|
26
|
+
handling = 0;
|
|
27
|
+
constructor(consumer, dependencies) {
|
|
28
|
+
this.consumer = consumer;
|
|
29
|
+
this.dependencies = dependencies;
|
|
30
|
+
}
|
|
31
|
+
get inFlight() {
|
|
32
|
+
return this.handling;
|
|
33
|
+
}
|
|
34
|
+
types() {
|
|
35
|
+
return [...this.handlers.keys()];
|
|
36
|
+
}
|
|
37
|
+
add(type, handler) {
|
|
38
|
+
const handlers = this.handlers.get(type) ?? new Set();
|
|
39
|
+
this.handlers.set(type, handlers.add(handler));
|
|
40
|
+
this.resumeWaiting();
|
|
41
|
+
return {
|
|
42
|
+
// The group keeps its place in the log: the consumer only stopped reading.
|
|
43
|
+
unsubscribe: () => {
|
|
44
|
+
handlers.delete(handler);
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** The group took these partitions back: their next owner counts the attempts again. */
|
|
49
|
+
forget(partitions) {
|
|
50
|
+
for (const partition of partitions) {
|
|
51
|
+
this.attempts.forget(partition);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** The records that wait for a handler stay where they are: the consumer is going away. */
|
|
55
|
+
abandonWaiting() {
|
|
56
|
+
this.waitingForHandlers.clear();
|
|
57
|
+
}
|
|
58
|
+
async deliver(delivery) {
|
|
59
|
+
this.handling += 1;
|
|
60
|
+
try {
|
|
61
|
+
await this.process(delivery);
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
this.handling -= 1;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
resumeWaiting() {
|
|
68
|
+
for (const resume of this.waitingForHandlers) {
|
|
69
|
+
resume();
|
|
70
|
+
}
|
|
71
|
+
this.waitingForHandlers.clear();
|
|
72
|
+
}
|
|
73
|
+
async process(delivery) {
|
|
74
|
+
if (this.isForAnotherConsumer(delivery)) {
|
|
75
|
+
await this.commit(delivery);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const event = decode(delivery.message.value);
|
|
79
|
+
if (event === undefined) {
|
|
80
|
+
await this.buryPoison(delivery);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const handlers = this.handlers.get(event.type);
|
|
84
|
+
if (handlers === undefined) {
|
|
85
|
+
// A type this consumer never subscribed to, on a topic that carries several.
|
|
86
|
+
await this.commit(delivery);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
await this.handle(delivery, event, handlers);
|
|
90
|
+
}
|
|
91
|
+
/** A replayed dead letter is on the topic for the one consumer that had given up on it. */
|
|
92
|
+
isForAnotherConsumer(delivery) {
|
|
93
|
+
const target = textHeader(delivery, REPLAY_FOR_HEADER);
|
|
94
|
+
return target !== undefined && target !== this.consumer;
|
|
95
|
+
}
|
|
96
|
+
async handle(delivery, event, handlers) {
|
|
97
|
+
if (handlers.size === 0) {
|
|
98
|
+
postpone(delivery, (resume) => this.waitingForHandlers.add(resume));
|
|
99
|
+
}
|
|
100
|
+
const code = await failureOf(handlers, event, this.deliveryOf(delivery));
|
|
101
|
+
if (code === undefined) {
|
|
102
|
+
this.settled(delivery, 'acknowledged');
|
|
103
|
+
await this.commit(delivery);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
await this.retryOrBury(delivery, event, code);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
deliveryOf(delivery) {
|
|
110
|
+
return {
|
|
111
|
+
attempt: this.attempts.of(delivery),
|
|
112
|
+
maxAttempts: this.dependencies.retry.maxAttempts,
|
|
113
|
+
system: MESSAGING_SYSTEM,
|
|
114
|
+
destination: delivery.topic,
|
|
115
|
+
consumer: this.consumer,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
async retryOrBury(delivery, event, code) {
|
|
119
|
+
const { retry, timers, onFailure } = this.dependencies;
|
|
120
|
+
const attempt = this.attempts.of(delivery);
|
|
121
|
+
const dead = attempt >= retry.maxAttempts;
|
|
122
|
+
const { id: eventId, type: eventType } = event;
|
|
123
|
+
const { consumer } = this;
|
|
124
|
+
onFailure({ kind: 'handler', consumer, topic: delivery.topic, eventId, eventType, code, attempt, dead });
|
|
125
|
+
this.settled(delivery, dead ? 'dead' : 'retried');
|
|
126
|
+
if (dead) {
|
|
127
|
+
const headers = { [ERROR_CODE_HEADER]: code, [DEAD_REASON_HEADER]: 'max-attempts' };
|
|
128
|
+
await this.bury(delivery, { ...headers, [ATTEMPT_HEADER]: String(attempt) });
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
this.attempts.failed(delivery);
|
|
132
|
+
postpone(delivery, (resume) => {
|
|
133
|
+
timers.later(resume, retry.delayMs);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
async buryPoison(delivery) {
|
|
137
|
+
const { consumer } = this;
|
|
138
|
+
const { topic } = delivery;
|
|
139
|
+
this.dependencies.onFailure({ kind: 'poison', consumer, topic, code: POISON_MESSAGE });
|
|
140
|
+
this.settled(delivery, 'poison');
|
|
141
|
+
await this.bury(delivery, { [ERROR_CODE_HEADER]: POISON_MESSAGE, [DEAD_REASON_HEADER]: 'poison' });
|
|
142
|
+
}
|
|
143
|
+
/** Acknowledged copy to the dead-letter topic first, commit second: never lost in between. */
|
|
144
|
+
async bury(delivery, headers) {
|
|
145
|
+
const dead = deadTopicOf(this.consumer, delivery.topic);
|
|
146
|
+
const source = { [SOURCE_HEADER]: sourceOf(delivery) };
|
|
147
|
+
try {
|
|
148
|
+
await this.dependencies.publications.send(republication(delivery, dead, { ...headers, ...source }));
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
this.postponeAfter(delivery, error);
|
|
152
|
+
}
|
|
153
|
+
await this.commit(delivery);
|
|
154
|
+
}
|
|
155
|
+
async commit(delivery) {
|
|
156
|
+
const { topic, partition, message } = delivery;
|
|
157
|
+
const offset = String(BigInt(message.offset) + 1n);
|
|
158
|
+
this.attempts.forget(delivery);
|
|
159
|
+
try {
|
|
160
|
+
await this.dependencies.commit({ topic, partition, offset });
|
|
161
|
+
this.dependencies.backoff.reset();
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
this.postponeAfter(delivery, error);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// The partition must not move past a record that is neither committed nor parked.
|
|
168
|
+
postponeAfter(delivery, error) {
|
|
169
|
+
const { backoff, timers, onFailure } = this.dependencies;
|
|
170
|
+
onFailure({ kind: 'connection', code: reasonOf(error) });
|
|
171
|
+
const delay = backoff.delayMs;
|
|
172
|
+
backoff.failed();
|
|
173
|
+
postpone(delivery, (resume) => {
|
|
174
|
+
timers.later(resume, delay);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
settled(delivery, outcome) {
|
|
178
|
+
const { topic, partition } = delivery;
|
|
179
|
+
const attempt = this.attempts.of(delivery);
|
|
180
|
+
this.dependencies.onDelivery({ consumer: this.consumer, topic, partition, attempt, outcome });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=record-handling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record-handling.js","sourceRoot":"","sources":["../../src/consumption/record-handling.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,GACd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAI1D,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAgBzC;;;;;;GAMG;AACH,MAAM,OAAO,cAAc;IAUN,QAAQ;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C;IAED,MAAM,IAAI,IAAI,CAIb;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** The delayed actions of a consumer, so that draining it cancels every one of them. */
|
|
2
|
+
export class Timers {
|
|
3
|
+
pending = new Set();
|
|
4
|
+
later(act, delayMs) {
|
|
5
|
+
const timer = setTimeout(() => {
|
|
6
|
+
this.pending.delete(timer);
|
|
7
|
+
act();
|
|
8
|
+
}, delayMs);
|
|
9
|
+
this.pending.add(timer);
|
|
10
|
+
}
|
|
11
|
+
cancel() {
|
|
12
|
+
for (const timer of this.pending) {
|
|
13
|
+
clearTimeout(timer);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=timers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timers.js","sourceRoot":"","sources":["../../src/consumption/timers.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,MAAM,OAAO,MAAM;IACA,OAAO,GAAG,IAAI,GAAG,EAAiC,CAAC;IAEpE,KAAK,CAAC,GAAe,EAAE,OAAe;QACpC,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC3B,GAAG,EAAE,CAAC;QACR,CAAC,EAAE,OAAO,CAAC,CAAC;QAEZ,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAED,MAAM;QACJ,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjC,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** The cluster cannot be reached, or did not answer in time. */
|
|
2
|
+
export declare class BrokerUnavailableError extends Error {
|
|
3
|
+
readonly reason: string;
|
|
4
|
+
readonly code = "BROKER_UNAVAILABLE";
|
|
5
|
+
/** `reason` is the code of what made the cluster unreachable, never a message. */
|
|
6
|
+
constructor(reason: string);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=broker-unavailable-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"broker-unavailable-error.d.ts","sourceRoot":"","sources":["../../src/errors/broker-unavailable-error.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,qBAAa,sBAAuB,SAAQ,KAAK;IAInC,QAAQ,CAAC,MAAM,EAAE,MAAM;IAHnC,QAAQ,CAAC,IAAI,wBAAwB;IAErC,kFAAkF;IAClF,YAAqB,MAAM,EAAE,MAAM,EAGlC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** The cluster cannot be reached, or did not answer in time. */
|
|
2
|
+
export class BrokerUnavailableError extends Error {
|
|
3
|
+
reason;
|
|
4
|
+
code = 'BROKER_UNAVAILABLE';
|
|
5
|
+
/** `reason` is the code of what made the cluster unreachable, never a message. */
|
|
6
|
+
constructor(reason) {
|
|
7
|
+
super(`The broker is unavailable (${reason})`);
|
|
8
|
+
this.reason = reason;
|
|
9
|
+
this.name = 'BrokerUnavailableError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=broker-unavailable-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"broker-unavailable-error.js","sourceRoot":"","sources":["../../src/errors/broker-unavailable-error.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAI1B,MAAM;IAHlB,IAAI,GAAG,oBAAoB,CAAC;IAErC,kFAAkF;IAClF,YAAqB,MAAc;QACjC,KAAK,CAAC,8BAA8B,MAAM,GAAG,CAAC,CAAC;sBAD5B,MAAM;QAEzB,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consumer-name-required-error.d.ts","sourceRoot":"","sources":["../../src/errors/consumer-name-required-error.ts"],"names":[],"mappings":"AAAA,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,QAAQ,CAAC,IAAI,4BAA4B;IAEzC,cAIC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export class ConsumerNameRequiredError extends Error {
|
|
2
|
+
code = 'CONSUMER_NAME_REQUIRED';
|
|
3
|
+
constructor() {
|
|
4
|
+
super('Subscribing needs a consumer name: build the bus with `consumer`, or use `forConsumer(name)`');
|
|
5
|
+
this.name = 'ConsumerNameRequiredError';
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=consumer-name-required-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consumer-name-required-error.js","sourceRoot":"","sources":["../../src/errors/consumer-name-required-error.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IACzC,IAAI,GAAG,wBAAwB,CAAC;IAEzC;QACE,KAAK,CAAC,8FAA8F,CAAC,CAAC;QAEtG,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC1C,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-bus-closed-error.d.ts","sourceRoot":"","sources":["../../src/errors/event-bus-closed-error.ts"],"names":[],"mappings":"AAAA,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,IAAI,sBAAsB;IAEnC,cAGC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-bus-closed-error.js","sourceRoot":"","sources":["../../src/errors/event-bus-closed-error.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IACnC,IAAI,GAAG,kBAAkB,CAAC;IAEnC;QACE,KAAK,CAAC,yBAAyB,CAAC,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What may be reported about an error of the client. librdkafka names its errors in `type`
|
|
3
|
+
* (`ERR__MSG_TIMED_OUT`, `ERR_UNKNOWN_TOPIC_OR_PART`): that name is the code. Never the message.
|
|
4
|
+
*/
|
|
5
|
+
export declare function failureCode(error: unknown): string;
|
|
6
|
+
//# sourceMappingURL=failure-code.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failure-code.d.ts","sourceRoot":"","sources":["../../src/errors/failure-code.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAUlD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { errorCode } from '@ddd-ts-kit/events';
|
|
2
|
+
/**
|
|
3
|
+
* What may be reported about an error of the client. librdkafka names its errors in `type`
|
|
4
|
+
* (`ERR__MSG_TIMED_OUT`, `ERR_UNKNOWN_TOPIC_OR_PART`): that name is the code. Never the message.
|
|
5
|
+
*/
|
|
6
|
+
export function failureCode(error) {
|
|
7
|
+
if (typeof error === 'object' && error !== null && 'type' in error) {
|
|
8
|
+
const { type } = error;
|
|
9
|
+
if (typeof type === 'string' && /^ERR_[A-Z_]+$/.test(type)) {
|
|
10
|
+
return type;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return errorCode(error);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=failure-code.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failure-code.js","sourceRoot":"","sources":["../../src/errors/failure-code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,EAAE,CAAC;QACnE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;QAEvB,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3D,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC"}
|