pulse-sdk 1.0.13 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/producer.d.ts +2 -0
- package/dist/producer.js +20 -7
- package/package.json +1 -1
package/dist/producer.d.ts
CHANGED
package/dist/producer.js
CHANGED
|
@@ -11,6 +11,18 @@ class Producer {
|
|
|
11
11
|
const address = `${h}:${p}`;
|
|
12
12
|
this.client = (0, client_1.createClient)(address);
|
|
13
13
|
this.setupTopics();
|
|
14
|
+
this.initStream();
|
|
15
|
+
}
|
|
16
|
+
initStream() {
|
|
17
|
+
this.stream = this.client.StreamPublish((err, summary) => {
|
|
18
|
+
if (err) {
|
|
19
|
+
console.error('StreamPublish ended with error:', err);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
this.stream.on('error', (err) => {
|
|
23
|
+
console.error('StreamPublish stream error:', err);
|
|
24
|
+
// Simple reconnect attempt could be added here
|
|
25
|
+
});
|
|
14
26
|
}
|
|
15
27
|
setupTopics() {
|
|
16
28
|
const topics = this.config.topics || [];
|
|
@@ -53,13 +65,11 @@ class Producer {
|
|
|
53
65
|
payload: data,
|
|
54
66
|
headers,
|
|
55
67
|
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
});
|
|
62
|
-
});
|
|
68
|
+
// Write to the stream
|
|
69
|
+
// Note: This is now fire-and-forget for performance.
|
|
70
|
+
// We don't wait for server acknowledgement for every message.
|
|
71
|
+
this.stream.write(req);
|
|
72
|
+
return Promise.resolve();
|
|
63
73
|
}
|
|
64
74
|
async streamSend(messages) {
|
|
65
75
|
return new Promise((resolve, reject) => {
|
|
@@ -100,6 +110,9 @@ class Producer {
|
|
|
100
110
|
});
|
|
101
111
|
}
|
|
102
112
|
close() {
|
|
113
|
+
if (this.stream) {
|
|
114
|
+
this.stream.end();
|
|
115
|
+
}
|
|
103
116
|
this.client.close();
|
|
104
117
|
}
|
|
105
118
|
}
|