@yarkivaev/source-to-sink 1.2.3 → 1.2.7
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/.github/workflows/ci.yml +1 -1
- package/.github/workflows/release.yml +1 -1
- package/package.json +1 -1
- package/src/batch.js +2 -6
- package/src/mqttSource.js +3 -0
- package/src/stompSource.js +9 -8
package/.github/workflows/ci.yml
CHANGED
package/package.json
CHANGED
package/src/batch.js
CHANGED
|
@@ -31,12 +31,8 @@ export default function batch(sink, size, circuit) {
|
|
|
31
31
|
}
|
|
32
32
|
let records = [];
|
|
33
33
|
function perform() {
|
|
34
|
-
if (records.length === 0) {
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
if (!circuit.allowing()) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
34
|
+
if (records.length === 0) { return; }
|
|
35
|
+
if (!circuit.allowing()) { return; }
|
|
40
36
|
const pending = records;
|
|
41
37
|
records = [];
|
|
42
38
|
try {
|
package/src/mqttSource.js
CHANGED
|
@@ -83,6 +83,9 @@ export default function mqttSource(url, topics, collector, options = {}) {
|
|
|
83
83
|
sessionExpiryInterval: options.sessionExpiryInterval || 3600
|
|
84
84
|
} : undefined
|
|
85
85
|
});
|
|
86
|
+
// @todo Implement manualAcknowledge to defer ack until batch writes to sink
|
|
87
|
+
// Currently MQTT.js auto-acks after this callback returns, before the batch
|
|
88
|
+
// flushes to the database. Up to 5 seconds of data may be lost on crash
|
|
86
89
|
function handler(tp, message) {
|
|
87
90
|
collector.accept({ topic: tp, payload: message.toString() });
|
|
88
91
|
}
|
package/src/stompSource.js
CHANGED
|
@@ -99,17 +99,18 @@ export default function stompSource(url, destination, collector, options = {}) {
|
|
|
99
99
|
maxReconnects: -1
|
|
100
100
|
});
|
|
101
101
|
const channel = new stompit.Channel(failover);
|
|
102
|
+
let pending = Promise.resolve();
|
|
102
103
|
const subscribe = { destination, ack: 'client-individual' };
|
|
103
104
|
channel.subscribe(subscribe, (err, message) => {
|
|
104
|
-
if (err) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
105
|
+
if (err) { return; }
|
|
107
106
|
message.readString('utf-8', (readErr, body) => {
|
|
108
|
-
if (readErr) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
107
|
+
if (readErr) { return; }
|
|
108
|
+
pending = pending.then(async () => {
|
|
109
|
+
try {
|
|
110
|
+
await collector.accept({ destination, payload: body.toString() });
|
|
111
|
+
channel.ack(message);
|
|
112
|
+
} catch { channel.nack(message); }
|
|
113
|
+
});
|
|
113
114
|
});
|
|
114
115
|
});
|
|
115
116
|
state = subscribed(channel);
|