@forklaunch/implementation-worker-kafka 1.0.40 → 1.0.41
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/lib/consumers/index.js +2 -2
- package/lib/consumers/index.mjs +2 -2
- package/lib/eject/consumers/kafkaWorker.consumer.ts +2 -2
- package/lib/eject/producers/kafkaWorker.producer.ts +15 -1
- package/lib/producers/index.js +11 -1
- package/lib/producers/index.mjs +11 -1
- package/lib/producers/kafkaWorker.producer.d.ts +2 -0
- package/lib/producers/kafkaWorker.producer.d.ts.map +1 -1
- package/package.json +5 -5
package/lib/consumers/index.js
CHANGED
|
@@ -76,7 +76,7 @@ var KafkaWorkerConsumer = class {
|
|
|
76
76
|
}
|
|
77
77
|
]);
|
|
78
78
|
} catch (error) {
|
|
79
|
-
this.failureHandler([
|
|
79
|
+
void this.failureHandler([
|
|
80
80
|
{
|
|
81
81
|
value: events[0],
|
|
82
82
|
error
|
|
@@ -134,7 +134,7 @@ var KafkaWorkerConsumer = class {
|
|
|
134
134
|
fromBeginning: false
|
|
135
135
|
});
|
|
136
136
|
const messagePromise = new Promise((resolve) => {
|
|
137
|
-
peekConsumer.run({
|
|
137
|
+
void peekConsumer.run({
|
|
138
138
|
eachMessage: async ({ message }) => {
|
|
139
139
|
if (message.value && events.length < this.options.peekCount) {
|
|
140
140
|
const messageEvents = JSON.parse(
|
package/lib/consumers/index.mjs
CHANGED
|
@@ -50,7 +50,7 @@ var KafkaWorkerConsumer = class {
|
|
|
50
50
|
}
|
|
51
51
|
]);
|
|
52
52
|
} catch (error) {
|
|
53
|
-
this.failureHandler([
|
|
53
|
+
void this.failureHandler([
|
|
54
54
|
{
|
|
55
55
|
value: events[0],
|
|
56
56
|
error
|
|
@@ -108,7 +108,7 @@ var KafkaWorkerConsumer = class {
|
|
|
108
108
|
fromBeginning: false
|
|
109
109
|
});
|
|
110
110
|
const messagePromise = new Promise((resolve) => {
|
|
111
|
-
peekConsumer.run({
|
|
111
|
+
void peekConsumer.run({
|
|
112
112
|
eachMessage: async ({ message }) => {
|
|
113
113
|
if (message.value && events.length < this.options.peekCount) {
|
|
114
114
|
const messageEvents = JSON.parse(
|
|
@@ -80,7 +80,7 @@ export class KafkaWorkerConsumer<
|
|
|
80
80
|
}
|
|
81
81
|
]);
|
|
82
82
|
} catch (error) {
|
|
83
|
-
this.failureHandler([
|
|
83
|
+
void this.failureHandler([
|
|
84
84
|
{
|
|
85
85
|
value: events[0],
|
|
86
86
|
error: error as Error
|
|
@@ -150,7 +150,7 @@ export class KafkaWorkerConsumer<
|
|
|
150
150
|
});
|
|
151
151
|
|
|
152
152
|
const messagePromise = new Promise<void>((resolve) => {
|
|
153
|
-
peekConsumer.run({
|
|
153
|
+
void peekConsumer.run({
|
|
154
154
|
eachMessage: async ({ message }) => {
|
|
155
155
|
if (message.value && events.length < this.options.peekCount) {
|
|
156
156
|
const messageEvents = JSON.parse(
|
|
@@ -6,6 +6,7 @@ export class KafkaWorkerProducer<
|
|
|
6
6
|
Options extends KafkaWorkerOptions
|
|
7
7
|
> {
|
|
8
8
|
private producer;
|
|
9
|
+
private connection?: Promise<void>;
|
|
9
10
|
private readonly queueName: string;
|
|
10
11
|
private readonly options: Options;
|
|
11
12
|
|
|
@@ -17,10 +18,22 @@ export class KafkaWorkerProducer<
|
|
|
17
18
|
brokers: this.options.brokers
|
|
18
19
|
});
|
|
19
20
|
this.producer = kafka.producer();
|
|
20
|
-
|
|
21
|
+
// Connect eagerly, but make every send wait for it: a send issued while
|
|
22
|
+
// the connection is still being established fails with "The producer is
|
|
23
|
+
// disconnected". A failed attempt is retried by the next send.
|
|
24
|
+
this.connect().catch(() => undefined);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private connect(): Promise<void> {
|
|
28
|
+
this.connection ??= this.producer.connect().catch((error: unknown) => {
|
|
29
|
+
this.connection = undefined;
|
|
30
|
+
throw error;
|
|
31
|
+
});
|
|
32
|
+
return this.connection;
|
|
21
33
|
}
|
|
22
34
|
|
|
23
35
|
async enqueueJob(event: EventEntity): Promise<void> {
|
|
36
|
+
await this.connect();
|
|
24
37
|
await this.producer.send({
|
|
25
38
|
topic: this.queueName,
|
|
26
39
|
messages: [{ value: JSON.stringify([event]) }]
|
|
@@ -28,6 +41,7 @@ export class KafkaWorkerProducer<
|
|
|
28
41
|
}
|
|
29
42
|
|
|
30
43
|
async enqueueBatchJobs(events: EventEntity[]): Promise<void> {
|
|
44
|
+
await this.connect();
|
|
31
45
|
await this.producer.send({
|
|
32
46
|
topic: this.queueName,
|
|
33
47
|
messages: events.map((event) => ({ value: JSON.stringify(event) }))
|
package/lib/producers/index.js
CHANGED
|
@@ -28,6 +28,7 @@ module.exports = __toCommonJS(producers_exports);
|
|
|
28
28
|
var import_kafkajs = require("kafkajs");
|
|
29
29
|
var KafkaWorkerProducer = class {
|
|
30
30
|
producer;
|
|
31
|
+
connection;
|
|
31
32
|
queueName;
|
|
32
33
|
options;
|
|
33
34
|
constructor(queueName, options) {
|
|
@@ -38,15 +39,24 @@ var KafkaWorkerProducer = class {
|
|
|
38
39
|
brokers: this.options.brokers
|
|
39
40
|
});
|
|
40
41
|
this.producer = kafka.producer();
|
|
41
|
-
this.
|
|
42
|
+
this.connect().catch(() => void 0);
|
|
43
|
+
}
|
|
44
|
+
connect() {
|
|
45
|
+
this.connection ??= this.producer.connect().catch((error) => {
|
|
46
|
+
this.connection = void 0;
|
|
47
|
+
throw error;
|
|
48
|
+
});
|
|
49
|
+
return this.connection;
|
|
42
50
|
}
|
|
43
51
|
async enqueueJob(event) {
|
|
52
|
+
await this.connect();
|
|
44
53
|
await this.producer.send({
|
|
45
54
|
topic: this.queueName,
|
|
46
55
|
messages: [{ value: JSON.stringify([event]) }]
|
|
47
56
|
});
|
|
48
57
|
}
|
|
49
58
|
async enqueueBatchJobs(events) {
|
|
59
|
+
await this.connect();
|
|
50
60
|
await this.producer.send({
|
|
51
61
|
topic: this.queueName,
|
|
52
62
|
messages: events.map((event) => ({ value: JSON.stringify(event) }))
|
package/lib/producers/index.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Kafka } from "kafkajs";
|
|
3
3
|
var KafkaWorkerProducer = class {
|
|
4
4
|
producer;
|
|
5
|
+
connection;
|
|
5
6
|
queueName;
|
|
6
7
|
options;
|
|
7
8
|
constructor(queueName, options) {
|
|
@@ -12,15 +13,24 @@ var KafkaWorkerProducer = class {
|
|
|
12
13
|
brokers: this.options.brokers
|
|
13
14
|
});
|
|
14
15
|
this.producer = kafka.producer();
|
|
15
|
-
this.
|
|
16
|
+
this.connect().catch(() => void 0);
|
|
17
|
+
}
|
|
18
|
+
connect() {
|
|
19
|
+
this.connection ??= this.producer.connect().catch((error) => {
|
|
20
|
+
this.connection = void 0;
|
|
21
|
+
throw error;
|
|
22
|
+
});
|
|
23
|
+
return this.connection;
|
|
16
24
|
}
|
|
17
25
|
async enqueueJob(event) {
|
|
26
|
+
await this.connect();
|
|
18
27
|
await this.producer.send({
|
|
19
28
|
topic: this.queueName,
|
|
20
29
|
messages: [{ value: JSON.stringify([event]) }]
|
|
21
30
|
});
|
|
22
31
|
}
|
|
23
32
|
async enqueueBatchJobs(events) {
|
|
33
|
+
await this.connect();
|
|
24
34
|
await this.producer.send({
|
|
25
35
|
topic: this.queueName,
|
|
26
36
|
messages: events.map((event) => ({ value: JSON.stringify(event) }))
|
|
@@ -2,9 +2,11 @@ import { WorkerEventEntity } from '@forklaunch/interfaces-worker/types';
|
|
|
2
2
|
import { KafkaWorkerOptions } from '../domain/types/kafkaWorker.types';
|
|
3
3
|
export declare class KafkaWorkerProducer<EventEntity extends WorkerEventEntity, Options extends KafkaWorkerOptions> {
|
|
4
4
|
private producer;
|
|
5
|
+
private connection?;
|
|
5
6
|
private readonly queueName;
|
|
6
7
|
private readonly options;
|
|
7
8
|
constructor(queueName: string, options: Options);
|
|
9
|
+
private connect;
|
|
8
10
|
enqueueJob(event: EventEntity): Promise<void>;
|
|
9
11
|
enqueueBatchJobs(events: EventEntity[]): Promise<void>;
|
|
10
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kafkaWorker.producer.d.ts","sourceRoot":"","sources":["../../producers/kafkaWorker.producer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAExE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,qBAAa,mBAAmB,CAC9B,WAAW,SAAS,iBAAiB,EACrC,OAAO,SAAS,kBAAkB;IAElC,OAAO,CAAC,QAAQ,CAAC;IACjB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAElC,YAAY,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"kafkaWorker.producer.d.ts","sourceRoot":"","sources":["../../producers/kafkaWorker.producer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAExE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,qBAAa,mBAAmB,CAC9B,WAAW,SAAS,iBAAiB,EACrC,OAAO,SAAS,kBAAkB;IAElC,OAAO,CAAC,QAAQ,CAAC;IACjB,OAAO,CAAC,UAAU,CAAC,CAAgB;IACnC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAElC,YAAY,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAY9C;IAED,OAAO,CAAC,OAAO;IAQT,UAAU,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAMlD;IAEK,gBAAgB,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAM3D;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forklaunch/implementation-worker-kafka",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.41",
|
|
4
4
|
"description": "Kafka implementation for forklaunch workers",
|
|
5
5
|
"homepage": "https://github.com/forklaunch/forklaunch-js#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -54,13 +54,13 @@
|
|
|
54
54
|
"lib/**"
|
|
55
55
|
],
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@forklaunch/core": "^3.
|
|
57
|
+
"@forklaunch/core": "^3.3.0",
|
|
58
|
+
"@forklaunch/interfaces-worker": "^1.0.37",
|
|
58
59
|
"@forklaunch/internal": "^1.2.35",
|
|
59
|
-
"@forklaunch/validator": "^1.
|
|
60
|
+
"@forklaunch/validator": "^1.3.0",
|
|
60
61
|
"@sinclair/typebox": "^0.34.52",
|
|
61
62
|
"kafkajs": "^2.2.4",
|
|
62
|
-
"zod": "^4.6.7"
|
|
63
|
-
"@forklaunch/interfaces-worker": "^1.0.37"
|
|
63
|
+
"zod": "^4.6.7"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"depcheck": "^1.4.7",
|